nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: NetApp/harvest
Pull request #1789 (2023-03-01 15:33:38)

feat: add datacenter to metadata exporter_time metrics
Fixes: #1432


Patch:
diff --git a/cmd/poller/exporter/exporter.go b/cmd/poller/exporter/exporter.go
index 6d9215d2..9bc093b6 100644
--- a/cmd/poller/exporter/exporter.go
+++ b/cmd/poller/exporter/exporter.go
@@ -59,7 +59,7 @@ type AbstractExporter struct {
 // @n - exporter name
 // @o - poller options
 // @p - exporter parameters
-func New(c, n string, o *options.Options, p conf.Exporter) *AbstractExporter {
+func New(c, n string, o *options.Options, p conf.Exporter, params *conf.Poller) *AbstractExporter {
 	abc := AbstractExporter{
 		Class:    c,
 		Name:     n,
@@ -68,13 +68,16 @@ func New(c, n string, o *options.Options, p conf.Exporter) *AbstractExporter {
 		Logger:   logging.Get().SubLogger("exporter", n),
 		Mutex:    &sync.Mutex{},
 		countMux: &sync.Mutex{},
+		Metadata: matrix.New(n, "metadata_exporter", "metadata_exporter"),
+	}
+	if params != nil {
+		abc.Metadata.SetGlobalLabel("datacenter", params.Datacenter)
 	}
 	return &abc
 }
 
-// InitAbc() initializes AbstractExporter
+// InitAbc initializes AbstractExporter
 func (me *AbstractExporter) InitAbc() error {
-	me.Metadata = matrix.New(me.Name, "metadata_exporter", "metadata_exporter")
 	me.Metadata.SetGlobalLabel("hostname", me.Options.Hostname)
 	me.Metadata.SetGlobalLabel("version", me.Options.Version)
 	me.Metadata.SetGlobalLabel("poller", me.Options.Poller)
diff --git a/cmd/poller/poller.go b/cmd/poller/poller.go
index cd9a75c8..e016eff3 100644
--- a/cmd/poller/poller.go
+++ b/cmd/poller/poller.go
@@ -867,7 +867,7 @@ func (p *Poller) loadExporter(name string) exporter.Exporter {
 		return nil
 	}
 
-	absExp := exporter.New(class, name, p.options, params)
+	absExp := exporter.New(class, name, p.options, params, p.params)
 	switch class {
 	case "Prometheus":
 		exp = prometheus.New(absExp)


Test patch:
diff --git a/cmd/exporters/influxdb/influxdb_test.go b/cmd/exporters/influxdb/influxdb_test.go
index fd2227f9..f852e810 100644
--- a/cmd/exporters/influxdb/influxdb_test.go
+++ b/cmd/exporters/influxdb/influxdb_test.go
@@ -24,7 +24,7 @@ func setupInfluxDB(t *testing.T, exporterName string) *InfluxDB {
 		t.Fatalf(`exporter (%v) not defined in config`, exporterName)
 	}
 
-	influx := &InfluxDB{AbstractExporter: exporter.New("InfluxDB", exporterName, opts, e)}
+	influx := &InfluxDB{AbstractExporter: exporter.New("InfluxDB", exporterName, opts, e, nil)}
 	if err := influx.Init(); err != nil {
 		t.Fatal(err)
 	}