Skip to content

Commit

Permalink
chore: rename prometheus metrics that are supposed to be gauge (#693)
Browse files Browse the repository at this point in the history
# Description

As title. Closes #237. Also
did a bunch of refactoring + removing unused metrics
## Related Issue

If this pull request is related to any issue, please mention it here.
Additionally, make sure that the issue is assigned to you before
submitting this pull request.

## Checklist

- [ ] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [ ] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [ ] I have correctly attributed the author(s) of the code.
- [ ] I have tested the changes locally.
- [ ] I have followed the project's style guidelines.
- [ ] I have updated the documentation, if necessary.
- [ ] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.
  • Loading branch information
nddq authored Sep 6, 2024
1 parent afddf78 commit 9b02475
Show file tree
Hide file tree
Showing 30 changed files with 271 additions and 283 deletions.
6 changes: 3 additions & 3 deletions pkg/metrics/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (

//go:generate go run go.uber.org/mock/[email protected] -source=interfaces.go -destination=mock_types.go -package=metrics

type ICounterVec interface {
type CounterVec interface {
WithLabelValues(lvs ...string) prometheus.Counter
GetMetricWithLabelValues(lvs ...string) (prometheus.Counter, error)
}

type IGaugeVec interface {
type GaugeVec interface {
WithLabelValues(lvs ...string) prometheus.Gauge
GetMetricWithLabelValues(lvs ...string) (prometheus.Gauge, error)
}

type IHistogramVec interface {
type Histogram interface {
Observe(float64)
// Keep the Write method for testing purposes.
Write(*dto.Metric) error
Expand Down
76 changes: 36 additions & 40 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ func InitializeMetrics() {
metricsLogger.Warn("Metrics already initialized. Exiting.")
return
}
DropCounter = exporter.CreatePrometheusGaugeVecForMetric(
DropPacketsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.DropCountTotalName,
dropCountTotalDescription,
utils.DroppedPacketsGaugeName,
dropPacketsGaugeDescription,
utils.Reason,
utils.Direction)
DropBytesCounter = exporter.CreatePrometheusGaugeVecForMetric(
DropBytesGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.DropBytesTotalName,
dropBytesTotalDescription,
utils.DropBytesGaugeName,
dropBytesGaugeDescription,
utils.Reason,
utils.Direction)
ForwardCounter = exporter.CreatePrometheusGaugeVecForMetric(
ForwardPacketsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.ForwardCountTotalName,
forwardCountTotalDescription,
utils.ForwardPacketsGaugeName,
forwardPacketsGaugeDescription,
utils.Direction)
ForwardBytesCounter = exporter.CreatePrometheusGaugeVecForMetric(
ForwardBytesGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.ForwardBytesTotalName,
forwardBytesTotalDescription,
utils.ForwardBytesGaugeName,
forwardBytesGaugeDescription,
utils.Direction)
WindowsCounter = exporter.CreatePrometheusGaugeVecForMetric(
WindowsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
hnsStats,
hnsStatsDescription,
Expand All @@ -49,69 +49,65 @@ func InitializeMetrics() {
NodeConnectivityStatusGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.NodeConnectivityStatusName,
nodeConnectivityStatusDescription,
nodeConnectivityStatusGaugeDescription,
utils.SourceNodeName,
utils.TargetNodeName)
NodeConnectivityLatencyGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.NodeConnectivityLatencySecondsName,
nodeConnectivityLatencySecondsDescription,
nodeConnectivityLatencySecondsGaugeDescription,
utils.SourceNodeName,
utils.TargetNodeName)

TCPStateGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.TcpStateGaugeName,
utils.TCPStateGaugeName,
tcpStateGaugeDescription,
utils.State,
)
TCPConnectionRemoteGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.TcpConnectionRemoteGaugeName,
utils.TCPConnectionRemoteGaugeName,
tcpConnectionRemoteGaugeDescription,
utils.Address,
utils.Port,
)
TCPConnectionStats = exporter.CreatePrometheusGaugeVecForMetric(
TCPConnectionStatsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.TcpConnectionStatsName,
tcpConnectionStatsDescription,
utils.TCPConnectionStatsName,
tcpConnectionStatsGaugeDescription,
utils.StatName,
)
TCPFlagCounters = exporter.CreatePrometheusGaugeVecForMetric(

TCPFlagGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.TcpFlagCounters,
tcpFlagCountersDescription,
utils.TCPFlagGauge,
tcpFlagGaugeDescription,
utils.Direction,
utils.Flag,
)

// IP States
IPConnectionStats = exporter.CreatePrometheusGaugeVecForMetric(
IPConnectionStatsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.IpConnectionStatsName,
ipConnectionStatsDescription,
utils.IPConnectionStatsName,
ipConnectionStatsGaugeDescription,
utils.StatName,
)

// UDP Stats
UDPConnectionStats = exporter.CreatePrometheusGaugeVecForMetric(
UDPConnectionStatsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.UdpConnectionStatsName,
udpConnectionStatsDescription,
utils.UDPConnectionStatsName,
udpConnectionStatsGaugeDescription,
utils.StatName,
)
UDPActiveSocketsCounter = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.UdpActiveSocketsCounterName,
udpActiveSocketsCounterDescription,
)

// Interface Stats
InterfaceStats = exporter.CreatePrometheusGaugeVecForMetric(
InterfaceStatsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.InterfaceStatsName,
interfaceStatsDescription,
interfaceStatsGaugeDescription,
utils.InterfaceName,
utils.StatName,
)
Expand Down Expand Up @@ -148,19 +144,19 @@ func InitializeMetrics() {
)

// InfiniBand Metrics
InfinibandCounterStats = exporter.CreatePrometheusGaugeVecForMetric(
InfinibandStatsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.InfinibandCounterStatsName,
infinibandCounterStatsDescription,
infinibandStatsGaugeDescription,
utils.StatName,
utils.Device,
utils.Port,
)

InfinibandStatusParams = exporter.CreatePrometheusGaugeVecForMetric(
InfinibandStatusParamsGauge = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.InfinibandStatusParamsName,
infinibandStatusParamsDescription,
infinibandStatusParamsGaugeDescription,
utils.StatName,
utils.InterfaceName,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestInitialization_FirstInit(t *testing.T) {
InitializeMetrics()

// All metrics should be initialized.
objs := []interface{}{DropCounter, DropBytesCounter, ForwardBytesCounter, ForwardCounter, NodeConnectivityStatusGauge, NodeConnectivityLatencyGauge, PluginManagerFailedToReconcileCounter}
objs := []interface{}{DropPacketsGauge, DropBytesGauge, ForwardBytesGauge, ForwardPacketsGauge, NodeConnectivityStatusGauge, NodeConnectivityLatencyGauge, PluginManagerFailedToReconcileCounter}
for _, obj := range objs {
if obj == nil {
t.Fatalf("Expected all metrics to be initialized")
Expand Down
102 changes: 51 additions & 51 deletions pkg/metrics/mock_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9b02475

Please sign in to comment.