-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite victoriametrics client to pure promql (#1882)
* Initial rewriting of victoriametrics client to the pure PromQl * Get rid of hacky code related to handling status codes query in one requests * Add few fixes * Add more tests for caching unavailable metrics * Debug reason of wiremock server timestous * Fix failing prometheus metrics tests * Add code refactor * Add metrics for prometheus requests * Improve creating prometheus client dependencies * Improve creating prometheus client dependencies * Fix handling errors when one of the requests fails * Remove unnecessary log * CR fixes * CR fixes * CR fixes
- Loading branch information
Showing
34 changed files
with
741 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 38 additions & 1 deletion
39
...in/java/pl/allegro/tech/hermes/management/infrastructure/prometheus/PrometheusClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,44 @@ | ||
package pl.allegro.tech.hermes.management.infrastructure.prometheus; | ||
|
||
import pl.allegro.tech.hermes.api.SubscriptionName; | ||
import pl.allegro.tech.hermes.api.TopicName; | ||
import pl.allegro.tech.hermes.management.infrastructure.metrics.MonitoringMetricsContainer; | ||
|
||
import java.util.List; | ||
|
||
|
||
public interface PrometheusClient { | ||
MonitoringMetricsContainer readMetrics(String query); | ||
String SUBSCRIPTION_QUERY_FORMAT = "sum by (group, topic, subscription)" | ||
+ " (irate({__name__='%s', group='%s', topic='%s', subscription='%s', %s}[1m]))"; | ||
|
||
String SUBSCRIPTION_QUERY_FORMAT_STATUS_CODE = "sum by (group, topic, subscription)" | ||
+ " (irate({__name__='%s', group='%s', topic='%s', subscription='%s', status_code=~'%s', %s}[1m]))"; | ||
|
||
String TOPIC_QUERY_FORMAT = "sum by (group, topic) (irate({__name__='%s', group='%s', " | ||
+ "topic='%s', %s}[1m]))"; | ||
|
||
default MonitoringMetricsContainer readMetrics(String... query) { | ||
return readMetrics(List.of(query)); | ||
} | ||
|
||
MonitoringMetricsContainer readMetrics(List<String> queries); | ||
|
||
static String forSubscription(String name, SubscriptionName subscriptionName, String additionalFilters) { | ||
return String.format(SUBSCRIPTION_QUERY_FORMAT, name, | ||
subscriptionName.getTopicName().getGroupName(), subscriptionName.getTopicName().getName(), | ||
subscriptionName.getName(), additionalFilters); | ||
} | ||
|
||
static String forSubscriptionStatusCode(String name, SubscriptionName subscriptionName, | ||
String regex, String additionalFilters) { | ||
return String.format(SUBSCRIPTION_QUERY_FORMAT_STATUS_CODE, name, | ||
subscriptionName.getTopicName().getGroupName(), subscriptionName.getTopicName().getName(), | ||
subscriptionName.getName(), regex, additionalFilters); | ||
} | ||
|
||
|
||
static String forTopic(String name, TopicName topicName, String additionalFilters) { | ||
return String.format(TOPIC_QUERY_FORMAT, name, | ||
topicName.getGroupName(), topicName.getName(), additionalFilters); | ||
} | ||
} |
Oops, something went wrong.