Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye authored Jan 31, 2024
1 parent b771359 commit 7260e13
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected void recordNonNegative(long amount, TimeUnit unit) {
}

if (!histogramExemplarsEnabled && exemplarSampler != null) {
updateLastExemplar(TimeUtils.nanosToUnit(amount, this.baseTimeUnit()), exemplarSampler);
updateLastExemplar(TimeUtils.nanosToUnit(amount, baseTimeUnit()), exemplarSampler);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
/**
* {@link MeterBinder} for Apache Log4j 2. Please use at least 2.21.0 since there was a
* bug in earlier versions that prevented Micrometer to increment its counters correctly.
* See:
* <a href="https://github.com/apache/logging-log4j2/issues/1550">logging-log4j2#1550</a>
* See: <a href=
* "https://github.com/micrometer-metrics/micrometer/issues/2176">micrometer#2176</a>
*
* @see <a href=
* "https://github.com/apache/logging-log4j2/issues/1550">logging-log4j2#1550</a>
* @see <a href=
* "https://github.com/micrometer-metrics/micrometer/issues/2176">micrometer#2176</a>
* @author Steven Sheehy
* @author Johnny Lim
* @since 1.1.0
Expand Down Expand Up @@ -76,7 +76,6 @@ public Log4j2Metrics(Iterable<Tag> tags, LoggerContext loggerContext) {

@Override
public void bindTo(MeterRegistry registry) {

Configuration configuration = loggerContext.getConfiguration();
LoggerConfig rootLoggerConfig = configuration.getRootLogger();
rootLoggerConfig.addFilter(createMetricsFilterAndStart(registry));
Expand All @@ -92,9 +91,9 @@ public void bindTo(MeterRegistry registry) {
}
Filter logFilter = loggerConfig.getFilter();

if ((logFilter instanceof CompositeFilter
if (logFilter instanceof CompositeFilter
&& Arrays.stream(((CompositeFilter) logFilter).getFiltersArray())
.anyMatch(innerFilter -> innerFilter instanceof MetricsFilter))) {
.anyMatch(innerFilter -> innerFilter instanceof MetricsFilter)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ void nullResponseShouldContributeUnknownOutcomeTag() {

@Test
void responseShouldContributeOutcomeTag() {
Tag unknownOutcome = Tag.of("outcome", "SUCCESS");
Tag successOutcome = Tag.of("outcome", "SUCCESS");
HttpServletResponse jakartaResponse = mockJakartaResponse(200);
Tag result = HttpJakartaServletRequestTags.outcome(jakartaResponse);
assertThat(result).isEqualTo(unknownOutcome);
assertThat(result).isEqualTo(successOutcome);

javax.servlet.http.HttpServletResponse javaxResponse = mockJavaxResponse(200);
result = HttpRequestTags.outcome(javaxResponse);
assertThat(result).isEqualTo(unknownOutcome);
assertThat(result).isEqualTo(successOutcome);
}

private HttpServletRequest mockJakartaRequest(String method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ protected KeyValue destinationName(JmsPublishObservationContext context) {
if (jmsDestination instanceof Queue) {
Queue queue = (Queue) jmsDestination;
String queueName = queue.getQueueName();
if (queueName == null) {
return getKeyValueTopic(jmsDestination);
if (queueName != null) {
return KeyValue.of(HighCardinalityKeyNames.DESTINATION_NAME, queueName);
}
return KeyValue.of(HighCardinalityKeyNames.DESTINATION_NAME, queueName);
}
return getKeyValueTopic(jmsDestination);
}
Expand All @@ -133,10 +132,9 @@ private static KeyValue getKeyValueTopic(Destination jmsDestination) throws JMSE
if (jmsDestination instanceof Topic) {
Topic topic = (Topic) jmsDestination;
String topicName = topic.getTopicName();
if (topicName == null) {
return DESTINATION_NAME_UNKNOWN;
if (topicName != null) {
return KeyValue.of(HighCardinalityKeyNames.DESTINATION_NAME, topicName);
}
return KeyValue.of(HighCardinalityKeyNames.DESTINATION_NAME, topicName);
}
return DESTINATION_NAME_UNKNOWN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void shouldHaveTopicDestinationName() throws Exception {
}

@Test
void shouldHaveTopicNullDestinationName() throws Exception {
JmsPublishObservationContext context = new JmsPublishObservationContext(createMessageWithNullTopic());
void shouldHaveUnknownDestinationNameWhenTopicNameIsNull() throws Exception {
JmsPublishObservationContext context = new JmsPublishObservationContext(createMessageWithNullTopicName());
assertThat(convention.getHighCardinalityKeyValues(context))
.contains(KeyValue.of("messaging.destination.name", "unknown"));
}
Expand Down Expand Up @@ -210,7 +210,7 @@ private Message createMessageWithTopic() throws Exception {
return message;
}

private Message createMessageWithNullTopic() throws Exception {
private Message createMessageWithNullTopicName() throws Exception {
Topic topic = mock(Topic.class);
when(topic.getTopicName()).thenReturn(null);
Message message = mock(Message.class);
Expand Down

0 comments on commit 7260e13

Please sign in to comment.