WorkspaceSuccessfulStartAttemptsMeterBinder implements MeterBinder { @Override public void bindTo(MeterRegistry registry) { startedCounter = Counter.builder(workspaceMetric("started.total")) .description("The count of started workspaces") .register(registry); eventService.subscribe( event -> { if (event.getPrevStatus() == WorkspaceStatus.STARTING && event.getStatus() == WorkspaceStatus.RUNNING) { startedCounter.increment(); } }, WorkspaceStatusEvent.class); } @Inject  WorkspaceSuccessfulStartAttemptsMeterBinder(EventService eventService); @Override void bindTo(MeterRegistry registry);  }
@Test(dataProvider = "allStatusTransitionsWithoutRunning") public void shouldNotCollectEvents(WorkspaceStatus from, WorkspaceStatus to) { WorkspaceSuccessfulStartAttemptsMeterBinder meterBinder = new WorkspaceSuccessfulStartAttemptsMeterBinder(eventService); meterBinder.bindTo(registry); eventService.publish( DtoFactory.newDto(WorkspaceStatusEvent.class) .withPrevStatus(from) .withStatus(to) .withWorkspaceId("id1")); Counter successful = registry.find("che.workspace.started.total").counter(); Assert.assertEquals(successful.count(), 0.0); }
@Test public void shouldCollectOnlyStarted() { WorkspaceSuccessfulStartAttemptsMeterBinder meterBinder = new WorkspaceSuccessfulStartAttemptsMeterBinder(eventService); meterBinder.bindTo(registry); eventService.publish( DtoFactory.newDto(WorkspaceStatusEvent.class) .withPrevStatus(WorkspaceStatus.STARTING) .withStatus(WorkspaceStatus.RUNNING) .withWorkspaceId("id1")); Counter successful = registry.find("che.workspace.started.total").counter(); Assert.assertEquals(successful.count(), 1.0); }