Skip to content

Commit b0c86a5

Browse files
committed
put round value to metrics label
Signed-off-by: mrrr61 <mrrr61@outlook.com>
1 parent 314bc3f commit b0c86a5

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

  • federated-learning-controller/internal/sidecar/exporter

federated-learning-controller/internal/sidecar/exporter/exporter.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Reporter struct {
2323
metrics map[string]float64
2424
gauges map[string]metric.Float64ObservableGauge
2525
callbackRegistration metric.Registration
26+
round *int
2627
}
2728

2829
func NewReporter(ctx context.Context, endpoint string, interval int, jobName string) (*Reporter, error) {
@@ -80,6 +81,16 @@ func (r *Reporter) UpdateMetrics(newMetrics map[string]float64) {
8081
}
8182
r.metrics["timestamp"] = float64(time.Now().Unix())
8283

84+
if roundFloat, ok := r.metrics["round"]; ok {
85+
log.Println("metric has round field")
86+
rountInt := int(roundFloat)
87+
r.round = &rountInt
88+
delete(r.metrics, "round")
89+
} else {
90+
log.Println("metric has no round field")
91+
r.round = nil
92+
}
93+
8394
needsUpdate := false
8495
if len(r.metrics) != len(r.gauges) {
8596
needsUpdate = true
@@ -127,7 +138,13 @@ func (r *Reporter) UpdateMetrics(newMetrics map[string]float64) {
127138
defer r.mu.Unlock()
128139
for name, gauge := range r.gauges {
129140
if value, ok := r.metrics[name]; ok {
130-
o.ObserveFloat64(gauge, value)
141+
var roundLabel metric.MeasurementOption
142+
if r.round == nil {
143+
roundLabel = metric.WithAttributes(attribute.String("round", "nil"))
144+
} else {
145+
roundLabel = metric.WithAttributes(attribute.Int("round", *r.round))
146+
}
147+
o.ObserveFloat64(gauge, value, roundLabel)
131148
}
132149
}
133150
return nil

0 commit comments

Comments
 (0)