From e00318d6f325a73b3fc0a375888862cf89e8c117 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 22 Aug 2022 18:06:35 +0200 Subject: [PATCH 1/4] WIP: --- .../main/java/io/micrometer/common/Event.java | 90 +++++++++++++++++++ .../DefaultMeterObservationHandler.java | 3 +- ...extObservationHandlerCompatibilityKit.java | 3 +- ...extObservationHandlerCompatibilityKit.java | 3 +- .../ObservationRegistryCompatibilityKit.java | 3 +- .../observation/NoopObservation.java | 1 + .../micrometer/observation/Observation.java | 53 +---------- .../observation/ObservationHandler.java | 12 +-- .../observation/ObservationTextPublisher.java | 3 +- .../observation/SimpleObservation.java | 1 + .../docs/DocumentedObservation.java | 18 ++++ .../tck/MeterRegistryCompatibilityKit.java | 5 +- 12 files changed, 131 insertions(+), 64 deletions(-) create mode 100644 micrometer-commons/src/main/java/io/micrometer/common/Event.java diff --git a/micrometer-commons/src/main/java/io/micrometer/common/Event.java b/micrometer-commons/src/main/java/io/micrometer/common/Event.java new file mode 100644 index 0000000000..0c07023beb --- /dev/null +++ b/micrometer-commons/src/main/java/io/micrometer/common/Event.java @@ -0,0 +1,90 @@ +/* + * Copyright 2022 VMware, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micrometer.common; + +/** + * Represents an event used for documenting instrumentation. + * + * @author Marcin Grzejszczak + * @since 1.10.0 + */ +public interface Event { + /** + * Returns event name. Use can use {@code %s} to represent dynamic entries that + * should be resolved at runtime via {@link String#format(String, Object...)}. + * @return event name + */ + String getName(); + + /** + * Returns event contextual name. Use can use {@code %s} to represent dynamic entries that + * should be resolved at runtime via {@link String#format(String, Object...)}. + * @return event contextual name + */ + default String getContextualName() { + return getName(); + } + + /** + * Creates a {@link Event} for the given names. + * @param name event name + * @param contextualName event contextual name + * @return KeyValue + */ + static Event of(String name, String contextualName) { + return new Event() { + @Override + public String getName() { + return name; + } + + @Override + public String getContextualName() { + return contextualName; + } + }; + } + + /** + * Creates a {@link Event} for the given name. + * @param name event name + * @return KeyValue + */ + static Event of(String name) { + return of(name, name); + } + + /** + * Creates an event for the given key name. + * @param dynamicEntriesForContextualName variables to be resolved in {@link Event#getContextualName()} via {@link String#format(String, Object...)} + * @return event + */ + default Event format(Object... dynamicEntriesForContextualName) { + Event parent = this; + return new Event() { + + @Override + public String getName() { + return parent.getName(); + } + + @Override + public String getContextualName() { + return String.format(parent.getContextualName(), dynamicEntriesForContextualName); + } + }; + } +} diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java index 5a14e33a52..b06da82a88 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java @@ -15,6 +15,7 @@ */ package io.micrometer.core.instrument.observation; +import io.micrometer.common.Event; import io.micrometer.core.instrument.*; import io.micrometer.observation.Observation; @@ -65,7 +66,7 @@ public void onStop(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { Counter.builder(context.getName() + "." + event.getName()).tags(createTags(context)).register(meterRegistry) .increment(); } diff --git a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java index ce02ed0395..2c4520045d 100644 --- a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java +++ b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation.tck; +import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; import org.junit.jupiter.api.DisplayName; @@ -41,7 +42,7 @@ void handlerSupportsAnyContext() { assertThatCode(() -> handler.onStart(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.onStop(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.onError(testContext)).doesNotThrowAnyException(); - assertThatCode(() -> handler.onEvent(new Observation.Event("testEvent"), testContext)) + assertThatCode(() -> handler.onEvent(Event.of("testEvent"), testContext)) .doesNotThrowAnyException(); assertThatCode(() -> handler.onScopeOpened(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.supportsContext(testContext)).doesNotThrowAnyException(); diff --git a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKit.java b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKit.java index 597190873c..67705d8d3c 100644 --- a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKit.java +++ b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKit.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation.tck; +import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.ObservationRegistry; @@ -58,7 +59,7 @@ void handlerSupportsConcreteContextForHandlerMethods() { assertThatCode(() -> handler.onStart(context())).doesNotThrowAnyException(); assertThatCode(() -> handler.onStop(context())).doesNotThrowAnyException(); assertThatCode(() -> handler.onError(context())).doesNotThrowAnyException(); - assertThatCode(() -> handler.onEvent(new Observation.Event("testEvent"), context())).doesNotThrowAnyException(); + assertThatCode(() -> handler.onEvent(Event.of("testEvent"), context())).doesNotThrowAnyException(); assertThatCode(() -> handler.onScopeOpened(context())).doesNotThrowAnyException(); } diff --git a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ObservationRegistryCompatibilityKit.java b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ObservationRegistryCompatibilityKit.java index dc83d60b87..96353c37b9 100644 --- a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ObservationRegistryCompatibilityKit.java +++ b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ObservationRegistryCompatibilityKit.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation.tck; +import io.micrometer.common.Event; import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValues; import io.micrometer.common.lang.Nullable; @@ -81,7 +82,7 @@ void observeWithHandlers() { inOrder.verify(handler).onScopeOpened(isA(Observation.Context.class)); assertThat(scope.getCurrentObservation()).isSameAs(observation); - Observation.Event event = new Observation.Event("testEvent", "event for testing"); + Event event = Event.of("testEvent", "event for testing"); observation.event(event); inOrder.verify(handler).onEvent(same(event), isA(Observation.Context.class)); diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/NoopObservation.java b/micrometer-observation/src/main/java/io/micrometer/observation/NoopObservation.java index 8312a52768..384b23266d 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/NoopObservation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/NoopObservation.java @@ -16,6 +16,7 @@ package io.micrometer.observation; import io.micrometer.common.KeyValue; +import io.micrometer.common.Event; /** * No-op implementation of {@link Observation} so that we can disable the instrumentation diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java b/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java index f42b8b40a1..c6de8c7c92 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java @@ -17,6 +17,7 @@ import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValues; +import io.micrometer.common.Event; import io.micrometer.common.lang.NonNull; import io.micrometer.common.lang.Nullable; @@ -916,58 +917,6 @@ private String toString(Map map) { } - /** - * An arbitrary event that you can extend and signal during an {@link Observation}. - * This helps you to tell to the {@link ObservationHandler} that something happened. - * If you want to signal an exception/error, please use - * {@link Observation#error(Throwable)} instead. - */ - class Event { - - private final String name; - - private final String contextualName; - - /** - * @param name The name of the event. - */ - public Event(String name) { - this(name, name); - } - - /** - * @param name The name of the event (should have low cardinality). - * @param contextualName The contextual name of the event (can have high - * cardinality). - */ - public Event(String name, String contextualName) { - this.name = name; - this.contextualName = contextualName; - } - - /** - * Returns the name of the event. - * @return the name of the event. - */ - public String getName() { - return this.name; - } - - /** - * Returns the contextual name of the event. - * @return the contextual name of the event. - */ - public String getContextualName() { - return this.contextualName; - } - - @Override - public String toString() { - return "event.name='" + this.name + "', event.contextualName='" + this.contextualName + '\''; - } - - } - /** * Read only view on the {@link Context}. */ diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationHandler.java b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationHandler.java index 3295cf3d24..d968fb00ed 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationHandler.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationHandler.java @@ -15,6 +15,8 @@ */ package io.micrometer.observation; +import io.micrometer.common.Event; + import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -48,11 +50,11 @@ default void onError(T context) { } /** - * Reacts to arbitrary {@link Observation.Event}. - * @param event the {@link Observation.Event} that was signaled + * Reacts to arbitrary {@link Event}. + * @param event the {@link Event} that was signaled * @param context an {@link Observation.Context} */ - default void onEvent(Observation.Event event, T context) { + default void onEvent(Event event, T context) { } /** @@ -140,7 +142,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { getFirstApplicableHandler(context).ifPresent(handler -> handler.onEvent(event, context)); } @@ -214,7 +216,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { getAllApplicableHandlers(context).forEach(handler -> handler.onEvent(event, context)); } diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationTextPublisher.java b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationTextPublisher.java index d09be4ecb5..f4420bc823 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationTextPublisher.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationTextPublisher.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation; +import io.micrometer.common.Event; import io.micrometer.common.util.internal.logging.InternalLoggerFactory; import java.util.function.Consumer; @@ -89,7 +90,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { publishUnformatted(String.format("%5s - %s, %s", "EVENT", event, converter.apply(context))); } diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java b/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java index 09180c8c40..19daded33c 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java @@ -16,6 +16,7 @@ package io.micrometer.observation; import io.micrometer.common.KeyValue; +import io.micrometer.common.Event; import io.micrometer.common.lang.Nullable; import io.micrometer.common.util.StringUtils; diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java b/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java index 93bae3d3eb..1564a3259f 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation.docs; +import io.micrometer.common.Event; import io.micrometer.common.docs.KeyName; import io.micrometer.common.lang.NonNull; import io.micrometer.common.lang.Nullable; @@ -55,11 +56,17 @@ public interface DocumentedObservation { */ KeyName[] EMPTY = new KeyName[0]; + /** + * Empty event names. + */ + Event[] EMPTY_EVENT_NAMES = new Event[0]; + /** * Default technical name (e.g.: metric name). You can set the name either by this * method or {@link #getDefaultConvention()}. You can't use both. * @return name */ + @Nullable default String getName() { return null; } @@ -101,6 +108,14 @@ default KeyName[] getHighCardinalityKeyNames() { return EMPTY; } + /** + * Event values. + * @return allowed event values + */ + default Event[] getEventNames() { + return EMPTY_EVENT_NAMES; + } + /** * Returns required prefix to be there for tags. For example, {@code foo.} would * require the tags to have a {@code foo.} prefix like this: {@code foo.bar=true}. @@ -163,6 +178,9 @@ default Observation observation( + "] but you have provided an incompatible one of type [" + defaultConvention.getClass() + "]"); } Observation observation = Observation.createNotStarted(customConvention, defaultConvention, context, registry); + if (getName() != null) { + context.setName(getName()); + } if (getContextualName() != null) { observation.contextualName(getContextualName()); } diff --git a/micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java b/micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java index 98b320ba87..6172d2faf3 100644 --- a/micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java +++ b/micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java @@ -15,6 +15,7 @@ */ package io.micrometer.core.tck; +import io.micrometer.common.Event; import io.micrometer.core.Issue; import io.micrometer.core.annotation.Timed; import io.micrometer.core.instrument.Timer; @@ -642,7 +643,7 @@ void recordWithObservation() { observation.lowCardinalityKeyValue("dynamicTag", "24"); clock(registry).add(1, TimeUnit.SECONDS); - observation.event(new Observation.Event("testEvent", "event for testing")); + observation.event(Event.of("testEvent", "event for testing")); LongTaskTimer longTaskTimer = registry.more().longTaskTimer("myObservation.active", "staticTag", "42"); assertThat(longTaskTimer.activeTasks()).isEqualTo(1); @@ -667,7 +668,7 @@ void recordWithObservationAndScope() { try (Observation.Scope scope = observation.openScope()) { assertThat(scope.getCurrentObservation()).isSameAs(observation); clock(registry).add(10, TimeUnit.NANOSECONDS); - observation.event(new Observation.Event("testEvent", "event for testing")); + observation.event(Event.of("testEvent", "event for testing")); } observation.stop(); clock(registry).add(step()); From 9c84ac943eb144fc217892afa959b255e71b515f Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 23 Aug 2022 12:16:22 +0200 Subject: [PATCH 2/4] Renamed getEvent to getEvents --- .../src/main/java/io/micrometer/common/Event.java | 13 ++++++++----- ...nyContextObservationHandlerCompatibilityKit.java | 3 +-- .../micrometer/observation/SimpleObservation.java | 2 +- .../observation/docs/DocumentedObservation.java | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/micrometer-commons/src/main/java/io/micrometer/common/Event.java b/micrometer-commons/src/main/java/io/micrometer/common/Event.java index 0c07023beb..2b11f54699 100644 --- a/micrometer-commons/src/main/java/io/micrometer/common/Event.java +++ b/micrometer-commons/src/main/java/io/micrometer/common/Event.java @@ -22,16 +22,17 @@ * @since 1.10.0 */ public interface Event { + /** - * Returns event name. Use can use {@code %s} to represent dynamic entries that - * should be resolved at runtime via {@link String#format(String, Object...)}. + * Returns event name. Use can use {@code %s} to represent dynamic entries that should + * be resolved at runtime via {@link String#format(String, Object...)}. * @return event name */ String getName(); /** - * Returns event contextual name. Use can use {@code %s} to represent dynamic entries that - * should be resolved at runtime via {@link String#format(String, Object...)}. + * Returns event contextual name. Use can use {@code %s} to represent dynamic entries + * that should be resolved at runtime via {@link String#format(String, Object...)}. * @return event contextual name */ default String getContextualName() { @@ -69,7 +70,8 @@ static Event of(String name) { /** * Creates an event for the given key name. - * @param dynamicEntriesForContextualName variables to be resolved in {@link Event#getContextualName()} via {@link String#format(String, Object...)} + * @param dynamicEntriesForContextualName variables to be resolved in + * {@link Event#getContextualName()} via {@link String#format(String, Object...)} * @return event */ default Event format(Object... dynamicEntriesForContextualName) { @@ -87,4 +89,5 @@ public String getContextualName() { } }; } + } diff --git a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java index 2c4520045d..962e3fbae7 100644 --- a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java +++ b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java @@ -42,8 +42,7 @@ void handlerSupportsAnyContext() { assertThatCode(() -> handler.onStart(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.onStop(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.onError(testContext)).doesNotThrowAnyException(); - assertThatCode(() -> handler.onEvent(Event.of("testEvent"), testContext)) - .doesNotThrowAnyException(); + assertThatCode(() -> handler.onEvent(Event.of("testEvent"), testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.onScopeOpened(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.supportsContext(testContext)).doesNotThrowAnyException(); assertThat(handler.supportsContext(testContext)).as("Handler supports any context").isTrue(); diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java b/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java index 19daded33c..b1ec0256ac 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java @@ -47,7 +47,7 @@ class SimpleObservation implements Observation { private final Collection filters; - SimpleObservation(String name, ObservationRegistry registry, Context context) { + SimpleObservation(@Nullable String name, ObservationRegistry registry, Context context) { this.registry = registry; this.context = context; this.context.setName(name); diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java b/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java index 1564a3259f..141ef3dc1b 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java @@ -112,7 +112,7 @@ default KeyName[] getHighCardinalityKeyNames() { * Event values. * @return allowed event values */ - default Event[] getEventNames() { + default Event[] getEvents() { return EMPTY_EVENT_NAMES; } From 01a9c59dec554a5c93c49422141ab392221820bf Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 23 Aug 2022 12:39:22 +0200 Subject: [PATCH 3/4] Fixed compilation issues --- .../AnyContextObservationHandlerCompatibilityKitTests.java | 3 ++- ...ncreteContextObservationHandlerCompatibilityKitTests.java | 3 ++- .../NullContextObservationHandlerCompatibilityKitTests.java | 3 ++- .../AllMatchingCompositeObservationHandlerTests.java | 5 +++-- .../FirstMatchingCompositeObservationHandlerTests.java | 5 +++-- .../io/micrometer/core/samples/ObservationHandlerSample.java | 3 ++- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKitTests.java b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKitTests.java index b10ad79dc0..227d4bb2af 100644 --- a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKitTests.java +++ b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKitTests.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation.tck; +import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -32,7 +33,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { } @Override diff --git a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKitTests.java b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKitTests.java index b4c6ab2d74..d11c92880b 100644 --- a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKitTests.java +++ b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKitTests.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation.tck; +import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -33,7 +34,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { } @Override diff --git a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/NullContextObservationHandlerCompatibilityKitTests.java b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/NullContextObservationHandlerCompatibilityKitTests.java index f00b3d8923..4e4179565e 100644 --- a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/NullContextObservationHandlerCompatibilityKitTests.java +++ b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/NullContextObservationHandlerCompatibilityKitTests.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation.tck; +import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -32,7 +33,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { } @Override diff --git a/micrometer-observation/src/test/java/io/micrometer/observation/AllMatchingCompositeObservationHandlerTests.java b/micrometer-observation/src/test/java/io/micrometer/observation/AllMatchingCompositeObservationHandlerTests.java index d02f94e141..069fbff942 100644 --- a/micrometer-observation/src/test/java/io/micrometer/observation/AllMatchingCompositeObservationHandlerTests.java +++ b/micrometer-observation/src/test/java/io/micrometer/observation/AllMatchingCompositeObservationHandlerTests.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation; +import io.micrometer.common.Event; import io.micrometer.observation.ObservationHandler.AllMatchingCompositeObservationHandler; import org.junit.jupiter.api.Test; @@ -67,7 +68,7 @@ void should_run_on_event_for_all_matching_handlers() { AllMatchingCompositeObservationHandler allMatchingHandler = new AllMatchingCompositeObservationHandler( new NotMatchingHandler(), this.matchingHandler, new NotMatchingHandler(), this.matchingHandler2); - allMatchingHandler.onEvent(new Observation.Event("testEvent"), null); + allMatchingHandler.onEvent(Event.of("testEvent"), null); assertThat(this.matchingHandler.eventDetected).isTrue(); assertThat(this.matchingHandler2.eventDetected).isTrue(); @@ -149,7 +150,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { this.eventDetected = true; } diff --git a/micrometer-observation/src/test/java/io/micrometer/observation/FirstMatchingCompositeObservationHandlerTests.java b/micrometer-observation/src/test/java/io/micrometer/observation/FirstMatchingCompositeObservationHandlerTests.java index 228a1be7f3..51dc9f8be6 100644 --- a/micrometer-observation/src/test/java/io/micrometer/observation/FirstMatchingCompositeObservationHandlerTests.java +++ b/micrometer-observation/src/test/java/io/micrometer/observation/FirstMatchingCompositeObservationHandlerTests.java @@ -15,6 +15,7 @@ */ package io.micrometer.observation; +import io.micrometer.common.Event; import io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler; import org.junit.jupiter.api.Test; @@ -62,7 +63,7 @@ void should_run_on_event_only_for_first_matching_handler() { FirstMatchingCompositeObservationHandler firstMatchingHandler = new FirstMatchingCompositeObservationHandler( new NotMatchingHandler(), this.matchingHandler, new NotMatchingHandler()); - firstMatchingHandler.onEvent(new Observation.Event("testEvent"), null); + firstMatchingHandler.onEvent(Event.of("testEvent"), null); assertThat(this.matchingHandler.eventDetected).isTrue(); } @@ -140,7 +141,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Observation.Event event, Observation.Context context) { + public void onEvent(Event event, Observation.Context context) { this.eventDetected = true; } diff --git a/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/ObservationHandlerSample.java b/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/ObservationHandlerSample.java index d23f451823..9f95a06daa 100644 --- a/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/ObservationHandlerSample.java +++ b/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/ObservationHandlerSample.java @@ -15,6 +15,7 @@ */ package io.micrometer.core.samples; +import io.micrometer.common.Event; import io.micrometer.common.KeyValues; import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; @@ -47,7 +48,7 @@ public static void main(String[] args) throws InterruptedException { try (Observation.Scope scope = observation.openScope()) { Thread.sleep(1_000); - observation.event(new Observation.Event("custom.event", "Custom " + UUID.randomUUID())); + observation.event(Event.of("custom.event", "Custom " + UUID.randomUUID())); observation.error(new IOException("simulated")); } From e358cd5ea49f47928416324c7f79d8846f3ac0a4 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 25 Aug 2022 13:58:44 +0200 Subject: [PATCH 4/4] Moved Event back to Observation --- .../main/java/io/micrometer/common/Event.java | 93 ------------------- .../DefaultMeterObservationHandler.java | 3 +- ...extObservationHandlerCompatibilityKit.java | 4 +- ...extObservationHandlerCompatibilityKit.java | 3 +- .../ObservationRegistryCompatibilityKit.java | 3 +- ...servationHandlerCompatibilityKitTests.java | 3 +- ...servationHandlerCompatibilityKitTests.java | 3 +- ...servationHandlerCompatibilityKitTests.java | 3 +- .../observation/NoopObservation.java | 1 - .../micrometer/observation/Observation.java | 78 +++++++++++++++- .../observation/ObservationHandler.java | 12 +-- .../observation/ObservationTextPublisher.java | 3 +- .../observation/SimpleObservation.java | 1 - .../docs/DocumentedObservation.java | 5 +- ...chingCompositeObservationHandlerTests.java | 5 +- ...chingCompositeObservationHandlerTests.java | 5 +- .../tck/MeterRegistryCompatibilityKit.java | 5 +- .../samples/ObservationHandlerSample.java | 3 +- 18 files changed, 100 insertions(+), 133 deletions(-) delete mode 100644 micrometer-commons/src/main/java/io/micrometer/common/Event.java diff --git a/micrometer-commons/src/main/java/io/micrometer/common/Event.java b/micrometer-commons/src/main/java/io/micrometer/common/Event.java deleted file mode 100644 index 2b11f54699..0000000000 --- a/micrometer-commons/src/main/java/io/micrometer/common/Event.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2022 VMware, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.common; - -/** - * Represents an event used for documenting instrumentation. - * - * @author Marcin Grzejszczak - * @since 1.10.0 - */ -public interface Event { - - /** - * Returns event name. Use can use {@code %s} to represent dynamic entries that should - * be resolved at runtime via {@link String#format(String, Object...)}. - * @return event name - */ - String getName(); - - /** - * Returns event contextual name. Use can use {@code %s} to represent dynamic entries - * that should be resolved at runtime via {@link String#format(String, Object...)}. - * @return event contextual name - */ - default String getContextualName() { - return getName(); - } - - /** - * Creates a {@link Event} for the given names. - * @param name event name - * @param contextualName event contextual name - * @return KeyValue - */ - static Event of(String name, String contextualName) { - return new Event() { - @Override - public String getName() { - return name; - } - - @Override - public String getContextualName() { - return contextualName; - } - }; - } - - /** - * Creates a {@link Event} for the given name. - * @param name event name - * @return KeyValue - */ - static Event of(String name) { - return of(name, name); - } - - /** - * Creates an event for the given key name. - * @param dynamicEntriesForContextualName variables to be resolved in - * {@link Event#getContextualName()} via {@link String#format(String, Object...)} - * @return event - */ - default Event format(Object... dynamicEntriesForContextualName) { - Event parent = this; - return new Event() { - - @Override - public String getName() { - return parent.getName(); - } - - @Override - public String getContextualName() { - return String.format(parent.getContextualName(), dynamicEntriesForContextualName); - } - }; - } - -} diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java index b06da82a88..5a14e33a52 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/observation/DefaultMeterObservationHandler.java @@ -15,7 +15,6 @@ */ package io.micrometer.core.instrument.observation; -import io.micrometer.common.Event; import io.micrometer.core.instrument.*; import io.micrometer.observation.Observation; @@ -66,7 +65,7 @@ public void onStop(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { Counter.builder(context.getName() + "." + event.getName()).tags(createTags(context)).register(meterRegistry) .increment(); } diff --git a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java index 962e3fbae7..92ec5d3c1f 100644 --- a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java +++ b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKit.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation.tck; -import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; import org.junit.jupiter.api.DisplayName; @@ -42,7 +41,8 @@ void handlerSupportsAnyContext() { assertThatCode(() -> handler.onStart(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.onStop(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.onError(testContext)).doesNotThrowAnyException(); - assertThatCode(() -> handler.onEvent(Event.of("testEvent"), testContext)).doesNotThrowAnyException(); + assertThatCode(() -> handler.onEvent(Observation.Event.of("testEvent"), testContext)) + .doesNotThrowAnyException(); assertThatCode(() -> handler.onScopeOpened(testContext)).doesNotThrowAnyException(); assertThatCode(() -> handler.supportsContext(testContext)).doesNotThrowAnyException(); assertThat(handler.supportsContext(testContext)).as("Handler supports any context").isTrue(); diff --git a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKit.java b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKit.java index 67705d8d3c..c24341a404 100644 --- a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKit.java +++ b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKit.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation.tck; -import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.ObservationRegistry; @@ -59,7 +58,7 @@ void handlerSupportsConcreteContextForHandlerMethods() { assertThatCode(() -> handler.onStart(context())).doesNotThrowAnyException(); assertThatCode(() -> handler.onStop(context())).doesNotThrowAnyException(); assertThatCode(() -> handler.onError(context())).doesNotThrowAnyException(); - assertThatCode(() -> handler.onEvent(Event.of("testEvent"), context())).doesNotThrowAnyException(); + assertThatCode(() -> handler.onEvent(Observation.Event.of("testEvent"), context())).doesNotThrowAnyException(); assertThatCode(() -> handler.onScopeOpened(context())).doesNotThrowAnyException(); } diff --git a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ObservationRegistryCompatibilityKit.java b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ObservationRegistryCompatibilityKit.java index 96353c37b9..1ba6176b5f 100644 --- a/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ObservationRegistryCompatibilityKit.java +++ b/micrometer-observation-test/src/main/java/io/micrometer/observation/tck/ObservationRegistryCompatibilityKit.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation.tck; -import io.micrometer.common.Event; import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValues; import io.micrometer.common.lang.Nullable; @@ -82,7 +81,7 @@ void observeWithHandlers() { inOrder.verify(handler).onScopeOpened(isA(Observation.Context.class)); assertThat(scope.getCurrentObservation()).isSameAs(observation); - Event event = Event.of("testEvent", "event for testing"); + Observation.Event event = Observation.Event.of("testEvent", "event for testing"); observation.event(event); inOrder.verify(handler).onEvent(same(event), isA(Observation.Context.class)); diff --git a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKitTests.java b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKitTests.java index 227d4bb2af..b10ad79dc0 100644 --- a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKitTests.java +++ b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/AnyContextObservationHandlerCompatibilityKitTests.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation.tck; -import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -33,7 +32,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { } @Override diff --git a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKitTests.java b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKitTests.java index d11c92880b..b4c6ab2d74 100644 --- a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKitTests.java +++ b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/ConcreteContextObservationHandlerCompatibilityKitTests.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation.tck; -import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -34,7 +33,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { } @Override diff --git a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/NullContextObservationHandlerCompatibilityKitTests.java b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/NullContextObservationHandlerCompatibilityKitTests.java index 4e4179565e..f00b3d8923 100644 --- a/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/NullContextObservationHandlerCompatibilityKitTests.java +++ b/micrometer-observation-test/src/test/java/io/micrometer/observation/tck/NullContextObservationHandlerCompatibilityKitTests.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation.tck; -import io.micrometer.common.Event; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -33,7 +32,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { } @Override diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/NoopObservation.java b/micrometer-observation/src/main/java/io/micrometer/observation/NoopObservation.java index 384b23266d..8312a52768 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/NoopObservation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/NoopObservation.java @@ -16,7 +16,6 @@ package io.micrometer.observation; import io.micrometer.common.KeyValue; -import io.micrometer.common.Event; /** * No-op implementation of {@link Observation} so that we can disable the instrumentation diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java b/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java index c6de8c7c92..358825fc88 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java @@ -17,7 +17,6 @@ import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValues; -import io.micrometer.common.Event; import io.micrometer.common.lang.NonNull; import io.micrometer.common.lang.Nullable; @@ -1107,4 +1106,81 @@ interface CheckedCallable { } + /** + * Represents an event used for documenting instrumentation. + * + * @author Marcin Grzejszczak + * @since 1.10.0 + */ + interface Event { + + /** + * Returns event name. + * @return event name + */ + String getName(); + + /** + * Returns event contextual name. You can use {@code %s} to represent dynamic + * entries that should be resolved at runtime via + * {@link String#format(String, Object...)}. + * @return event contextual name + */ + default String getContextualName() { + return getName(); + } + + /** + * Creates a {@link Event} for the given names. + * @param name event name + * @param contextualName event contextual name + * @return event + */ + static Event of(String name, String contextualName) { + return new Event() { + @Override + public String getName() { + return name; + } + + @Override + public String getContextualName() { + return contextualName; + } + }; + } + + /** + * Creates a {@link Event} for the given name. + * @param name event name + * @return event + */ + static Event of(String name) { + return of(name, name); + } + + /** + * Creates an event for the given key name. + * @param dynamicEntriesForContextualName variables to be resolved in + * {@link Event#getContextualName()} via {@link String#format(String, Object...)} + * @return event + */ + default Event format(Object... dynamicEntriesForContextualName) { + Event parent = this; + return new Event() { + + @Override + public String getName() { + return parent.getName(); + } + + @Override + public String getContextualName() { + return String.format(parent.getContextualName(), dynamicEntriesForContextualName); + } + }; + } + + } + } diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationHandler.java b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationHandler.java index d968fb00ed..3295cf3d24 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationHandler.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationHandler.java @@ -15,8 +15,6 @@ */ package io.micrometer.observation; -import io.micrometer.common.Event; - import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -50,11 +48,11 @@ default void onError(T context) { } /** - * Reacts to arbitrary {@link Event}. - * @param event the {@link Event} that was signaled + * Reacts to arbitrary {@link Observation.Event}. + * @param event the {@link Observation.Event} that was signaled * @param context an {@link Observation.Context} */ - default void onEvent(Event event, T context) { + default void onEvent(Observation.Event event, T context) { } /** @@ -142,7 +140,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { getFirstApplicableHandler(context).ifPresent(handler -> handler.onEvent(event, context)); } @@ -216,7 +214,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { getAllApplicableHandlers(context).forEach(handler -> handler.onEvent(event, context)); } diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationTextPublisher.java b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationTextPublisher.java index f4420bc823..d09be4ecb5 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationTextPublisher.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationTextPublisher.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation; -import io.micrometer.common.Event; import io.micrometer.common.util.internal.logging.InternalLoggerFactory; import java.util.function.Consumer; @@ -90,7 +89,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { publishUnformatted(String.format("%5s - %s, %s", "EVENT", event, converter.apply(context))); } diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java b/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java index b1ec0256ac..5f1ea61fc3 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/SimpleObservation.java @@ -16,7 +16,6 @@ package io.micrometer.observation; import io.micrometer.common.KeyValue; -import io.micrometer.common.Event; import io.micrometer.common.lang.Nullable; import io.micrometer.common.util.StringUtils; diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java b/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java index 141ef3dc1b..9a8939a548 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/docs/DocumentedObservation.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation.docs; -import io.micrometer.common.Event; import io.micrometer.common.docs.KeyName; import io.micrometer.common.lang.NonNull; import io.micrometer.common.lang.Nullable; @@ -59,7 +58,7 @@ public interface DocumentedObservation { /** * Empty event names. */ - Event[] EMPTY_EVENT_NAMES = new Event[0]; + Observation.Event[] EMPTY_EVENT_NAMES = new Observation.Event[0]; /** * Default technical name (e.g.: metric name). You can set the name either by this @@ -112,7 +111,7 @@ default KeyName[] getHighCardinalityKeyNames() { * Event values. * @return allowed event values */ - default Event[] getEvents() { + default Observation.Event[] getEvents() { return EMPTY_EVENT_NAMES; } diff --git a/micrometer-observation/src/test/java/io/micrometer/observation/AllMatchingCompositeObservationHandlerTests.java b/micrometer-observation/src/test/java/io/micrometer/observation/AllMatchingCompositeObservationHandlerTests.java index 069fbff942..1a78639afa 100644 --- a/micrometer-observation/src/test/java/io/micrometer/observation/AllMatchingCompositeObservationHandlerTests.java +++ b/micrometer-observation/src/test/java/io/micrometer/observation/AllMatchingCompositeObservationHandlerTests.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation; -import io.micrometer.common.Event; import io.micrometer.observation.ObservationHandler.AllMatchingCompositeObservationHandler; import org.junit.jupiter.api.Test; @@ -68,7 +67,7 @@ void should_run_on_event_for_all_matching_handlers() { AllMatchingCompositeObservationHandler allMatchingHandler = new AllMatchingCompositeObservationHandler( new NotMatchingHandler(), this.matchingHandler, new NotMatchingHandler(), this.matchingHandler2); - allMatchingHandler.onEvent(Event.of("testEvent"), null); + allMatchingHandler.onEvent(Observation.Event.of("testEvent"), null); assertThat(this.matchingHandler.eventDetected).isTrue(); assertThat(this.matchingHandler2.eventDetected).isTrue(); @@ -150,7 +149,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { this.eventDetected = true; } diff --git a/micrometer-observation/src/test/java/io/micrometer/observation/FirstMatchingCompositeObservationHandlerTests.java b/micrometer-observation/src/test/java/io/micrometer/observation/FirstMatchingCompositeObservationHandlerTests.java index 51dc9f8be6..cd1654809c 100644 --- a/micrometer-observation/src/test/java/io/micrometer/observation/FirstMatchingCompositeObservationHandlerTests.java +++ b/micrometer-observation/src/test/java/io/micrometer/observation/FirstMatchingCompositeObservationHandlerTests.java @@ -15,7 +15,6 @@ */ package io.micrometer.observation; -import io.micrometer.common.Event; import io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler; import org.junit.jupiter.api.Test; @@ -63,7 +62,7 @@ void should_run_on_event_only_for_first_matching_handler() { FirstMatchingCompositeObservationHandler firstMatchingHandler = new FirstMatchingCompositeObservationHandler( new NotMatchingHandler(), this.matchingHandler, new NotMatchingHandler()); - firstMatchingHandler.onEvent(Event.of("testEvent"), null); + firstMatchingHandler.onEvent(Observation.Event.of("testEvent"), null); assertThat(this.matchingHandler.eventDetected).isTrue(); } @@ -141,7 +140,7 @@ public void onError(Observation.Context context) { } @Override - public void onEvent(Event event, Observation.Context context) { + public void onEvent(Observation.Event event, Observation.Context context) { this.eventDetected = true; } diff --git a/micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java b/micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java index 6172d2faf3..5c558284b6 100644 --- a/micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java +++ b/micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java @@ -15,7 +15,6 @@ */ package io.micrometer.core.tck; -import io.micrometer.common.Event; import io.micrometer.core.Issue; import io.micrometer.core.annotation.Timed; import io.micrometer.core.instrument.Timer; @@ -643,7 +642,7 @@ void recordWithObservation() { observation.lowCardinalityKeyValue("dynamicTag", "24"); clock(registry).add(1, TimeUnit.SECONDS); - observation.event(Event.of("testEvent", "event for testing")); + observation.event(Observation.Event.of("testEvent", "event for testing")); LongTaskTimer longTaskTimer = registry.more().longTaskTimer("myObservation.active", "staticTag", "42"); assertThat(longTaskTimer.activeTasks()).isEqualTo(1); @@ -668,7 +667,7 @@ void recordWithObservationAndScope() { try (Observation.Scope scope = observation.openScope()) { assertThat(scope.getCurrentObservation()).isSameAs(observation); clock(registry).add(10, TimeUnit.NANOSECONDS); - observation.event(Event.of("testEvent", "event for testing")); + observation.event(Observation.Event.of("testEvent", "event for testing")); } observation.stop(); clock(registry).add(step()); diff --git a/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/ObservationHandlerSample.java b/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/ObservationHandlerSample.java index 9f95a06daa..0360a112e0 100644 --- a/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/ObservationHandlerSample.java +++ b/samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/ObservationHandlerSample.java @@ -15,7 +15,6 @@ */ package io.micrometer.core.samples; -import io.micrometer.common.Event; import io.micrometer.common.KeyValues; import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; @@ -48,7 +47,7 @@ public static void main(String[] args) throws InterruptedException { try (Observation.Scope scope = observation.openScope()) { Thread.sleep(1_000); - observation.event(Event.of("custom.event", "Custom " + UUID.randomUUID())); + observation.event(Observation.Event.of("custom.event", "Custom " + UUID.randomUUID())); observation.error(new IOException("simulated")); }