Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Nov 24, 2024
1 parent d80af62 commit a600326
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ subprojects {
}

plugins.withId('org.jetbrains.kotlin.jvm') {
// We disble the kotlinSourcesJar task since it conflicts with the sourcesJar task of the Java plugin
// We disable the kotlinSourcesJar task since it conflicts with the sourcesJar task of the Java plugin
// See: https://github.com/micrometer-metrics/micrometer/issues/5151
// See: https://youtrack.jetbrains.com/issue/KT-54207/Kotlin-has-two-sources-tasks-kotlinSourcesJar-and-sourcesJar-that-archives-sources-to-the-same-artifact
kotlinSourcesJar.enabled = false
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/implementations/otlp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ management:
----

1. `url` - The URL to which data is reported. Environment variables `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` and `OTEL_EXPORTER_OTLP_ENDPOINT` are also supported in the default implementation. If a value is not provided, it defaults to `http://localhost:4318/v1/metrics`
2. `batchSize` - number of `Meter` to include in a single payload sent to the backend. The default is 10,000.
2. `batchSize` - number of ``Meter``s to include in a single payload sent to the backend. The default is 10,000.
3. `aggregationTemporality` - https://opentelemetry.io/docs/specs/otel/metrics/data-model/#temporality[Aggregation temporality, window=_blank] determines how the additive quantities are expressed, in relation to time. The environment variable `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` is supported by the default implementation. The supported values are `cumulative` or `delta`. Defaults to `cumulative`.
4. `headers` - Additional headers to send with exported metrics. This can be used for authorization headers. By default, headers are loaded from the config. If that is not set, they can be taken from the environment variables `OTEL_EXPORTER_OTLP_HEADERS` and `OTEL_EXPORTER_OTLP_METRICS_HEADERS`. If a header is set in both the environmental variables, the header in the latter overrides the former.
5. `step` - the interval at which metrics will be published. The environment variable `OTEL_METRIC_EXPORT_INTERVAL` is supported by the default implementation. If a value is not provided, defaults to 1 minute.
Expand Down
12 changes: 6 additions & 6 deletions docs/modules/ROOT/pages/implementations/prometheus.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ By default, the `PrometheusMeterRegistry` `scrape()` method returns the https://

The https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md[OpenMetrics] format can also be produced.
To specify the format to be returned, you can pass a content type to the `scrape` method.
For example, to get the OpenMetrics 1.0.0 format scrape, you could use the Prometheus Java client constant for it, as follows in case of the "new" client (`micrometer-registry-prometheus`):
For example, to get the OpenMetrics 1.0.0 format scrape, you could use the Content-Type for it, as follows in case of the "new" client (`micrometer-registry-prometheus`):

[source,java]
----
String openMetricsScrape = registry.scrape("application/openmetrics-text");
----

if you use the "legacy" client (`micrometer-registry-prometheus-simpleclient`):
If you use the "legacy" client (`micrometer-registry-prometheus-simpleclient`), you could use the Prometheus Java client constant for it:

[source,java]
----
Expand Down Expand Up @@ -137,7 +137,7 @@ PrometheusMeterRegistry registry = new PrometheusMeterRegistry(config, new Prome
<1> You can reuse the "default" properties defined in `PrometheusConfig`.
<2> You can set any property from any property source.

Micrometer passes these properties to the Exporters and the Examplar Sampler of the Prometheus client so you can use the https://prometheus.github.io/client_java/config/config/#exporter-properties[exporter]-, and the https://prometheus.github.io/client_java/config/config/#exemplar-properties[exemplar] properties of the Prometheus Client.
Micrometer passes these properties to the Exporters and the Exemplar Sampler of the Prometheus client, so you can use the https://prometheus.github.io/client_java/config/config/#exporter-properties[exporter], and the https://prometheus.github.io/client_java/config/config/#exemplar-properties[exemplar] properties of the Prometheus Client.

== Graphing

Expand Down Expand Up @@ -253,7 +253,7 @@ PrometheusMeterRegistry registry = new PrometheusMeterRegistry(
registry.counter("test").increment();
System.out.println(registry.scrape("application/openmetrics-text"));
----
<1> You need to implement `MySpanContext` (`class MySpanContext implements SpanContext { ... }`) or use an implementation that already exists.
<1> You need to implement `SpanContext` (`class MySpanContext implements SpanContext { ... }`) or use an implementation that already exists.

But if you use the "legacy" client (`micrometer-registry-prometheus-simpleclient`):
[source,java]
Expand All @@ -267,9 +267,9 @@ PrometheusMeterRegistry registry = new PrometheusMeterRegistry(
registry.counter("test").increment();
System.out.println(registry.scrape(TextFormat.CONTENT_TYPE_OPENMETRICS_100));
----
<1> You need to implement `MySpanContextSupplier` (`class MySpanContextSupplier implements SpanContextSupplier { ... }`) or use an implementation that already exists.
<1> You need to implement `SpanContextSupplier` (`class MySpanContextSupplier implements SpanContextSupplier { ... }`) or use an implementation that already exists.

If your configuration is correct, you should get something like this, the `# {span_id="321",trace_id="123"} ...` section is the Exempar right after the value:
If your configuration is correct, you should get something like this, the `# {span_id="321",trace_id="123"} ...` section is the Exemplar right after the value:
[source]
----
# TYPE test counter
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/reference/jetty.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You can collect metrics from a Jetty `Connector` by configuring it with `JettyCo
server.setConnectors(new Connector[] { connector });
----
<1> Register general connection metrics
<2> Registers metrics for bytes in/out on this connector
<2> Register metrics for bytes in/out on this connector

Alternatively, you can apply the metrics instrumentation to all connectors on a `Server` as follows:

Expand Down
2 changes: 1 addition & 1 deletion implementations/micrometer-registry-otlp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.awaitility:awaitility'
testImplementation libs.mockitoCore5
testImplementation libs.mockitoCore5
}

dockerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ default Map<String, String> headers() {
String metricsHeaders = env.getOrDefault("OTEL_EXPORTER_OTLP_METRICS_HEADERS", "").trim();
headersString = Objects.equals(headersString, "") ? metricsHeaders : headersString + "," + metricsHeaders;
try {
// headers are encoded as URL - see
// headers are URL-encoded - see
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables
headersString = URLDecoder.decode(headersString, "UTF-8");
}
catch (Exception e) {
throw new InvalidConfigurationException("Cannot URL decode header value: " + headersString, e);
throw new InvalidConfigurationException("Cannot URL decode headers value: " + headersString, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,12 @@ static double[] getSloWithPositiveInf(DistributionStatisticConfig distributionSt
}

private String getUserAgentHeader() {
if (this.getClass().getPackage().getImplementationVersion() == null) {
return "Micrometer-OTLP-Exporter-Java";
String userAgent = "Micrometer-OTLP-Exporter-Java";
String version = getClass().getPackage().getImplementationVersion();
if (version != null) {
userAgent += "/" + version;
}
return "Micrometer-OTLP-Exporter-Java/" + this.getClass().getPackage().getImplementationVersion();
return userAgent;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void headersDecodingError() throws Exception {
OtlpConfig config = k -> null;
withEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS", "header2=%-1").execute(() -> {
assertThatThrownBy(config::headers).isInstanceOf(InvalidConfigurationException.class)
.hasMessage("Cannot URL decode header value: header2=%-1,");
.hasMessage("Cannot URL decode headers value: header2=%-1,");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -559,7 +558,7 @@ private void onMeterRemoved(Meter meter) {
}

private MetricMetadata getMetadata(String name, @Nullable String description) {
String help = prometheusConfig.descriptions() ? Optional.ofNullable(description).orElse(" ") : " ";
String help = prometheusConfig.descriptions() & description != null ? description : " ";
// Unit is intentionally not set, see:
// https://github.com/OpenObservability/OpenMetrics/blob/1386544931307dff279688f332890c31b6c5de36/specification/OpenMetrics.md#unit
return new MetricMetadata(name, help, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void verifyPrometheusTextScrapeResult() {
.then()
.statusCode(200)
.header("Content-Type", "text/plain; version=0.0.4; charset=utf-8")
.body(not((contains("# EOF"))));
.body(not(contains("# EOF")));
// @formatter:on
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void receiveAllBufferedMetricsAfterCloseSuccessfully(StatsdProtocol protocol) th
final int port = getPort(protocol);
meterRegistry = new StatsdMeterRegistry(getBufferedConfig(protocol, port), Clock.SYSTEM);
startRegistryAndWaitForClient();
Thread.sleep(1000);
Counter counter = Counter.builder("my.counter").register(meterRegistry);
counter.increment();
counter.increment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static Tag uri(RequestEvent event) {
if (matchingPattern == null) {
return URI_UNKNOWN;
}
else if (matchingPattern.equals("/")) {
if (matchingPattern.equals("/")) {
return URI_ROOT;
}
return Tag.of("uri", matchingPattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void outgoing(Socket socket, ByteBuffer bytes) {
}

/**
* Configures metrics instrumentation on all the {@link Server}'s {@link Connector}.
* Configures metrics instrumentation on all the {@link Server}'s {@link Connector}s.
* @param server apply to this server's connectors
* @param registry register metrics to this registry
* @param tags add these tags as additional tags on metrics registered via this
Expand Down Expand Up @@ -230,7 +230,7 @@ public static void addToAllConnectors(Server server, MeterRegistry registry, Ite
}

/**
* Configures metrics instrumentation on all the {@link Server}'s {@link Connector}.
* Configures metrics instrumentation on all the {@link Server}'s {@link Connector}s.
* @param server apply to this server's connectors
* @param registry register metrics to this registry
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.micrometer.core.instrument.config;

import io.micrometer.common.lang.Nullable;

/**
* Signals that a piece of provided configuration is not acceptable for some reason. For
* example negative SLO boundaries.
Expand All @@ -31,12 +33,12 @@ public class InvalidConfigurationException extends IllegalStateException {
* indicates that the cause is nonexistent or unknown.)
* @since 1.11.9
*/
public InvalidConfigurationException(String message, Throwable cause) {
public InvalidConfigurationException(String message, @Nullable Throwable cause) {
super(message, cause);
}

public InvalidConfigurationException(String s) {
super(s);
public InvalidConfigurationException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,12 @@ private CloseableHttpClient classicClient_aggregateRetries() {
.setConnectTimeout(2000L, TimeUnit.MILLISECONDS)
.build();

// tag::setup_classic_aggregate_retries[]
HttpClientBuilder clientBuilder = HttpClients.custom()
.setRetryStrategy(retryStrategy)
.addExecInterceptorFirst("micrometer", new ObservationExecChainHandler(observationRegistry))
.setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()
.setDefaultConnectionConfig(connectionConfig)
.build());
// end::setup_classic_aggregate_retries[]

return clientBuilder.build();
}
Expand Down
2 changes: 1 addition & 1 deletion micrometer-java11/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
}

java {
targetCompatibility = 11
targetCompatibility = JavaVersion.VERSION_11
}

tasks.withType(JavaCompile).configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public KeyValues getLowCardinalityKeyValues(HttpClientContext context) {
return KeyValues.of(
HttpClientObservationDocumentation.LowCardinalityKeys.METHOD.withValue(httpRequest.method()),
HttpClientObservationDocumentation.LowCardinalityKeys.URI
.withValue(getUriTag(httpRequest, context.getResponse(), context.getUriMapper())),
.withValue(getUri(httpRequest, context.getResponse(), context.getUriMapper())),
HttpClientObservationDocumentation.LowCardinalityKeys.STATUS
.withValue(getStatus(context.getResponse())),
HttpClientObservationDocumentation.LowCardinalityKeys.OUTCOME
.withValue(getOutcome(context.getResponse())));
}

String getUriTag(HttpRequest request, @Nullable HttpResponse<?> httpResponse,
String getUri(HttpRequest request, @Nullable HttpResponse<?> httpResponse,
Function<HttpRequest, String> uriMapper) {
return httpResponse != null && (httpResponse.statusCode() == 404 || httpResponse.statusCode() == 301)
? "NOT_FOUND" : uriMapper.apply(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private <T> void stopObservationOrTimer(
instrumentation.stop(DefaultHttpClientObservationConvention.INSTANCE.getName(), "Timer for JDK's HttpClient",
() -> Tags.of(HttpClientObservationDocumentation.LowCardinalityKeys.METHOD.asString(), request.method(),
HttpClientObservationDocumentation.LowCardinalityKeys.URI.asString(),
DefaultHttpClientObservationConvention.INSTANCE.getUriTag(request, res, uriMapper),
DefaultHttpClientObservationConvention.INSTANCE.getUri(request, res, uriMapper),
HttpClientObservationDocumentation.LowCardinalityKeys.STATUS.asString(),
DefaultHttpClientObservationConvention.INSTANCE.getStatus(res),
HttpClientObservationDocumentation.LowCardinalityKeys.OUTCOME.asString(),
Expand Down Expand Up @@ -265,12 +265,10 @@ public <T> CompletableFuture<HttpResponse<T>> sendAsync(HttpRequest httpRequest,
httpRequestBuilder);
HttpRequest request = httpRequestBuilder.build();
return client.sendAsync(request, bodyHandler, pushPromiseHandler).handle((response, throwable) -> {
if (throwable != null) {
instrumentation.setThrowable(throwable);
}
instrumentation.setResponse(response);
stopObservationOrTimer(instrumentation, request, response);
if (throwable != null) {
instrumentation.setThrowable(throwable);
throw new CompletionException(throwable);
}
return response;
Expand Down
2 changes: 1 addition & 1 deletion micrometer-jetty12/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
}

java {
targetCompatibility = 17
targetCompatibility = JavaVersion.VERSION_17
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* An {@link ObservationDocumentation} for {@link ObservedAspect}.
*
* @author Jonatan Ivanov
* @since 1.10.0
*/
enum ObservedAspectObservationDocumentation implements ObservationDocumentation {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

@SuppressWarnings("deprecation")
@Deprecated
class ApacheAsyncHttpClientTimingInstrumentationVerificationTests
extends HttpClientTimingInstrumentationVerificationTests<CloseableHttpAsyncClient> {

Expand Down

0 comments on commit a600326

Please sign in to comment.