forked from linkedin/cruise-control
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow externalized prometheus queries in a properties file This resolves linkedin#1540
- Loading branch information
g.chouet
committed
Feb 23, 2024
1 parent
dcdb4b1
commit 7417b28
Showing
7 changed files
with
125 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file contains all the custom prometheus queries | ||
# This is an example property file for Kafka Cruise Control configurable prometheus queries. | ||
|
||
|
||
# ======================================= | ||
# This must define all the queries for the different RawMetricType needed. | ||
# based on the schema <RAW_METRIC_TYPE>=query | ||
|
||
BROKER_CPU_UTIL=1 - avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[2m])) | ||
# .. |
57 changes: 57 additions & 0 deletions
57
.../kafka/cruisecontrol/monitor/sampling/prometheus/ConfigurablePrometheusQuerySupplier.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.linkedin.kafka.cruisecontrol.monitor.sampling.prometheus; | ||
|
||
import com.linkedin.cruisecontrol.common.CruiseControlConfigurable; | ||
import com.linkedin.kafka.cruisecontrol.metricsreporter.metric.RawMetricType; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import static com.linkedin.cruisecontrol.common.utils.Utils.validateNotNull; | ||
import static com.linkedin.kafka.cruisecontrol.monitor.sampling.prometheus.PrometheusMetricSampler.PROMETHEUS_QUERY_FILE_CONFIG; | ||
|
||
/** | ||
* Configurable prometheus query supplier. This needs a configuration file to specify the different | ||
* prometheus metrics. | ||
* <p> | ||
* See {@link PrometheusQuerySupplier} | ||
*/ | ||
public class ConfigurablePrometheusQuerySupplier implements CruiseControlConfigurable, PrometheusQuerySupplier { | ||
private static final Map<RawMetricType, String> TYPE_TO_QUERY = new HashMap<>(); | ||
|
||
@Override | ||
public Map<RawMetricType, String> get() { | ||
return TYPE_TO_QUERY; | ||
} | ||
|
||
@Override | ||
public void configure(Map<String, ?> configs) { | ||
String configFileName = validateNotNull((String) configs.get(PROMETHEUS_QUERY_FILE_CONFIG), | ||
"Prometheus configuration file is missing."); | ||
|
||
internalParse(configFileName); | ||
} | ||
|
||
/** | ||
* Parse the config file to fill in the map | ||
* @param configFileName the name of the input config file | ||
*/ | ||
private void internalParse(String configFileName) { | ||
Properties props = new Properties(); | ||
try (InputStream propStream = new FileInputStream(configFileName)) { | ||
props.load(propStream); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
|
||
// load each entry of the properties into the internal map | ||
props.forEach((key, value) -> loadEntry((String) key, (String) value)); | ||
} | ||
|
||
private void loadEntry(String rawMetricTypeName, String query) { | ||
// will throw a IllegalArgumentException if the name is unknown in the RawMetricType enum | ||
TYPE_TO_QUERY.put(RawMetricType.valueOf(rawMetricTypeName), query); | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
cruise-control/src/test/resources/prometheusQueriesTest.properties
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
ALL_TOPIC_BYTES_IN=test_query |
2 changes: 2 additions & 0 deletions
2
cruise-control/src/test/resources/prometheusQueriesTestFailing.properties
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALL_TOPIC_BYTES_IN=test_query | ||
Unknown="I don't know" |
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