From 3dcfcb70d88e4b43a346a28eac43edfc6ac34e76 Mon Sep 17 00:00:00 2001 From: Amelia Downs Date: Wed, 25 Sep 2024 19:58:57 +0000 Subject: [PATCH] fix: explicitly name metrics to pass linter --- depot/steps/emit_check_failure_metric_step.go | 17 +++++++++++------ .../emit_check_failure_metric_step_test.go | 11 +++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/depot/steps/emit_check_failure_metric_step.go b/depot/steps/emit_check_failure_metric_step.go index c313b1c1..62233082 100644 --- a/depot/steps/emit_check_failure_metric_step.go +++ b/depot/steps/emit_check_failure_metric_step.go @@ -1,7 +1,6 @@ package steps import ( - "fmt" "os" loggingclient "code.cloudfoundry.org/diego-logging-client" @@ -57,12 +56,18 @@ func (step *emitCheckFailureMetricStep) Run(signals <-chan os.Signal, ready chan } func (step *emitCheckFailureMetricStep) emitFailureMetric() { - metricName := constructMetricName(step.checkProtocol, step.checkType) - go step.metronClient.IncrementCounter(metricName) -} + if step.checkType != executor.IsLivenessCheck { + return + } -func constructMetricName(checkProtocol executor.CheckProtocol, checkType executor.HealthcheckType) string { - return fmt.Sprintf("%s%s%s", checkProtocol, checkType, CheckFailedCount) + if step.checkProtocol == executor.TCPCheck { + httpMetricName := "TCPLivenessChecksFailedCount" + go step.metronClient.IncrementCounter(httpMetricName) + + } else if step.checkProtocol == executor.HTTPCheck { + tcpMetricName := "HTTPLivenessChecksFailedCount" + go step.metronClient.IncrementCounter(tcpMetricName) + } } func waitForReadiness(p ifrit.Process, ready chan<- struct{}, done <-chan struct{}) { diff --git a/depot/steps/emit_check_failure_metric_step_test.go b/depot/steps/emit_check_failure_metric_step_test.go index 4286dbc3..faeda288 100644 --- a/depot/steps/emit_check_failure_metric_step_test.go +++ b/depot/steps/emit_check_failure_metric_step_test.go @@ -114,6 +114,17 @@ var _ = Describe("EmitCheckFailureMetricStep", func() { Expect(name).To(Equal("TCPLivenessChecksFailedCount")) }) }) + + Context("when HealthCheckType is not Liveness", func() { + BeforeEach(func() { + checkType = executor.IsUntilFailureReadinessCheck + checkProtocol = executor.TCPCheck + }) + + It("should not emit any metric", func() { + Eventually(fakeMetronClient.IncrementCounterCallCount).Should(Equal(0)) + }) + }) }) })