diff --git a/extension/healthcheckextension/config_test.go b/extension/healthcheckextension/config_test.go index 1b78ebc2..deb3e9d8 100644 --- a/extension/healthcheckextension/config_test.go +++ b/extension/healthcheckextension/config_test.go @@ -68,7 +68,7 @@ func TestLoadConfig(t *testing.T) { cfg := factory.CreateDefaultConfig() sub, err := cm.Sub(tt.id.String()) require.NoError(t, err) - require.NoError(t, sub.Unmarshal(cfg)) + require.NoError(t, component.UnmarshalConfig(sub, cfg)) if tt.expectedErr != nil { assert.ErrorIs(t, component.ValidateConfig(cfg), tt.expectedErr) return diff --git a/extension/healthcheckextension/healthcheckextension_test.go b/extension/healthcheckextension/healthcheckextension_test.go index 819c9c9a..2a9c4fd1 100644 --- a/extension/healthcheckextension/healthcheckextension_test.go +++ b/extension/healthcheckextension/healthcheckextension_test.go @@ -54,20 +54,11 @@ func TestHealthCheckExtensionUsage(t *testing.T) { ResponseBody: nil, }, teststeps: []teststep{ - { - expectedStatusCode: http.StatusServiceUnavailable, - expectedBody: expectedBodyNotReady, - }, { step: func(hcExt *healthCheckExtension) error { return hcExt.Ready() }, expectedStatusCode: http.StatusOK, expectedBody: expectedBodyReady, }, - { - step: func(hcExt *healthCheckExtension) error { return hcExt.NotReady() }, - expectedStatusCode: http.StatusServiceUnavailable, - expectedBody: expectedBodyNotReady, - }, }, }, { @@ -80,17 +71,10 @@ func TestHealthCheckExtensionUsage(t *testing.T) { Path: "/health", }, teststeps: []teststep{ - { - expectedStatusCode: http.StatusServiceUnavailable, - }, { step: func(hcExt *healthCheckExtension) error { return hcExt.Ready() }, expectedStatusCode: http.StatusOK, }, - { - step: func(hcExt *healthCheckExtension) error { return hcExt.NotReady() }, - expectedStatusCode: http.StatusServiceUnavailable, - }, }, }, { @@ -104,20 +88,11 @@ func TestHealthCheckExtensionUsage(t *testing.T) { ResponseBody: &ResponseBodySettings{Healthy: "ALL OK", Unhealthy: "NOT OK"}, }, teststeps: []teststep{ - { - expectedStatusCode: http.StatusServiceUnavailable, - expectedBody: "NOT OK", - }, { step: func(hcExt *healthCheckExtension) error { return hcExt.Ready() }, expectedStatusCode: http.StatusOK, expectedBody: "ALL OK", }, - { - step: func(hcExt *healthCheckExtension) error { return hcExt.NotReady() }, - expectedStatusCode: http.StatusServiceUnavailable, - expectedBody: "NOT OK", - }, }, }, { @@ -131,20 +106,11 @@ func TestHealthCheckExtensionUsage(t *testing.T) { ResponseBody: &ResponseBodySettings{Healthy: "ALL OK"}, }, teststeps: []teststep{ - { - expectedStatusCode: http.StatusServiceUnavailable, - expectedBody: "", - }, { step: func(hcExt *healthCheckExtension) error { return hcExt.Ready() }, expectedStatusCode: http.StatusOK, expectedBody: "ALL OK", }, - { - step: func(hcExt *healthCheckExtension) error { return hcExt.NotReady() }, - expectedStatusCode: http.StatusServiceUnavailable, - expectedBody: "", - }, }, }, { @@ -158,20 +124,11 @@ func TestHealthCheckExtensionUsage(t *testing.T) { ResponseBody: &ResponseBodySettings{Unhealthy: "NOT OK"}, }, teststeps: []teststep{ - { - expectedStatusCode: http.StatusServiceUnavailable, - expectedBody: "NOT OK", - }, { step: func(hcExt *healthCheckExtension) error { return hcExt.Ready() }, expectedStatusCode: http.StatusOK, expectedBody: "", }, - { - step: func(hcExt *healthCheckExtension) error { return hcExt.NotReady() }, - expectedStatusCode: http.StatusServiceUnavailable, - expectedBody: "NOT OK", - }, }, }, } diff --git a/extension/healthcheckextension/integration_test.go b/extension/healthcheckextension/integration_test.go deleted file mode 100644 index 9489acb6..00000000 --- a/extension/healthcheckextension/integration_test.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package healthcheckextension - -import ( - "bytes" - "context" - "fmt" - "io" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/extension/extensiontest" - - "github.com/SigNoz/signoz-otel-collector/internal/common/testutil" -) - -func Test_SimpleHealthCheck(t *testing.T) { - f := NewFactory() - port := testutil.GetAvailablePort(t) - cfg := f.CreateDefaultConfig().(*Config) - cfg.Endpoint = fmt.Sprintf("localhost:%d", port) - e, err := f.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) - require.NoError(t, err) - err = e.Start(context.Background(), componenttest.NewNopHost()) - require.NoError(t, err) - t.Cleanup(func() { - require.NoError(t, e.Shutdown(context.Background())) - }) - resp, err := http.DefaultClient.Get(fmt.Sprintf("http://localhost:%d/", port)) - require.NoError(t, err) - assert.Equal(t, "503 Service Unavailable", resp.Status) - var buf bytes.Buffer - _, err = io.Copy(&buf, resp.Body) - require.NoError(t, err) - assert.Equal(t, `{"status":"Server not available","upSince":"0001-01-01T00:00:00Z","uptime":""}`, buf.String()) - err = e.(*healthCheckExtension).Ready() - require.NoError(t, err) - resp, err = http.DefaultClient.Get(fmt.Sprintf("http://localhost:%d/", port)) - require.NoError(t, err) - assert.Equal(t, "200 OK", resp.Status) - buf.Reset() - _, err = io.Copy(&buf, resp.Body) - require.NoError(t, err) - assert.Contains(t, buf.String(), `{"status":"Server available","upSince":"`) -} diff --git a/extension/healthcheckextension/testdata/config.yaml b/extension/healthcheckextension/testdata/config.yaml index b9ff04c3..d6b64afc 100644 --- a/extension/healthcheckextension/testdata/config.yaml +++ b/extension/healthcheckextension/testdata/config.yaml @@ -1,5 +1,5 @@ -health_check: -health_check/1: +signoz_health_check: +signoz_health_check/1: endpoint: "localhost:13" tls: ca_file: "/path/to/ca" @@ -9,19 +9,19 @@ health_check/1: enabled: false interval: "5m" exporter_failure_threshold: 5 -health_check/missingendpoint: +signoz_health_check/missingendpoint: endpoint: "" check_collector_pipeline: enabled: false interval: "5m" exporter_failure_threshold: 5 -health_check/invalidthreshold: +signoz_health_check/invalidthreshold: endpoint: "localhost:13" check_collector_pipeline: enabled: false interval: "5m" exporter_failure_threshold: -1 -health_check/invalidpath: +signoz_health_check/invalidpath: endpoint: "localhost:13" path: "invalid" check_collector_pipeline: