Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add druid_service and host_name labels to Prometheus exporter #12769

Merged
merged 5 commits into from
Jul 15, 2022

Conversation

liujianhuanzz
Copy link
Contributor

@liujianhuanzz liujianhuanzz commented Jul 11, 2022

Fixes #12731

Description

Some labels are missing from the Prometheus exporter. They were in the Statsd exporter, such as druid_service and host_name, Which makes the result of Prometheus exporter incompatible with the stated exporter.

In this current implementation, these two labels can be optionally added.

image


Key changed/added classes in this PR
  • docs/development/extensions-contrib/prometheus.md
  • extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/Metrics.java
  • extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
  • extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitterConfig.java
  • extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/MetricsTest.java
  • extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/PrometheusEmitterTest.java

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@liujianhuanzz
Copy link
Contributor Author

CI failure is unrelated to this change. @FrankChen021

Copy link
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, @liujianhuanzz !
I have left some comments.

Comment on lines 52 to 53
private static final String HOST_LABEL_NAME = "hostName";
private static final String SERVICE_LABEL_NAME = "druidService";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the other emitters, say StatsDEmitter,

Suggested change
private static final String HOST_LABEL_NAME = "hostName";
private static final String SERVICE_LABEL_NAME = "druidService";
private static final String TAG_HOSTNAME = "host_name";
private static final String TAG_SERVICE = "druid_service";

{
Map<String, Metric> metrics = readConfig(path);
for (Map.Entry<String, Metric> entry : metrics.entrySet()) {
String name = entry.getKey();
Metric metric = entry.getValue();
Metric.Type type = metric.type;

if (isIncludeHost) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we need these flags. Can't we always include these dimensions?

I guess it would create a separate time series though according to Prometheus docs:

Changing any label value, including adding or removing a label, will create a new time series.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These flags are used to maintain compatibility.

@@ -142,6 +146,25 @@ private void emitMetric(ServiceMetricEvent metricEvent)
}
}

private String fillLabelValue(String lableName, Object userDim, boolean isIncludeHost, String hostName, boolean isServiceAsTag, String serviceName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
isIncludeHost and isServiceTag are not needed as arguments. They can always be obtained from the config.

Suggested change
private String fillLabelValue(String lableName, Object userDim, boolean isIncludeHost, String hostName, boolean isServiceAsTag, String serviceName)
private String getLabelValue(String labelName, Object userDim, String hostName, String serviceName)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could even move this if-else to the calling method itself.

  • this method is called only from that one place
  • the contents are fairly small and would be easier to follow there
  • having to pass hostName and serviceName to this method is a little weird

@@ -99,6 +109,16 @@ public Strategy getStrategy()
return strategy;
}

public boolean isHostAsLabel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: If we do decide to include these flags, better names would be includeHost, includeHostAsLabel or addHostAsLabel. Although, I see that even StatsDEmitter is inconsistent in its naming of includeHost and dogstatsdServiceAsTag.

@@ -43,17 +43,17 @@
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.7.0</version>
<version>0.16.0</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I assume this version is fully backward compatible and doesn't cause any upgrade issues.

Copy link
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, @liujianhuanzz .

Minor comment on docs.
Overall, LGTM 🚀

@@ -40,6 +40,8 @@ All the configuration parameters for the Prometheus emitter are under `druid.emi
|`druid.emitter.prometheus.port`|The port on which to expose the prometheus HTTPServer. Required if using exporter strategy.|no|none|
|`druid.emitter.prometheus.namespace`|Optional metric namespace. Must match the regex `[a-zA-Z_:][a-zA-Z0-9_:]*`|no|"druid"|
|`druid.emitter.prometheus.dimensionMapPath`|JSON file defining the Prometheus metric type, desired dimensions, help text, and conversionFactor for every Druid metric.|no|Default mapping provided. See below.|
|`druid.emitter.prometheus.addHostAsLabel`|Flag to include the hostname as a prometheus label.|no|false|
|`druid.emitter.prometheus.addServiceAsLabel`|If `druid.emitter.prometheus.addServiceAsLabel` is true, druid service (e.g. `druid/broker`, `druid/coordinator`, etc) is reported as a tag (e.g. `druid_service:druid/broker`)|no|false|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: similar to addHostAsLabel.

Suggested change
|`druid.emitter.prometheus.addServiceAsLabel`|If `druid.emitter.prometheus.addServiceAsLabel` is true, druid service (e.g. `druid/broker`, `druid/coordinator`, etc) is reported as a tag (e.g. `druid_service:druid/broker`)|no|false|
|`druid.emitter.prometheus.addServiceAsLabel`|Flag to include the druid service name (e.g. `druid/broker`, `druid/coordinator`, etc.) as a prometheus label.|no|false|

@liujianhuanzz
Copy link
Contributor Author

Thanks for the changes, @liujianhuanzz .

Minor comment on docs. Overall, LGTM 🚀

Thanks

@liujianhuanzz
Copy link
Contributor Author

CI failure is unrelated to this change.

@kfaraz kfaraz merged commit d4403c1 into apache:master Jul 15, 2022
@abhishekagarwal87 abhishekagarwal87 added this to the 24.0.0 milestone Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add druid_service and host_name labels to Prometheus exporter
4 participants