-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metrics for IP-to-services lookups (#997)
Adds a `service_lookups_total` metric which tracks IP-to-services lookups (via entity cache). To differentiate between successful and failed lookups, status=OK/Error label can be used. Resolves #882
- Loading branch information
1 parent
5eb7fbf
commit 5cbabe3
Showing
5 changed files
with
90 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package servicegetter | ||
|
||
import ( | ||
"github.com/fluxninja/aperture/pkg/metrics" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// Metrics is used for collecting metrics about servicegetter | ||
// | ||
// nil value of Metrics should be always usable. | ||
type Metrics struct { | ||
okTotal prometheus.Counter | ||
errorsTotal prometheus.Counter | ||
} | ||
|
||
// NewMetrics creates new Metrics, registering counters in given registry. | ||
func NewMetrics(registry *prometheus.Registry) (*Metrics, error) { | ||
total := prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: metrics.ServiceLookupsMetricName, | ||
Help: "Number of IP to services lookups", | ||
}, | ||
[]string{metrics.ServiceLookupsStatusLabel}, | ||
) | ||
if err := registry.Register(total); err != nil { | ||
return nil, err | ||
} | ||
return &Metrics{ | ||
okTotal: total.WithLabelValues(metrics.ServiceLookupsStatusOK), | ||
errorsTotal: total.WithLabelValues(metrics.ServiceLookupsStatusError), | ||
}, nil | ||
} | ||
|
||
func (m *Metrics) inc(ok bool) { | ||
if m == nil { | ||
return | ||
} | ||
if ok { | ||
m.okTotal.Inc() | ||
} else { | ||
m.errorsTotal.Inc() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package servicegetter | ||
|
||
import "go.uber.org/fx" | ||
|
||
// Module is a set of default providers for servicegetter components. | ||
var Module = fx.Options( | ||
fx.Provide(ProvideFromEntityCache), | ||
fx.Provide(NewMetrics), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters