micrometer-metrics/micrometer

Multigauge Documentation lacks overwrite=true

Fermée

#4 403 ouverte le 22 nov. 2023

 (8 commentaires) (0 réaction) (0 personne assignée)Java (1 133 forks)batch import
doc-updatehelp wanted

Métriques du dépôt

Stars
 (4 882 étoiles)
Métriques de merge PR
 (Merge moyen 1j 21h) (100 PRs mergées en 30 j)

Description

Describe the bug It's a bug in the documentation only!

I tried the code from https://micrometer.io/docs/concepts#_multi_gauge it suggests that you run "register" periodically when running the query, and for me it is implied, that the "count" would be updated every time. For this to work, the second parameter "overwrite" in my understanding must be set to true, the default is false.

I suggest changing the doumentation to

statuses.register(
    resultSet.stream()
        .map(result -> Row.of(Tags.of("status", result.getAsString("status")), result.getAsInt("count")))
        .collect(toList()),
/* overwrite */ true
);

Environment Micrometer 1.12

To Reproduce

 @Test
    fun `min sample`() {
        val gauge = MultiGauge.builder("test").register(meterRegistry)
        gauge.register(
            listOf(MultiGauge.Row.of(Tags.of("status", "some status"), 1)),
        )

        printGauge()

        gauge.register(
            listOf(MultiGauge.Row.of(Tags.of("status", "some status"), 2)),
        )

        printGauge()

        gauge.register(
            listOf(MultiGauge.Row.of(Tags.of("status", "some status"), 3)),
            /* overwrite = */ true,
        )

        printGauge()
    }

    private fun printGauge() {
        println(
            meterRegistry
                .find("test")
                .gauges()
                .map { Pair(it.id.tags, it.value()) },
        )
    }
    
prints:

[([tag(status=some status)], 1.0)]
[([tag(status=some status)], 1.0)] // not updated
[([tag(status=some status)], 3.0)] // updated    

Additional context A related thought: Looking at the implementation of Multigauge.register, I see that gauges are deleted and recreated in the MeterRegistry. I can't see how this is multithreading save: If the metrics are collected by Prometheus just as the gauge is deleted, the gauge will be missing from the metrics. Should I open a ticket for this?

Guide contributeur