Plugins: Add metric to track plugin backend target (#95976)
* add metric to track plugin backend target * tidy * fix test
This commit is contained in:
@@ -200,6 +200,8 @@ var (
|
||||
|
||||
grafanaPluginBuildInfoDesc *prometheus.GaugeVec
|
||||
|
||||
grafanaPluginTargetInfoDesc *prometheus.GaugeVec
|
||||
|
||||
// StatsTotalLibraryPanels is a metric of total number of library panels stored in Grafana.
|
||||
StatsTotalLibraryPanels prometheus.Gauge
|
||||
|
||||
@@ -570,6 +572,12 @@ func init() {
|
||||
Namespace: ExporterName,
|
||||
}, []string{"plugin_id", "plugin_type", "version", "signature_status"})
|
||||
|
||||
grafanaPluginTargetInfoDesc = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "plugin_target_info",
|
||||
Help: "A metric with a constant '1' value labeled by pluginId and target",
|
||||
Namespace: ExporterName,
|
||||
}, []string{"plugin_id", "target"})
|
||||
|
||||
StatsTotalDashboardVersions = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "stat_totals_dashboard_versions",
|
||||
Help: "total amount of dashboard versions in the database",
|
||||
@@ -710,6 +718,10 @@ func SetPluginBuildInformation(pluginID, pluginType, version, signatureStatus st
|
||||
grafanaPluginBuildInfoDesc.WithLabelValues(pluginID, pluginType, version, signatureStatus).Set(1)
|
||||
}
|
||||
|
||||
func SetPluginTargetInformation(pluginID, target string) {
|
||||
grafanaPluginTargetInfoDesc.WithLabelValues(pluginID, target).Set(1)
|
||||
}
|
||||
|
||||
func initMetricVars(reg prometheus.Registerer) {
|
||||
reg.MustRegister(
|
||||
MInstanceStart,
|
||||
@@ -764,6 +776,7 @@ func initMetricVars(reg prometheus.Registerer) {
|
||||
StatsTotalActiveAdmins,
|
||||
StatsTotalDataSources,
|
||||
grafanaPluginBuildInfoDesc,
|
||||
grafanaPluginTargetInfoDesc,
|
||||
StatsTotalDashboardVersions,
|
||||
StatsTotalAnnotations,
|
||||
StatsTotalAlertRules,
|
||||
|
||||
@@ -127,6 +127,10 @@ func (pc *FakePluginClient) IsDecommissioned() bool {
|
||||
return pc.decommissioned
|
||||
}
|
||||
|
||||
func (pc *FakePluginClient) Target() backendplugin.Target {
|
||||
return "test-target"
|
||||
}
|
||||
|
||||
func (pc *FakePluginClient) CollectMetrics(ctx context.Context, req *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
||||
if pc.CollectMetricsHandlerFunc != nil {
|
||||
return pc.CollectMetricsHandlerFunc(ctx, req)
|
||||
@@ -646,3 +650,7 @@ func (p *FakeBackendPlugin) Kill() {
|
||||
defer p.mutex.Unlock()
|
||||
p.Running = false
|
||||
}
|
||||
|
||||
func (p *FakeBackendPlugin) Target() backendplugin.Target {
|
||||
return "test-target"
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ func ProvideInitializationStage(cfg *config.PluginManagementCfg, pr registry.Ser
|
||||
RegisterPluginRolesStep(roleRegistry),
|
||||
RegisterActionSetsStep(actionSetRegistry),
|
||||
ReportBuildMetrics,
|
||||
ReportTargetMetrics,
|
||||
initialization.PluginRegistrationStep(pr),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -127,6 +127,16 @@ func ReportBuildMetrics(_ context.Context, p *plugins.Plugin) (*plugins.Plugin,
|
||||
if !p.IsCorePlugin() && !p.IsBundledPlugin() {
|
||||
metrics.SetPluginBuildInformation(p.ID, string(p.Type), p.Info.Version, string(p.Signature))
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// ReportTargetMetrics reports target information for all backend plugins.
|
||||
func ReportTargetMetrics(_ context.Context, p *plugins.Plugin) (*plugins.Plugin, error) {
|
||||
if p.Backend {
|
||||
metrics.SetPluginTargetInformation(p.ID, string(p.Target()))
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user