From 0465b91d089abc992be811c1f16d582413d060b0 Mon Sep 17 00:00:00 2001 From: Amit Schendel <58078857+amitschendel@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:16:15 +0300 Subject: [PATCH] Adding node name and cluster to init (#254) * Adding node name and cluster to init Signed-off-by: Amit Schendel * Adding test case Signed-off-by: Amit Schendel --------- Signed-off-by: Amit Schendel --- pkg/exporters/http_exporter.go | 4 +++- pkg/exporters/http_exporter_test.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/exporters/http_exporter.go b/pkg/exporters/http_exporter.go index a5fe3a7e..132a4d08 100644 --- a/pkg/exporters/http_exporter.go +++ b/pkg/exporters/http_exporter.go @@ -82,7 +82,9 @@ func InitHTTPExporter(config HTTPExporterConfig, clusterName string, nodeName st } return &HTTPExporter{ - config: config, + ClusterName: clusterName, + NodeName: nodeName, + config: config, httpClient: &http.Client{ Timeout: time.Duration(config.TimeoutSeconds) * time.Second, }, diff --git a/pkg/exporters/http_exporter_test.go b/pkg/exporters/http_exporter_test.go index 37d73009..22014753 100644 --- a/pkg/exporters/http_exporter_test.go +++ b/pkg/exporters/http_exporter_test.go @@ -240,12 +240,14 @@ func TestValidateHTTPExporterConfig(t *testing.T) { // Test case: URL is not empty exp, err := InitHTTPExporter(HTTPExporterConfig{ URL: "http://localhost:9093", - }, "", "") + }, "cluster", "node") assert.NoError(t, err) assert.Equal(t, "POST", exp.config.Method) assert.Equal(t, 5, exp.config.TimeoutSeconds) assert.Equal(t, 10000, exp.config.MaxAlertsPerMinute) assert.Equal(t, map[string]string{}, exp.config.Headers) + assert.Equal(t, "cluster", exp.ClusterName) + assert.Equal(t, "node", exp.NodeName) // Test case: Method is PUT exp, err = InitHTTPExporter(HTTPExporterConfig{