From 36f503e688ac73ec9db813c3013e32b8e641f061 Mon Sep 17 00:00:00 2001 From: Cristian Greco Date: Mon, 25 Nov 2024 17:51:35 +0100 Subject: [PATCH] fixes --- .../mysql/collector/connection_info.go | 6 +++++- .../mysql/collector/connection_info_test.go | 2 +- .../database_observability/mysql/collector/query_sample.go | 2 +- .../database_observability/mysql/collector/schema_table.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/component/database_observability/mysql/collector/connection_info.go b/internal/component/database_observability/mysql/collector/connection_info.go index 7c27165ec3..bd890788a0 100644 --- a/internal/component/database_observability/mysql/collector/connection_info.go +++ b/internal/component/database_observability/mysql/collector/connection_info.go @@ -44,7 +44,11 @@ func (c *ConnectionInfo) Start(ctx context.Context) error { return err } - var providerName, providerRegion, dbInstanceIdentifier string + var ( + providerName = "unknown" + providerRegion = "unknown" + dbInstanceIdentifier = "unknown" + ) host, _, err := net.SplitHostPort(cfg.Addr) if err == nil && host != "" { diff --git a/internal/component/database_observability/mysql/collector/connection_info_test.go b/internal/component/database_observability/mysql/collector/connection_info_test.go index 91a16affc8..67ec6195c4 100644 --- a/internal/component/database_observability/mysql/collector/connection_info_test.go +++ b/internal/component/database_observability/mysql/collector/connection_info_test.go @@ -29,7 +29,7 @@ func TestConnectionInfo(t *testing.T) { { name: "generic dsn", dsn: "user:pass@tcp(localhost:3306)/db", - expectedMetrics: fmt.Sprintf(baseExpectedMetrics, "", "", ""), + expectedMetrics: fmt.Sprintf(baseExpectedMetrics, "unknown", "unknown", "unknown"), }, { name: "AWS/RDS dsn", diff --git a/internal/component/database_observability/mysql/collector/query_sample.go b/internal/component/database_observability/mysql/collector/query_sample.go index a927c666ce..3d6f52966d 100644 --- a/internal/component/database_observability/mysql/collector/query_sample.go +++ b/internal/component/database_observability/mysql/collector/query_sample.go @@ -71,6 +71,7 @@ func (c *QuerySample) Start(ctx context.Context) error { for { if err := c.fetchQuerySamples(c.ctx); err != nil { level.Error(c.logger).Log("msg", "collector stopping due to error", "err", err) + c.Stop() break } @@ -83,7 +84,6 @@ func (c *QuerySample) Start(ctx context.Context) error { } }() - c.Stop() return nil } diff --git a/internal/component/database_observability/mysql/collector/schema_table.go b/internal/component/database_observability/mysql/collector/schema_table.go index c2f3380340..21ecbba17c 100644 --- a/internal/component/database_observability/mysql/collector/schema_table.go +++ b/internal/component/database_observability/mysql/collector/schema_table.go @@ -102,6 +102,7 @@ func (c *SchemaTable) Start(ctx context.Context) error { for { if err := c.extractSchema(c.ctx); err != nil { level.Error(c.logger).Log("msg", "collector stopping due to error", "err", err) + c.Stop() break } @@ -114,7 +115,6 @@ func (c *SchemaTable) Start(ctx context.Context) error { } }() - c.Stop() return nil }