Skip to content

Commit

Permalink
[#3157] Fix setting of common metrics tags.
Browse files Browse the repository at this point in the history
They have to be set before metrics get registered
via the corresponding Binders.

Signed-off-by: Carsten Lohmann <[email protected]>
  • Loading branch information
calohmn committed Mar 18, 2022
1 parent ac0cac0 commit 2cd3e19
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -43,6 +43,7 @@ MicrometerBasedAmqpAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final AmqpAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedAmqpAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_AMQP));
final var metrics = new MicrometerBasedAmqpAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -43,6 +43,7 @@ MicrometerBasedCoapAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final CoapAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedCoapAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_COAP));
final var metrics = new MicrometerBasedCoapAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -43,6 +43,7 @@ MicrometerBasedHttpAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final HttpProtocolAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedHttpAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP));
final var metrics = new MicrometerBasedHttpAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -45,6 +45,7 @@ MicrometerBasedHttpAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final HttpProtocolAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedHttpAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_LORA));
final var metrics = new MicrometerBasedHttpAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -43,6 +43,7 @@ MicrometerBasedMqttAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final MqttProtocolAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedMqttAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT));
final var metrics = new MicrometerBasedMqttAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -93,6 +93,16 @@ protected void logJvmDetails() {
}
}

/**
* Sets common metrics tags.
* <p>
* This default implementation does nothing. Subclasses should override this method to set the metrics tags,
* if not already set elsewhere.
*/
protected void setCommonMetricsTags() {
// nothing done by default
}

/**
* Enables collection of JVM related metrics.
* <p>
Expand All @@ -112,6 +122,7 @@ protected void enableJvmMetrics() {
* <p>
* This implementation
* <ol>
* <li>sets common metrics tags,</li>
* <li>logs the VM details,</li>
* <li>enables JVM metrics and</li>
* <li>invokes {@link #doStart()}.</li>
Expand All @@ -121,6 +132,7 @@ protected void enableJvmMetrics() {
*/
public void onStart(final @Observes StartupEvent ev) {

setCommonMetricsTags();
logJvmDetails();
enableJvmMetrics();
doStart();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -73,10 +73,13 @@ void setAuthenticationServiceOptions(final FileBasedAuthenticationServiceOptions
}

@Override
protected void doStart() {

protected void setCommonMetricsTags() {
LOG.info("adding common tags to meter registry");
meterRegistry.config().commonTags(MetricsTags.forService(Constants.SERVICE_NAME_AUTH));
}

@Override
protected void doStart() {

LOG.info("deploying {} ...", getComponentName());
final CompletableFuture<Void> startup = new CompletableFuture<>();
Expand Down
2 changes: 2 additions & 0 deletions site/homepage/content/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description = "Information about changes in recent Hono releases. Includes new f

* *HonoConnectionImpl* instances failed to release/close the underlying TCP/TLS connection when its *disconnect* or
*shutdown* method had been invoked. This has been fixed.
* In the Quarkus variant of the Hono auth component, the provided metrics did not contain the default set of tags, as
used in the other Hono components (e.g. *host* or *component-name*). This has been fixed.

## 1.11.2

Expand Down

0 comments on commit 2cd3e19

Please sign in to comment.