Skip to content

Commit

Permalink
Prometheus encoding (#1525)
Browse files Browse the repository at this point in the history
Continuation of #1068

Addressed some of the concerns in the reviews:
- Move `PrometheusMetric` method to original type where possible
- Move `writeResponse` logic to api package
- Improve handling slices of Prometheus marshallable types
- Disable type checking in `jape`
  • Loading branch information
n8maninger authored Oct 3, 2024
2 parents 1744b9d + ad38176 commit b4e3df9
Show file tree
Hide file tree
Showing 9 changed files with 1,158 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
autopilot
bus bus/client
worker worker/client
flags: |
-japecheck.types=false
test:
needs: analyze
runs-on: ${{ matrix.os }}
Expand Down
24 changes: 24 additions & 0 deletions alerts/prometheus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package alerts

import "go.sia.tech/renterd/internal/prometheus"

// PrometheusMetric implements prometheus.Marshaller.
func (a Alert) PrometheusMetric() (metrics []prometheus.Metric) {
metrics = append(metrics, prometheus.Metric{
Name: "renterd_alert",
Labels: map[string]any{
"id": a.ID,
"severity": a.Severity.String(),
"message": a.Message,
"timestamp": a.Timestamp,
},
Value: 1,
})
return
}

// PrometheusMetric implements prometheus.Marshaller.
func (a AlertsResponse) PrometheusMetric() (metrics []prometheus.Metric) {
metrics = prometheus.Slice(a.Alerts).PrometheusMetric()
return
}
Loading

0 comments on commit b4e3df9

Please sign in to comment.