entur / lamassu

Mobility hub
European Union Public License 1.2
5 stars 7 forks source link

Initially failedSetup metrics don't get updated on later success #438

Closed hbruch closed 5 months ago

hbruch commented 5 months ago

Expected behavior

When an initially failed setup for a system subscription later on succeeds, the app.lamassu.gbfs.subscription.failedsetup metric should switch from 1.0 to 0.0 for this system.

Observed behavior

The metric stays at value 1.0.

Version of lamassu used (exact commit hash or JAR name)

0d14f97

Data sets in use (links to GBFS feeds)

Manuelly created feed with initially invalid gbfs.json which I fixed after starting lamassu

Further information

Reason for this issue (and probably some other gauge related issues), is the current MetricsService use of meterRegistry.gauge(), which will not update the metric for subsequent calls (see e.g. )

Testcase to reproduce:


package org.entur.lamassu.metrics;

import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.entur.lamassu.model.provider.FeedProvider;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class MetricsServiceTest {

    @Test
    public void testRegisterSubscriptionSetup() {
        SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry();
        MetricsService metricsService = new MetricsService(meterRegistry);
        FeedProvider fp = new FeedProvider();
        fp.setSystemId("TestSystem");

        metricsService.registerSubscriptionSetup(fp, false);
        assertEquals(1.0, meterRegistry.get(MetricsService.SUBSCRIPTION_FAILEDSETUP).gauge().value(), 0.01);

        metricsService.registerSubscriptionSetup(fp, true);
        assertEquals(0.0, meterRegistry.get(MetricsService.SUBSCRIPTION_FAILEDSETUP).gauge().value(), 0.01);
    }
}