Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ func (c *Controller) ExecIndex(
// Announce.
c.AnnounceCommand(index, serviceInfo)

metricResult := "SUCCESS"
metricResult := metric.ActionResultSuccess
if failed {
metricResult = "FAIL"
metricResult = metric.ActionResultFail
//#nosec G104 -- Errors are logged to CL
//nolint:errcheck // ^
c.Notifiers.Shoutrrr.Send(
Expand Down
8 changes: 4 additions & 4 deletions command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func (c *Controller) InitMetrics() {
name,
serviceID,
"",
"SUCCESS")
metric.ActionResultSuccess)
metric.InitPrometheusCounter(metric.CommandResultTotal,
name,
serviceID,
"",
"FAIL")
metric.ActionResultFail)
}
}

Expand All @@ -95,12 +95,12 @@ func (c *Controller) DeleteMetrics() {
name,
serviceID,
"",
"SUCCESS")
metric.ActionResultSuccess)
metric.DeletePrometheusCounter(metric.CommandResultTotal,
name,
serviceID,
"",
"FAIL")
metric.ActionResultFail)
}
}

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/sqlite v1.41.0 h1:bJXddp4ZpsqMsNN1vS0jWo4IJTZzb8nWpcgvyCFG9Ck=
modernc.org/sqlite v1.41.0/go.mod h1:9fjQZ0mB1LLP0GYrp39oOJXx/I2sxEnZtzCmEQIKvGE=
modernc.org/sqlite v1.42.0 h1:We9UqdM177BV38uTZx1MXsbtyJBTKA6PUKifOAPnC7o=
modernc.org/sqlite v1.42.0/go.mod h1:9fjQZ0mB1LLP0GYrp39oOJXx/I2sxEnZtzCmEQIKvGE=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
Expand Down
8 changes: 4 additions & 4 deletions notify/shoutrrr/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ func (s *Shoutrrr) initMetrics() {
s.ID,
serviceID,
s.GetType(),
"SUCCESS")
metric.ActionResultSuccess)
metric.InitPrometheusCounter(metric.NotifyResultTotal,
s.ID,
serviceID,
s.GetType(),
"FAIL")
metric.ActionResultFail)
}

// DeleteMetrics for this Shoutrrrs.
Expand All @@ -199,10 +199,10 @@ func (s *Shoutrrr) deleteMetrics() {
s.ID,
serviceID,
s.GetType(),
"SUCCESS")
metric.ActionResultSuccess)
metric.DeletePrometheusCounter(metric.NotifyResultTotal,
s.ID,
serviceID,
s.GetType(),
"FAIL")
metric.ActionResultFail)
}
4 changes: 2 additions & 2 deletions notify/shoutrrr/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (s *Shoutrrr) parseSend(
s.ID,
serviceName,
s.GetType(),
"SUCCESS")
metric.ActionResultSuccess)
s.Failed.Set(s.ID, &failed)
return
}
Expand All @@ -531,6 +531,6 @@ func (s *Shoutrrr) parseSend(
s.ID,
serviceName,
s.GetType(),
"FAIL")
metric.ActionResultFail)
return
}
4 changes: 2 additions & 2 deletions notify/shoutrrr/shoutrrr_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestShoutrrr_Send(t *testing.T) {
}
gotMetric := testutil.ToFloat64(metric.NotifyResultTotal.WithLabelValues(
tc.shoutrrr.ID,
"SUCCESS",
metric.ActionResultSuccess,
svcStatus.ServiceInfo.ID,
tc.shoutrrr.GetType()))
if gotMetric != want {
Expand All @@ -153,7 +153,7 @@ func TestShoutrrr_Send(t *testing.T) {
}
gotMetric = testutil.ToFloat64(metric.NotifyResultTotal.WithLabelValues(
tc.shoutrrr.ID,
"FAIL",
metric.ActionResultFail,
svcStatus.ServiceInfo.ID,
tc.shoutrrr.GetType()))
if gotMetric != want {
Expand Down
12 changes: 6 additions & 6 deletions service/deployed_version/types/base/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func (l *Lookup) InitMetrics(parentLookup Interface) {
l.GetServiceID(),
"",
lookupType,
"SUCCESS")
metric.ActionResultSuccess)
metric.InitPrometheusCounter(metric.DeployedVersionQueryResultTotal,
l.GetServiceID(),
"",
lookupType,
"FAIL")
metric.ActionResultFail)
}

// DeleteMetrics for this Lookup.
Expand All @@ -52,12 +52,12 @@ func (l *Lookup) DeleteMetrics(parentLookup Interface) {
l.GetServiceID(),
"",
lookupType,
"SUCCESS")
metric.ActionResultSuccess)
metric.DeletePrometheusCounter(metric.DeployedVersionQueryResultTotal,
l.GetServiceID(),
"",
lookupType,
"FAIL")
metric.ActionResultFail)
}

// QueryMetrics sets the Prometheus metrics for the DeployedVersion query.
Expand All @@ -69,7 +69,7 @@ func (l *Lookup) QueryMetrics(parentLookup Interface, err error) {
l.GetServiceID(),
"",
parentLookup.GetType(),
"FAIL")
metric.ActionResultFail)
// Set liveness.
metric.SetPrometheusGauge(metric.DeployedVersionQueryResultLast,
l.GetServiceID(), parentLookup.GetType(),
Expand All @@ -80,7 +80,7 @@ func (l *Lookup) QueryMetrics(parentLookup Interface, err error) {
l.GetServiceID(),
"",
parentLookup.GetType(),
"SUCCESS")
metric.ActionResultSuccess)
metric.SetPrometheusGauge(metric.DeployedVersionQueryResultLast,
l.GetServiceID(), parentLookup.GetType(),
1)
Expand Down
14 changes: 7 additions & 7 deletions service/deployed_version/types/base/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ func TestLookup_Metrics(t *testing.T) {
wantC := 2
if (gotC - hadC) != wantC {
t.Errorf("%s\nCount metrics mismatch after InitMetrics()\nwant: %d\ngot: %d",
packageName, wantC, gotC - hadC)
packageName, wantC, gotC-hadC)
}
// gauges:
gotG := testutil.CollectAndCount(metric.DeployedVersionQueryResultLast)
wantG := 0
if (gotG - hadG) != wantG {
t.Errorf("%s\nGauge metrics mismatch after InitMetrics()\nwant: %d\ngot: %d",
packageName, wantG, gotG - hadG)
packageName, wantG, gotG-hadG)
}
// But can be added.
lookup.QueryMetrics(&lookup, nil)
gotG = testutil.CollectAndCount(metric.DeployedVersionQueryResultLast)
wantG = 1
if (gotG - hadG) != wantG {
t.Errorf("%s\nGauge metrics mismatch after QueryMetrics()\nwant: %d\ngot: %d",
packageName, wantG, gotG - hadG)
packageName, wantG, gotG-hadG)
}

// AND it can be deleted.
Expand Down Expand Up @@ -133,9 +133,9 @@ func TestLookup_QueryMetrics(t *testing.T) {

// AND the Prometheus metrics are initialised to 0.
counterSuccess := testutil.ToFloat64(metric.DeployedVersionQueryResultTotal.WithLabelValues(
lookup.GetServiceID(), lookup.GetType(), "SUCCESS"))
lookup.GetServiceID(), lookup.GetType(), metric.ActionResultSuccess))
counterFail := testutil.ToFloat64(metric.DeployedVersionQueryResultTotal.WithLabelValues(
lookup.GetServiceID(), lookup.GetType(), "FAIL"))
lookup.GetServiceID(), lookup.GetType(), metric.ActionResultFail))
gauge := testutil.ToFloat64(metric.DeployedVersionQueryResultLast.WithLabelValues(
lookup.GetServiceID(), lookup.GetType()))
if counterSuccess != 0 || counterFail != 0 || gauge != 0 {
Expand All @@ -157,9 +157,9 @@ func TestLookup_QueryMetrics(t *testing.T) {
}

counterSuccess = testutil.ToFloat64(metric.DeployedVersionQueryResultTotal.WithLabelValues(
lookup.GetServiceID(), lookup.GetType(), "SUCCESS"))
lookup.GetServiceID(), lookup.GetType(), metric.ActionResultSuccess))
counterFail = testutil.ToFloat64(metric.DeployedVersionQueryResultTotal.WithLabelValues(
lookup.GetServiceID(), lookup.GetType(), "FAIL"))
lookup.GetServiceID(), lookup.GetType(), metric.ActionResultFail))
gauge = testutil.ToFloat64(metric.DeployedVersionQueryResultLast.WithLabelValues(
lookup.GetServiceID(), lookup.GetType()))
if counterSuccess != wantSuccess ||
Expand Down
4 changes: 2 additions & 2 deletions service/deployed_version/types/web/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ func TestLookup_Track(t *testing.T) {
for haveQueried != false {
serviceID := tc.lookup.GetServiceID()
passQ := testutil.ToFloat64(metric.DeployedVersionQueryResultTotal.WithLabelValues(
serviceID, "SUCCESS", tc.lookup.Type))
serviceID, metric.ActionResultSuccess, tc.lookup.Type))
failQ := testutil.ToFloat64(metric.DeployedVersionQueryResultTotal.WithLabelValues(
serviceID, "FAIL", tc.lookup.Type))
serviceID, metric.ActionResultFail, tc.lookup.Type))
if passQ != float64(0) && failQ != float64(0) {
haveQueried = true
}
Expand Down
13 changes: 10 additions & 3 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ func (s *Service) Init(

// initMetrics will initialise the Prometheus metrics for the Service.
func (s *Service) initMetrics() {
metric.ServiceCountCurrentAdd(s.Options.Active, 1)
if !s.Options.GetActive() {
return
}

if s.LatestVersion != nil {
s.LatestVersion.InitMetrics(s.LatestVersion)
}
Expand All @@ -174,11 +179,15 @@ func (s *Service) initMetrics() {
s.CommandController.InitMetrics()
s.WebHook.InitMetrics()
s.Status.InitMetrics()
metric.ServiceCountCurrent.Add(1)
}

// deleteMetrics will delete the Prometheus metrics for the Service.
func (s *Service) deleteMetrics() {
metric.ServiceCountCurrentAdd(s.Options.Active, -1)
if !s.Options.GetActive() {
return
}

if s.LatestVersion != nil {
s.LatestVersion.DeleteMetrics(s.LatestVersion)
}
Expand All @@ -189,6 +198,4 @@ func (s *Service) deleteMetrics() {
s.CommandController.DeleteMetrics()
s.WebHook.DeleteMetrics()
s.Status.DeleteMetrics()

metric.ServiceCountCurrent.Add(-1)
}
Loading
Loading