Skip to content

Commit

Permalink
Add support for using ElasticSearch index aliases common when using r…
Browse files Browse the repository at this point in the history
…ollover indices

 * Added ES_USE_ALIASES flag uses 'jaeger-span-read' index alias instead of indexDate postfixed one and
   'jaeger-dependencies-write' to store the dependencies
 * Added range query to only fetch the spans for the last 24 hours (based on startTimeMillies field)

Signed-off-by: Christian Rohmann <[email protected]>
  • Loading branch information
frittentheke committed May 12, 2022
1 parent a41f173 commit 7d69dbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Elasticsearch is used when `STORAGE=elasticsearch`.
* `ES_INDEX_PREFIX`: index prefix of Jaeger indices. By default unset.
* `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.
Usually required when using rollover indices.

Example usage:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static final class Builder {
Boolean nodesWanOnly = Boolean.parseBoolean(Utils.getEnv("ES_NODES_WAN_ONLY", "false"));
String indexPrefix = Utils.getEnv("ES_INDEX_PREFIX", null);
String spanRange = Utils.getEnv("ES_TIME_RANGE", "24h");
Boolean useAliases = Boolean.parseBoolean(Utils.getEnv("ES_USE_ALIASES", "false"));

final Map<String, String> sparkProperties = new LinkedHashMap<>();

Expand Down Expand Up @@ -166,6 +167,7 @@ private static String getSystemPropertyAsFileResource(String key) {
private final SparkConf conf;
private final String indexPrefix;
private final String spanRange;
private final Boolean useAliases;

ElasticsearchDependenciesJob(Builder builder) {
this.day = builder.day;
Expand Down Expand Up @@ -195,6 +197,7 @@ private static String getSystemPropertyAsFileResource(String key) {
}
this.indexPrefix = builder.indexPrefix;
this.spanRange = builder.spanRange;
this.useAliases = builder.useAliases;
}

/**
Expand All @@ -209,7 +212,21 @@ private static String prefix(String prefix) {
}

public void run(String peerServiceTag) {
run(indexDate("jaeger-span"), indexDate("jaeger-dependencies") ,peerServiceTag);

String[] readIndices;
String[] writeIndex;

// use alias indices common when using index rollover
if (this.useAliases) {
readIndices = new String[]{prefix(indexPrefix) + "jaeger-span-read", prefixBefore19(indexPrefix) + "jaeger-span-read"};
writeIndex = new String[] {prefix(indexPrefix) + "jaeger-dependencies-write", prefixBefore19(indexPrefix) + "jaeger-dependencies-write"};
}
else {
readIndices = indexDate("jaeger-span");
writeIndex = indexDate("jaeger-dependencies");
}

run(readIndices, writeIndex, peerServiceTag);
}

String[] indexDate(String index) {
Expand Down

0 comments on commit 7d69dbe

Please sign in to comment.