diff --git a/pkg/monitor/cluster/clustersync.go b/pkg/monitor/cluster/clustersync.go index afd49cea3b3..de0830d598a 100644 --- a/pkg/monitor/cluster/clustersync.go +++ b/pkg/monitor/cluster/clustersync.go @@ -12,7 +12,7 @@ import ( func (mon *Monitor) emitClusterSync(ctx context.Context) error { if mon.hiveClusterManager == nil { - // TODO(hive): remove this once we have Hive everywhere + // TODO(hive): remove this once we have Hive everywhere. mon.log.Info("skipping: no hive cluster manager") return nil } @@ -21,18 +21,22 @@ func (mon *Monitor) emitClusterSync(ctx context.Context) error { if err != nil { return err } - if clusterSync != nil { - if clusterSync.Status.SyncSets != nil { + if clusterSync == nil { + return nil + } else { + if clusterSync.Status.SyncSets == nil { + return nil + } else { for _, s := range clusterSync.Status.SyncSets { mon.emitGauge("hive.clustersync", 1, map[string]string{ - "metric": "SyncSets", - "name": s.Name, - "result": string(s.Result), + "syncType": "SyncSets", + "name": s.Name, + "result": string(s.Result), }) if mon.hourlyRun { mon.log.WithFields(logrus.Fields{ - "metric": "SyncSets", + "syncType": "SyncSets", "name": s.Name, "result": string(s.Result), "firstSuccessTime": timeToString(s.FirstSuccessTime), @@ -42,16 +46,18 @@ func (mon *Monitor) emitClusterSync(ctx context.Context) error { } } } - if clusterSync.Status.SelectorSyncSets != nil { + if clusterSync.Status.SelectorSyncSets == nil { + return nil + } else { for _, s := range clusterSync.Status.SelectorSyncSets { mon.emitGauge("hive.clustersync", 1, map[string]string{ - "metric": "SelectorSyncSets", - "name": s.Name, - "result": string(s.Result), + "syncType": "SelectorSyncSets", + "name": s.Name, + "result": string(s.Result), }) if mon.hourlyRun { mon.log.WithFields(logrus.Fields{ - "metric": "SelectorSyncSets", + "syncType": "SelectorSyncSets", "name": s.Name, "result": string(s.Result), "firstSuccessTime": timeToString(s.FirstSuccessTime), diff --git a/pkg/monitor/cluster/clustersync_test.go b/pkg/monitor/cluster/clustersync_test.go index 506a39bb393..abb1ccefb37 100644 --- a/pkg/monitor/cluster/clustersync_test.go +++ b/pkg/monitor/cluster/clustersync_test.go @@ -75,18 +75,18 @@ func TestEmitClusterSync(t *testing.T) { name: "hive.clustersync", value: 1, labels: map[string]string{ - "metric": "SyncSets", - "name": "syncset1", - "result": "Success", + "syncType": "SyncSets", + "name": "syncset1", + "result": "Success", }, }, { name: "hive.clustersync", value: 1, labels: map[string]string{ - "metric": "SelectorSyncSets", - "name": "selectorsyncset1", - "result": "Success", + "syncType": "SelectorSyncSets", + "name": "selectorsyncset1", + "result": "Success", }, }, }, @@ -126,18 +126,18 @@ func TestEmitClusterSync(t *testing.T) { name: "hive.clustersync", value: 1, labels: map[string]string{ - "metric": "SyncSets", - "name": "syncset2", - "result": "Failure", + "syncType": "SyncSets", + "name": "syncset2", + "result": "Failure", }, }, { name: "hive.clustersync", value: 1, labels: map[string]string{ - "metric": "SelectorSyncSets", - "name": "selectorsyncset2", - "result": "Success", + "syncType": "SelectorSyncSets", + "name": "selectorsyncset2", + "result": "Success", }, }, },