Skip to content

Commit

Permalink
Add elasticsearch storage date format config. (#101)
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Zhengwei <[email protected]>

Signed-off-by: chen zhengwei <[email protected]>
  • Loading branch information
sniperking1234 authored Jun 24, 2022
1 parent 278726d commit 0eb64c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Elasticsearch is used when `STORAGE=elasticsearch`.
If your elasticsearch cluster's data nodes only listen on loopback ip, set this to true.
Defaults to false
* `ES_INDEX_PREFIX`: index prefix of Jaeger indices. By default unset.
* `ES_INDEX_DATE_SEPARATOR`: index date separator of Jaeger indices. The default value is `-`.
For example `.` will find index "jaeger-span-2020.11.25".
* `ES_TIME_RANGE`: How far in the past the job should look to for spans, the maximum and default is `24h`.
Any value accepted by [date-math](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math) can be used here, but the anchor is always `now`.
* `ES_USE_ALIASES`: Set to true to use index alias names to read from and write to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static final class Builder {
Boolean clientNodeOnly = Boolean.parseBoolean(Utils.getEnv("ES_CLIENT_NODE_ONLY", "false"));
Boolean nodesWanOnly = Boolean.parseBoolean(Utils.getEnv("ES_NODES_WAN_ONLY", "false"));
String indexPrefix = Utils.getEnv("ES_INDEX_PREFIX", null);
String indexDatePattern = datePattern(Utils.getEnv("ES_INDEX_DATE_SEPARATOR", "-"));
String spanRange = Utils.getEnv("ES_TIME_RANGE", "24h");
Boolean useAliases = Boolean.parseBoolean(Utils.getEnv("ES_USE_ALIASES", "false"));

Expand Down Expand Up @@ -119,6 +120,12 @@ public Builder indexPrefix(String indexPrefix) {
return this;
}

/** index date pattern for Jaeger indices. By default yyyy-MM-dd */
public Builder indexDatePattern(String indexDatePattern) {
this.indexDatePattern = indexDatePattern;
return this;
}

/** span range for Jaeger indices. By default 24h */
public Builder spanRange(String spanRange) {
this.spanRange = spanRange;
Expand Down Expand Up @@ -166,6 +173,7 @@ private static String getSystemPropertyAsFileResource(String key) {
private final ZonedDateTime day;
private final SparkConf conf;
private final String indexPrefix;
private final String indexDatePattern;
private final String spanRange;
private final Boolean useAliases;

Expand Down Expand Up @@ -196,6 +204,7 @@ private static String getSystemPropertyAsFileResource(String key) {
conf.set(entry.getKey(), entry.getValue());
}
this.indexPrefix = builder.indexPrefix;
this.indexDatePattern = builder.indexDatePattern;
this.spanRange = builder.spanRange;
this.useAliases = builder.useAliases;
}
Expand All @@ -211,6 +220,17 @@ private static String prefix(String prefix) {
return prefix != null ? String.format("%s-", prefix) : "";
}

private static String datePattern(String separator) {
if (separator.equals("")) {
return "yyyyMMdd";
}
// ' is escape character in date format, we should double it here.
if (separator.contains("'")) {
separator = separator.replace("'", "''");
}
return String.format("yyyy'%s'MM'%s'dd", separator, separator);
}

public void run(String peerServiceTag) {

String[] readIndices;
Expand All @@ -230,7 +250,7 @@ public void run(String peerServiceTag) {
}

String[] indexDate(String index) {
String date = day.toLocalDate().format(DateTimeFormatter.ISO_LOCAL_DATE);
String date = day.toLocalDate().format(DateTimeFormatter.ofPattern(indexDatePattern));
if (indexPrefix != null && indexPrefix.length() > 0) {
return new String[]{String.format("%s%s-%s", prefix(indexPrefix), index, date), String.format("%s%s-%s", prefixBefore19(indexPrefix), index, date)};
}
Expand Down

0 comments on commit 0eb64c4

Please sign in to comment.