Skip to content

Commit

Permalink
feat: using shorter keys with tag values only instead of key:value
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Mar 30, 2023
1 parent 8bdc9b3 commit 075c82b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
Expand Up @@ -269,13 +269,11 @@ protected String getConventionName(Id id, Iterable<Tag> tags) {
StringBuilder name = new StringBuilder();
name.append(super.getConventionName(id));
for (Tag tag : tags) {
name.append(config.keySeparator()).append(getConventionName(tag));
name.append(config.keySeparator()).append(tag.getValue());
}
return name.toString();
}

protected abstract String getConventionName(Tag tag);

protected String key(Id id, String suffix) {
// usually tagKeys and metricNames naming rules are the same
// but we can't call getConventionName again after adding suffix
Expand Down
Expand Up @@ -73,11 +73,6 @@ public RediSearchMeterRegistry(RediSearchRegistryConfig config, Clock clock, Abs
excludedKeyTags = excludedKeyTags(config);
}

@Override
protected String getConventionName(Tag tag) {
return tag.getValue();
}

private Function<Id, String> indexNamingFunction(RediSearchRegistryConfig config) {
NamingConvention namingConvention = new RedisNamingConvention(config.indexSeparator());
Function<Id, String> idFunction = id -> id.getConventionName(namingConvention);
Expand Down
Expand Up @@ -65,11 +65,6 @@ public RedisTimeSeriesMeterRegistry(RedisRegistryConfig config, Clock clock, Abs
super(config, clock, client, DEFAULT_THREAD_FACTORY);
}

@Override
protected String getConventionName(Tag tag) {
return tag.getKey() + config.keySeparator() + tag.getValue();
}

@Override
protected void handleExecutionException(Exception e) throws Exception {
if (e.getCause() != null && ERROR_KEY_ALREADY_EXISTS.equals(e.getCause().getMessage())) {
Expand Down
Expand Up @@ -171,7 +171,7 @@ void writeTimerWithTags() throws Exception {
String tagValue = "tagvalue";
tsRegistry.timer(id, tagName, tagValue).record(Duration.ofMillis(3));
tsRegistry.write(tsRegistry.get(id).tags(tagName, tagValue).timer());
List<Sample> samples = connection.sync().tsRange(key(id) + ":" + tagName + ":" + tagValue + ":count",
List<Sample> samples = connection.sync().tsRange(key(id) + ":" + tagValue + ":count",
TimeRange.unbounded());
Assertions.assertEquals(1, samples.size());
}
Expand Down Expand Up @@ -235,7 +235,7 @@ void writeLongTaskTimer() throws Exception {
String id = "writelongtasktimer.timer";
LongTaskTimer timer = LongTaskTimer.builder(id).tag("tag", "value").register(tsRegistry);
tsRegistry.write(timer);
String prefix = id + ".tag.value";
String prefix = id + ".value";
Set<String> expected = Stream
.of(key(prefix + ".active.count"), key(prefix + ".duration.sum"), key(prefix + ".max"))
.collect(Collectors.toSet());
Expand Down Expand Up @@ -393,11 +393,10 @@ public String[] nonKeyTags() {
Awaitility.await().timeout(Duration.ofMillis(300))
.until(() -> connection.sync().ftSearch(index, "*").size() == 2);
List<String> tsKeys = connection.sync().keys("ts:*");
Assertions.assertEquals(new HashSet<>(Arrays.asList("ts:query:id:456:max", "ts:query:id:456:quantile:0.9",
"ts:query:id:123:sum", "ts:query:id:123:quantile:0.99", "ts:query:id:123:count",
"ts:query:id:123:quantile:0.9", "ts:query:id:456:count", "ts:query:id:123:mean", "ts:query:id:123:max",
"ts:query:id:456:mean", "ts:query:id:456:sum", "ts:query:id:456:quantile:0.99")),
new HashSet<>(tsKeys));
Assertions.assertEquals(new HashSet<>(Arrays.asList("ts:query:456:max", "ts:query:456:0.9",
"ts:query:123:sum", "ts:query:123:0.99", "ts:query:123:count", "ts:query:123:0.9",
"ts:query:456:count", "ts:query:123:mean", "ts:query:123:max", "ts:query:456:mean", "ts:query:456:sum",
"ts:query:456:0.99")), new HashSet<>(tsKeys));
List<String> searchKeys = connection.sync().keys("hash:*");
Assertions.assertEquals(new HashSet<>(Arrays.asList("hash:query:456", "hash:query:123")),
new HashSet<>(searchKeys));
Expand Down

0 comments on commit 075c82b

Please sign in to comment.