micrometer-metrics / micrometer

An application observability facade for the most popular observability tools. Think SLF4J, but for observability.
https://micrometer.io
Apache License 2.0
4.39k stars 966 forks source link

Timer metrics - not able to see _seconds_count and _seconds_sum metrics, _max metric is getting scrap #5196

Closed sanyaj22 closed 2 weeks ago

sanyaj22 commented 3 weeks ago

Describe the bug Timer metrics - not able to see _seconds_count and _seconds_sum metrics, _max metric is getting scrap

Environment production micro meter 1.11.0

I need to calculate response time(avg, p99) of an api and i have implemented like this

package com.groww.payouts.util;

import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component;

import java.sql.Time; import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit;

@Component @Slf4j public class MetricUtil {

private final Map<String, Long> responseTimes = new ConcurrentHashMap<>();

public static final String YESBANK_FUND_TRANSFER_RESPONSE_TIME = "yesbank.fund.transfer.response.time";

public static final String YESBANK_INIT_RESPONSE_TIME = "yesbank.init.response.time";

@Autowired
private MeterRegistry meterRegistry;

@Autowired
private Timer timer;

public void recordResponseTimeGauge(String metric, String emid, long responseTime) {
    responseTimes.put(emid,responseTime);
    meterRegistry.gauge(metric,
            Collections.singletonList(Tag.of("emid", emid)),
            responseTimes,
            map -> map.getOrDefault(emid, 0L));
}

public void recordResponseTimeTimer(String metric, String emid, long responseTime) {

    timer.record(responseTime,TimeUnit.MILLISECONDS);
}

} package com.groww.payouts.config;

import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.Timer; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile;

import java.util.Optional;

@Configuration public class OtelMetricsConfig { @Bean @ConditionalOnClass(name = "io.opentelemetry.javaagent.OpenTelemetryAgent") public MeterRegistry otelRegistry() { Optional otelRegistry = Metrics.globalRegistry.getRegistries().stream() .filter(r -> r.getClass().getName().contains("OpenTelemetryMeterRegistry")) .findAny(); otelRegistry.ifPresent(Metrics.globalRegistry::remove); return otelRegistry.orElse(null); }

@Bean
public Timer responseTimeTimer(MeterRegistry meterRegistry) {
    return Timer.builder("response.time.yes")
            .publishPercentileHistogram(true)
            .register(meterRegistry);
}

}

the issue here is I am not able to see response_time_yes_seconds_count or response_time_yes_seconds_sum metric but response_time_yes_max is getting scrap . i am doing anything wrong

jonatan-ivanov commented 2 weeks ago

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the support guidelines, we prefer to use GitHub issues for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Also, Micrometer 1.11.0 does not have OSS support anymore, please consider to upgrade: https://micrometer.io/support/ If you decide to post this to Stack Overflow please make sure your question is clear and the code is formatted, I have a hard time to read the description of this issue.