diff --git a/pkg/api/v1/metric_usage.go b/pkg/api/v1/metric_usage.go index 48ad142..efb16b3 100644 --- a/pkg/api/v1/metric_usage.go +++ b/pkg/api/v1/metric_usage.go @@ -111,10 +111,16 @@ type RuleUsage struct { Expression string `json:"expression"` } +type DashboardUsage struct { + UID string `json:"uid"` + Name string `json:"title"` + URL string `json:"url"` +} + type MetricUsage struct { - Dashboards Set[string] `json:"dashboards,omitempty"` - RecordingRules Set[RuleUsage] `json:"recordingRules,omitempty"` - AlertRules Set[RuleUsage] `json:"alertRules,omitempty"` + Dashboards Set[DashboardUsage] `json:"dashboards,omitempty"` + RecordingRules Set[RuleUsage] `json:"recordingRules,omitempty"` + AlertRules Set[RuleUsage] `json:"alertRules,omitempty"` } func MergeUsage(old, new *MetricUsage) *MetricUsage { diff --git a/source/grafana/grafana.go b/source/grafana/grafana.go index ea2a1cd..fed2796 100644 --- a/source/grafana/grafana.go +++ b/source/grafana/grafana.go @@ -144,10 +144,18 @@ func (c *grafanaCollector) generateUsage(metricNames modelAPIV1.Set[string], cur dashboardURL := fmt.Sprintf("%s/d/%s", c.grafanaURL, currentDashboard.UID) for metricName := range metricNames { if usage, ok := metricUsage[metricName]; ok { - usage.Dashboards.Add(dashboardURL) + usage.Dashboards.Add(modelAPIV1.DashboardUsage{ + UID: currentDashboard.UID, + Name: currentDashboard.Title, + URL: dashboardURL, + }) } else { metricUsage[metricName] = &modelAPIV1.MetricUsage{ - Dashboards: modelAPIV1.NewSet(dashboardURL), + Dashboards: modelAPIV1.NewSet(modelAPIV1.DashboardUsage{ + UID: currentDashboard.UID, + Name: currentDashboard.Title, + URL: dashboardURL, + }), } } } diff --git a/source/perses/perses.go b/source/perses/perses.go index 98926b8..83496db 100644 --- a/source/perses/perses.go +++ b/source/perses/perses.go @@ -90,10 +90,18 @@ func (c *persesCollector) generateUsage(metricNames modelAPIV1.Set[string], curr dashboardURL := fmt.Sprintf("%s/api/v1/projects/%s/dashboards/%s", c.persesURL, currentDashboard.Metadata.Project, currentDashboard.Metadata.Name) for metricName := range metricNames { if usage, ok := metricUsage[metricName]; ok { - usage.Dashboards.Add(dashboardURL) + usage.Dashboards.Add(modelAPIV1.DashboardUsage{ + UID: currentDashboard.Metadata.Name, + Name: currentDashboard.Metadata.Name, + URL: dashboardURL, + }) } else { metricUsage[metricName] = &modelAPIV1.MetricUsage{ - Dashboards: modelAPIV1.NewSet(dashboardURL), + Dashboards: modelAPIV1.NewSet(modelAPIV1.DashboardUsage{ + UID: currentDashboard.Metadata.Name, + Name: currentDashboard.Metadata.Name, + URL: dashboardURL, + }), } } }