From 20d536bbaac1686854b26f9017b52257b04ea7d3 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Thu, 16 May 2024 15:40:54 -0700 Subject: [PATCH] Changes requested in PR - rename metric to sqlserver.database.count - Add more info to err log --- receiver/sqlserverreceiver/documentation.md | 32 ++--- receiver/sqlserverreceiver/factory.go | 2 +- .../internal/metadata/generated_config.go | 8 +- .../metadata/generated_config_test.go | 4 +- .../internal/metadata/generated_metrics.go | 128 +++++++++--------- .../metadata/generated_metrics_test.go | 36 ++--- .../internal/metadata/testdata/config.yaml | 8 +- receiver/sqlserverreceiver/metadata.yaml | 4 +- receiver/sqlserverreceiver/scraper.go | 14 +- receiver/sqlserverreceiver/scraper_test.go | 2 +- .../testdata/expectedProperties.yaml | 4 +- 11 files changed, 121 insertions(+), 121 deletions(-) diff --git a/receiver/sqlserverreceiver/documentation.md b/receiver/sqlserverreceiver/documentation.md index 3b19693812d0..036e09733671 100644 --- a/receiver/sqlserverreceiver/documentation.md +++ b/receiver/sqlserverreceiver/documentation.md @@ -226,6 +226,22 @@ metrics: enabled: true ``` +### sqlserver.database.count + +The number of databases + +This metric is only available when the receiver is configured to directly connect to SQL Server. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| {databases} | Gauge | Int | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| database.status | The current status of a database | Str: ``online``, ``restoring``, ``recovering``, ``pending_recovery``, ``suspect``, ``offline`` | + ### sqlserver.database.io.read_latency Total time that the users waited for reads issued on this file. @@ -254,22 +270,6 @@ This metric is only available when the receiver is configured to directly connec | ---- | ----------- | ---------- | | {processes} | Gauge | Int | -### sqlserver.properties.db.status - -The number of databases that are in a given state. - -This metric is only available when the receiver is configured to directly connect to SQL Server. - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| {databases} | Gauge | Int | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| database.status | The current status of a database | Str: ``online``, ``restoring``, ``recovering``, ``pending_recovery``, ``suspect``, ``offline`` | - ### sqlserver.resource_pool.disk.throttled.read.rate The number of read operations that were throttled in the last second diff --git a/receiver/sqlserverreceiver/factory.go b/receiver/sqlserverreceiver/factory.go index bd5ecbb6b951..104f0efcd06e 100644 --- a/receiver/sqlserverreceiver/factory.go +++ b/receiver/sqlserverreceiver/factory.go @@ -51,7 +51,7 @@ func setupQueries(cfg *Config) []string { queries = append(queries, getSQLServerPerformanceCounterQuery(cfg.InstanceName)) } - if cfg.MetricsBuilderConfig.Metrics.SqlserverPropertiesDbStatus.Enabled { + if cfg.MetricsBuilderConfig.Metrics.SqlserverDatabaseCount.Enabled { queries = append(queries, getSQLServerPropertiesQuery(cfg.InstanceName)) } diff --git a/receiver/sqlserverreceiver/internal/metadata/generated_config.go b/receiver/sqlserverreceiver/internal/metadata/generated_config.go index b6ef32f1114a..65d7ab429d51 100644 --- a/receiver/sqlserverreceiver/internal/metadata/generated_config.go +++ b/receiver/sqlserverreceiver/internal/metadata/generated_config.go @@ -31,6 +31,7 @@ type MetricsConfig struct { SqlserverBatchRequestRate MetricConfig `mapstructure:"sqlserver.batch.request.rate"` SqlserverBatchSQLCompilationRate MetricConfig `mapstructure:"sqlserver.batch.sql_compilation.rate"` SqlserverBatchSQLRecompilationRate MetricConfig `mapstructure:"sqlserver.batch.sql_recompilation.rate"` + SqlserverDatabaseCount MetricConfig `mapstructure:"sqlserver.database.count"` SqlserverDatabaseIoReadLatency MetricConfig `mapstructure:"sqlserver.database.io.read_latency"` SqlserverLockWaitRate MetricConfig `mapstructure:"sqlserver.lock.wait.rate"` SqlserverLockWaitTimeAvg MetricConfig `mapstructure:"sqlserver.lock.wait_time.avg"` @@ -41,7 +42,6 @@ type MetricsConfig struct { SqlserverPageOperationRate MetricConfig `mapstructure:"sqlserver.page.operation.rate"` SqlserverPageSplitRate MetricConfig `mapstructure:"sqlserver.page.split.rate"` SqlserverProcessesBlocked MetricConfig `mapstructure:"sqlserver.processes.blocked"` - SqlserverPropertiesDbStatus MetricConfig `mapstructure:"sqlserver.properties.db.status"` SqlserverResourcePoolDiskThrottledReadRate MetricConfig `mapstructure:"sqlserver.resource_pool.disk.throttled.read.rate"` SqlserverResourcePoolDiskThrottledWriteRate MetricConfig `mapstructure:"sqlserver.resource_pool.disk.throttled.write.rate"` SqlserverTransactionRate MetricConfig `mapstructure:"sqlserver.transaction.rate"` @@ -66,6 +66,9 @@ func DefaultMetricsConfig() MetricsConfig { SqlserverBatchSQLRecompilationRate: MetricConfig{ Enabled: true, }, + SqlserverDatabaseCount: MetricConfig{ + Enabled: false, + }, SqlserverDatabaseIoReadLatency: MetricConfig{ Enabled: false, }, @@ -96,9 +99,6 @@ func DefaultMetricsConfig() MetricsConfig { SqlserverProcessesBlocked: MetricConfig{ Enabled: false, }, - SqlserverPropertiesDbStatus: MetricConfig{ - Enabled: false, - }, SqlserverResourcePoolDiskThrottledReadRate: MetricConfig{ Enabled: false, }, diff --git a/receiver/sqlserverreceiver/internal/metadata/generated_config_test.go b/receiver/sqlserverreceiver/internal/metadata/generated_config_test.go index 255092efc6d6..28b73eefd690 100644 --- a/receiver/sqlserverreceiver/internal/metadata/generated_config_test.go +++ b/receiver/sqlserverreceiver/internal/metadata/generated_config_test.go @@ -29,6 +29,7 @@ func TestMetricsBuilderConfig(t *testing.T) { SqlserverBatchRequestRate: MetricConfig{Enabled: true}, SqlserverBatchSQLCompilationRate: MetricConfig{Enabled: true}, SqlserverBatchSQLRecompilationRate: MetricConfig{Enabled: true}, + SqlserverDatabaseCount: MetricConfig{Enabled: true}, SqlserverDatabaseIoReadLatency: MetricConfig{Enabled: true}, SqlserverLockWaitRate: MetricConfig{Enabled: true}, SqlserverLockWaitTimeAvg: MetricConfig{Enabled: true}, @@ -39,7 +40,6 @@ func TestMetricsBuilderConfig(t *testing.T) { SqlserverPageOperationRate: MetricConfig{Enabled: true}, SqlserverPageSplitRate: MetricConfig{Enabled: true}, SqlserverProcessesBlocked: MetricConfig{Enabled: true}, - SqlserverPropertiesDbStatus: MetricConfig{Enabled: true}, SqlserverResourcePoolDiskThrottledReadRate: MetricConfig{Enabled: true}, SqlserverResourcePoolDiskThrottledWriteRate: MetricConfig{Enabled: true}, SqlserverTransactionRate: MetricConfig{Enabled: true}, @@ -66,6 +66,7 @@ func TestMetricsBuilderConfig(t *testing.T) { SqlserverBatchRequestRate: MetricConfig{Enabled: false}, SqlserverBatchSQLCompilationRate: MetricConfig{Enabled: false}, SqlserverBatchSQLRecompilationRate: MetricConfig{Enabled: false}, + SqlserverDatabaseCount: MetricConfig{Enabled: false}, SqlserverDatabaseIoReadLatency: MetricConfig{Enabled: false}, SqlserverLockWaitRate: MetricConfig{Enabled: false}, SqlserverLockWaitTimeAvg: MetricConfig{Enabled: false}, @@ -76,7 +77,6 @@ func TestMetricsBuilderConfig(t *testing.T) { SqlserverPageOperationRate: MetricConfig{Enabled: false}, SqlserverPageSplitRate: MetricConfig{Enabled: false}, SqlserverProcessesBlocked: MetricConfig{Enabled: false}, - SqlserverPropertiesDbStatus: MetricConfig{Enabled: false}, SqlserverResourcePoolDiskThrottledReadRate: MetricConfig{Enabled: false}, SqlserverResourcePoolDiskThrottledWriteRate: MetricConfig{Enabled: false}, SqlserverTransactionRate: MetricConfig{Enabled: false}, diff --git a/receiver/sqlserverreceiver/internal/metadata/generated_metrics.go b/receiver/sqlserverreceiver/internal/metadata/generated_metrics.go index 3ebf9676d538..97b5907cd787 100644 --- a/receiver/sqlserverreceiver/internal/metadata/generated_metrics.go +++ b/receiver/sqlserverreceiver/internal/metadata/generated_metrics.go @@ -229,6 +229,57 @@ func newMetricSqlserverBatchSQLRecompilationRate(cfg MetricConfig) metricSqlserv return m } +type metricSqlserverDatabaseCount struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills sqlserver.database.count metric with initial data. +func (m *metricSqlserverDatabaseCount) init() { + m.data.SetName("sqlserver.database.count") + m.data.SetDescription("The number of databases") + m.data.SetUnit("{databases}") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricSqlserverDatabaseCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, databaseStatusAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("database.status", databaseStatusAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSqlserverDatabaseCount) updateCapacity() { + if m.data.Gauge().DataPoints().Len() > m.capacity { + m.capacity = m.data.Gauge().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricSqlserverDatabaseCount) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSqlserverDatabaseCount(cfg MetricConfig) metricSqlserverDatabaseCount { + m := metricSqlserverDatabaseCount{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricSqlserverDatabaseIoReadLatency struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -727,57 +778,6 @@ func newMetricSqlserverProcessesBlocked(cfg MetricConfig) metricSqlserverProcess return m } -type metricSqlserverPropertiesDbStatus struct { - data pmetric.Metric // data buffer for generated metric. - config MetricConfig // metric config provided by user. - capacity int // max observed number of data points added to the metric. -} - -// init fills sqlserver.properties.db.status metric with initial data. -func (m *metricSqlserverPropertiesDbStatus) init() { - m.data.SetName("sqlserver.properties.db.status") - m.data.SetDescription("The number of databases that are in a given state.") - m.data.SetUnit("{databases}") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricSqlserverPropertiesDbStatus) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, databaseStatusAttributeValue string) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("database.status", databaseStatusAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricSqlserverPropertiesDbStatus) updateCapacity() { - if m.data.Gauge().DataPoints().Len() > m.capacity { - m.capacity = m.data.Gauge().DataPoints().Len() - } -} - -// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricSqlserverPropertiesDbStatus) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricSqlserverPropertiesDbStatus(cfg MetricConfig) metricSqlserverPropertiesDbStatus { - m := metricSqlserverPropertiesDbStatus{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - type metricSqlserverResourcePoolDiskThrottledReadRate struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -1334,6 +1334,7 @@ type MetricsBuilder struct { metricSqlserverBatchRequestRate metricSqlserverBatchRequestRate metricSqlserverBatchSQLCompilationRate metricSqlserverBatchSQLCompilationRate metricSqlserverBatchSQLRecompilationRate metricSqlserverBatchSQLRecompilationRate + metricSqlserverDatabaseCount metricSqlserverDatabaseCount metricSqlserverDatabaseIoReadLatency metricSqlserverDatabaseIoReadLatency metricSqlserverLockWaitRate metricSqlserverLockWaitRate metricSqlserverLockWaitTimeAvg metricSqlserverLockWaitTimeAvg @@ -1344,7 +1345,6 @@ type MetricsBuilder struct { metricSqlserverPageOperationRate metricSqlserverPageOperationRate metricSqlserverPageSplitRate metricSqlserverPageSplitRate metricSqlserverProcessesBlocked metricSqlserverProcessesBlocked - metricSqlserverPropertiesDbStatus metricSqlserverPropertiesDbStatus metricSqlserverResourcePoolDiskThrottledReadRate metricSqlserverResourcePoolDiskThrottledReadRate metricSqlserverResourcePoolDiskThrottledWriteRate metricSqlserverResourcePoolDiskThrottledWriteRate metricSqlserverTransactionRate metricSqlserverTransactionRate @@ -1377,6 +1377,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricSqlserverBatchRequestRate: newMetricSqlserverBatchRequestRate(mbc.Metrics.SqlserverBatchRequestRate), metricSqlserverBatchSQLCompilationRate: newMetricSqlserverBatchSQLCompilationRate(mbc.Metrics.SqlserverBatchSQLCompilationRate), metricSqlserverBatchSQLRecompilationRate: newMetricSqlserverBatchSQLRecompilationRate(mbc.Metrics.SqlserverBatchSQLRecompilationRate), + metricSqlserverDatabaseCount: newMetricSqlserverDatabaseCount(mbc.Metrics.SqlserverDatabaseCount), metricSqlserverDatabaseIoReadLatency: newMetricSqlserverDatabaseIoReadLatency(mbc.Metrics.SqlserverDatabaseIoReadLatency), metricSqlserverLockWaitRate: newMetricSqlserverLockWaitRate(mbc.Metrics.SqlserverLockWaitRate), metricSqlserverLockWaitTimeAvg: newMetricSqlserverLockWaitTimeAvg(mbc.Metrics.SqlserverLockWaitTimeAvg), @@ -1387,7 +1388,6 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricSqlserverPageOperationRate: newMetricSqlserverPageOperationRate(mbc.Metrics.SqlserverPageOperationRate), metricSqlserverPageSplitRate: newMetricSqlserverPageSplitRate(mbc.Metrics.SqlserverPageSplitRate), metricSqlserverProcessesBlocked: newMetricSqlserverProcessesBlocked(mbc.Metrics.SqlserverProcessesBlocked), - metricSqlserverPropertiesDbStatus: newMetricSqlserverPropertiesDbStatus(mbc.Metrics.SqlserverPropertiesDbStatus), metricSqlserverResourcePoolDiskThrottledReadRate: newMetricSqlserverResourcePoolDiskThrottledReadRate(mbc.Metrics.SqlserverResourcePoolDiskThrottledReadRate), metricSqlserverResourcePoolDiskThrottledWriteRate: newMetricSqlserverResourcePoolDiskThrottledWriteRate(mbc.Metrics.SqlserverResourcePoolDiskThrottledWriteRate), metricSqlserverTransactionRate: newMetricSqlserverTransactionRate(mbc.Metrics.SqlserverTransactionRate), @@ -1484,6 +1484,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricSqlserverBatchRequestRate.emit(ils.Metrics()) mb.metricSqlserverBatchSQLCompilationRate.emit(ils.Metrics()) mb.metricSqlserverBatchSQLRecompilationRate.emit(ils.Metrics()) + mb.metricSqlserverDatabaseCount.emit(ils.Metrics()) mb.metricSqlserverDatabaseIoReadLatency.emit(ils.Metrics()) mb.metricSqlserverLockWaitRate.emit(ils.Metrics()) mb.metricSqlserverLockWaitTimeAvg.emit(ils.Metrics()) @@ -1494,7 +1495,6 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricSqlserverPageOperationRate.emit(ils.Metrics()) mb.metricSqlserverPageSplitRate.emit(ils.Metrics()) mb.metricSqlserverProcessesBlocked.emit(ils.Metrics()) - mb.metricSqlserverPropertiesDbStatus.emit(ils.Metrics()) mb.metricSqlserverResourcePoolDiskThrottledReadRate.emit(ils.Metrics()) mb.metricSqlserverResourcePoolDiskThrottledWriteRate.emit(ils.Metrics()) mb.metricSqlserverTransactionRate.emit(ils.Metrics()) @@ -1552,6 +1552,16 @@ func (mb *MetricsBuilder) RecordSqlserverBatchSQLRecompilationRateDataPoint(ts p mb.metricSqlserverBatchSQLRecompilationRate.recordDataPoint(mb.startTime, ts, val) } +// RecordSqlserverDatabaseCountDataPoint adds a data point to sqlserver.database.count metric. +func (mb *MetricsBuilder) RecordSqlserverDatabaseCountDataPoint(ts pcommon.Timestamp, inputVal string, databaseStatusAttributeValue AttributeDatabaseStatus) error { + val, err := strconv.ParseInt(inputVal, 10, 64) + if err != nil { + return fmt.Errorf("failed to parse int64 for SqlserverDatabaseCount, value was %s: %w", inputVal, err) + } + mb.metricSqlserverDatabaseCount.recordDataPoint(mb.startTime, ts, val, databaseStatusAttributeValue.String()) + return nil +} + // RecordSqlserverDatabaseIoReadLatencyDataPoint adds a data point to sqlserver.database.io.read_latency metric. func (mb *MetricsBuilder) RecordSqlserverDatabaseIoReadLatencyDataPoint(ts pcommon.Timestamp, val float64, physicalFilenameAttributeValue string, logicalFilenameAttributeValue string, fileTypeAttributeValue string) { mb.metricSqlserverDatabaseIoReadLatency.recordDataPoint(mb.startTime, ts, val, physicalFilenameAttributeValue, logicalFilenameAttributeValue, fileTypeAttributeValue) @@ -1607,16 +1617,6 @@ func (mb *MetricsBuilder) RecordSqlserverProcessesBlockedDataPoint(ts pcommon.Ti return nil } -// RecordSqlserverPropertiesDbStatusDataPoint adds a data point to sqlserver.properties.db.status metric. -func (mb *MetricsBuilder) RecordSqlserverPropertiesDbStatusDataPoint(ts pcommon.Timestamp, inputVal string, databaseStatusAttributeValue AttributeDatabaseStatus) error { - val, err := strconv.ParseInt(inputVal, 10, 64) - if err != nil { - return fmt.Errorf("failed to parse int64 for SqlserverPropertiesDbStatus, value was %s: %w", inputVal, err) - } - mb.metricSqlserverPropertiesDbStatus.recordDataPoint(mb.startTime, ts, val, databaseStatusAttributeValue.String()) - return nil -} - // RecordSqlserverResourcePoolDiskThrottledReadRateDataPoint adds a data point to sqlserver.resource_pool.disk.throttled.read.rate metric. func (mb *MetricsBuilder) RecordSqlserverResourcePoolDiskThrottledReadRateDataPoint(ts pcommon.Timestamp, inputVal string) error { val, err := strconv.ParseInt(inputVal, 10, 64) diff --git a/receiver/sqlserverreceiver/internal/metadata/generated_metrics_test.go b/receiver/sqlserverreceiver/internal/metadata/generated_metrics_test.go index f28fc40bd2c4..b7cc17409a29 100644 --- a/receiver/sqlserverreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/sqlserverreceiver/internal/metadata/generated_metrics_test.go @@ -80,6 +80,9 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordSqlserverBatchSQLRecompilationRateDataPoint(ts, 1) + allMetricsCount++ + mb.RecordSqlserverDatabaseCountDataPoint(ts, "1", AttributeDatabaseStatusOnline) + allMetricsCount++ mb.RecordSqlserverDatabaseIoReadLatencyDataPoint(ts, 1, "physical_filename-val", "logical_filename-val", "file_type-val") @@ -118,9 +121,6 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordSqlserverProcessesBlockedDataPoint(ts, "1") - allMetricsCount++ - mb.RecordSqlserverPropertiesDbStatusDataPoint(ts, "1", AttributeDatabaseStatusOnline) - allMetricsCount++ mb.RecordSqlserverResourcePoolDiskThrottledReadRateDataPoint(ts, "1") @@ -225,6 +225,21 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) assert.Equal(t, float64(1), dp.DoubleValue()) + case "sqlserver.database.count": + assert.False(t, validatedMetrics["sqlserver.database.count"], "Found a duplicate in the metrics slice: sqlserver.database.count") + validatedMetrics["sqlserver.database.count"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "The number of databases", ms.At(i).Description()) + assert.Equal(t, "{databases}", ms.At(i).Unit()) + dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + attrVal, ok := dp.Attributes().Get("database.status") + assert.True(t, ok) + assert.EqualValues(t, "online", attrVal.Str()) case "sqlserver.database.io.read_latency": assert.False(t, validatedMetrics["sqlserver.database.io.read_latency"], "Found a duplicate in the metrics slice: sqlserver.database.io.read_latency") validatedMetrics["sqlserver.database.io.read_latency"] = true @@ -359,21 +374,6 @@ func TestMetricsBuilder(t *testing.T) { assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) assert.Equal(t, int64(1), dp.IntValue()) - case "sqlserver.properties.db.status": - assert.False(t, validatedMetrics["sqlserver.properties.db.status"], "Found a duplicate in the metrics slice: sqlserver.properties.db.status") - validatedMetrics["sqlserver.properties.db.status"] = true - assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "The number of databases that are in a given state.", ms.At(i).Description()) - assert.Equal(t, "{databases}", ms.At(i).Unit()) - dp := ms.At(i).Gauge().DataPoints().At(0) - assert.Equal(t, start, dp.StartTimestamp()) - assert.Equal(t, ts, dp.Timestamp()) - assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) - assert.Equal(t, int64(1), dp.IntValue()) - attrVal, ok := dp.Attributes().Get("database.status") - assert.True(t, ok) - assert.EqualValues(t, "online", attrVal.Str()) case "sqlserver.resource_pool.disk.throttled.read.rate": assert.False(t, validatedMetrics["sqlserver.resource_pool.disk.throttled.read.rate"], "Found a duplicate in the metrics slice: sqlserver.resource_pool.disk.throttled.read.rate") validatedMetrics["sqlserver.resource_pool.disk.throttled.read.rate"] = true diff --git a/receiver/sqlserverreceiver/internal/metadata/testdata/config.yaml b/receiver/sqlserverreceiver/internal/metadata/testdata/config.yaml index cc760efd4284..449b7e435a9b 100644 --- a/receiver/sqlserverreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/sqlserverreceiver/internal/metadata/testdata/config.yaml @@ -7,6 +7,8 @@ all_set: enabled: true sqlserver.batch.sql_recompilation.rate: enabled: true + sqlserver.database.count: + enabled: true sqlserver.database.io.read_latency: enabled: true sqlserver.lock.wait.rate: @@ -27,8 +29,6 @@ all_set: enabled: true sqlserver.processes.blocked: enabled: true - sqlserver.properties.db.status: - enabled: true sqlserver.resource_pool.disk.throttled.read.rate: enabled: true sqlserver.resource_pool.disk.throttled.write.rate: @@ -66,6 +66,8 @@ none_set: enabled: false sqlserver.batch.sql_recompilation.rate: enabled: false + sqlserver.database.count: + enabled: false sqlserver.database.io.read_latency: enabled: false sqlserver.lock.wait.rate: @@ -86,8 +88,6 @@ none_set: enabled: false sqlserver.processes.blocked: enabled: false - sqlserver.properties.db.status: - enabled: false sqlserver.resource_pool.disk.throttled.read.rate: enabled: false sqlserver.resource_pool.disk.throttled.write.rate: diff --git a/receiver/sqlserverreceiver/metadata.yaml b/receiver/sqlserverreceiver/metadata.yaml index 700b697e9526..b8f063526d91 100644 --- a/receiver/sqlserverreceiver/metadata.yaml +++ b/receiver/sqlserverreceiver/metadata.yaml @@ -226,9 +226,9 @@ metrics: input_type: string attributes: [] extended_documentation: This metric is only available when the receiver is configured to directly connect to SQL Server. - sqlserver.properties.db.status: + sqlserver.database.count: enabled: false - description: The number of databases that are in a given state. + description: The number of databases unit: "{databases}" gauge: value_type: int diff --git a/receiver/sqlserverreceiver/scraper.go b/receiver/sqlserverreceiver/scraper.go index 351da4ad4a5b..3a69e87b0eb8 100644 --- a/receiver/sqlserverreceiver/scraper.go +++ b/receiver/sqlserverreceiver/scraper.go @@ -212,7 +212,7 @@ func (s *sqlServerScraperHelper) recordDatabaseStatusMetrics(ctx context.Context if errors.Is(err, sqlquery.ErrNullValueWarning) { s.logger.Warn("problems encountered getting metric rows", zap.Error(err)) } else { - return fmt.Errorf("sqlServerScraperHelper: %w", err) + return fmt.Errorf("sqlServerScraperHelper failed getting metric rows: %w", err) } } @@ -223,12 +223,12 @@ func (s *sqlServerScraperHelper) recordDatabaseStatusMetrics(ctx context.Context rb.SetSqlserverInstanceName(row[instanceNameKey]) } - errs = append(errs, s.mb.RecordSqlserverPropertiesDbStatusDataPoint(now, row[dbOnline], metadata.AttributeDatabaseStatusOnline)) - errs = append(errs, s.mb.RecordSqlserverPropertiesDbStatusDataPoint(now, row[dbRestoring], metadata.AttributeDatabaseStatusRestoring)) - errs = append(errs, s.mb.RecordSqlserverPropertiesDbStatusDataPoint(now, row[dbRecovering], metadata.AttributeDatabaseStatusRecovering)) - errs = append(errs, s.mb.RecordSqlserverPropertiesDbStatusDataPoint(now, row[dbPendingRecovery], metadata.AttributeDatabaseStatusPendingRecovery)) - errs = append(errs, s.mb.RecordSqlserverPropertiesDbStatusDataPoint(now, row[dbSuspect], metadata.AttributeDatabaseStatusSuspect)) - errs = append(errs, s.mb.RecordSqlserverPropertiesDbStatusDataPoint(now, row[dbOffline], metadata.AttributeDatabaseStatusOffline)) + errs = append(errs, s.mb.RecordSqlserverDatabaseCountDataPoint(now, row[dbOnline], metadata.AttributeDatabaseStatusOnline)) + errs = append(errs, s.mb.RecordSqlserverDatabaseCountDataPoint(now, row[dbRestoring], metadata.AttributeDatabaseStatusRestoring)) + errs = append(errs, s.mb.RecordSqlserverDatabaseCountDataPoint(now, row[dbRecovering], metadata.AttributeDatabaseStatusRecovering)) + errs = append(errs, s.mb.RecordSqlserverDatabaseCountDataPoint(now, row[dbPendingRecovery], metadata.AttributeDatabaseStatusPendingRecovery)) + errs = append(errs, s.mb.RecordSqlserverDatabaseCountDataPoint(now, row[dbSuspect], metadata.AttributeDatabaseStatusSuspect)) + errs = append(errs, s.mb.RecordSqlserverDatabaseCountDataPoint(now, row[dbOffline], metadata.AttributeDatabaseStatusOffline)) } diff --git a/receiver/sqlserverreceiver/scraper_test.go b/receiver/sqlserverreceiver/scraper_test.go index d44b63f18698..5c09786cc73a 100644 --- a/receiver/sqlserverreceiver/scraper_test.go +++ b/receiver/sqlserverreceiver/scraper_test.go @@ -27,7 +27,7 @@ func enableAllScraperMetrics(cfg *Config) { cfg.MetricsBuilderConfig.Metrics.SqlserverResourcePoolDiskThrottledWriteRate.Enabled = true cfg.MetricsBuilderConfig.Metrics.SqlserverProcessesBlocked.Enabled = true - cfg.MetricsBuilderConfig.Metrics.SqlserverPropertiesDbStatus.Enabled = true + cfg.MetricsBuilderConfig.Metrics.SqlserverDatabaseCount.Enabled = true } func TestEmptyScrape(t *testing.T) { diff --git a/receiver/sqlserverreceiver/testdata/expectedProperties.yaml b/receiver/sqlserverreceiver/testdata/expectedProperties.yaml index 4dea2738ae1e..a53e2efb2518 100644 --- a/receiver/sqlserverreceiver/testdata/expectedProperties.yaml +++ b/receiver/sqlserverreceiver/testdata/expectedProperties.yaml @@ -6,7 +6,7 @@ resourceMetrics: stringValue: ad8fb2b53dce scopeMetrics: - metrics: - - description: The number of databases that are in a given state. + - description: The number of databases gauge: dataPoints: - asInt: "0" @@ -51,7 +51,7 @@ resourceMetrics: stringValue: suspect startTimeUnixNano: "1000000" timeUnixNano: "2000000" - name: sqlserver.properties.db.status + name: sqlserver.database.count unit: '{databases}' scope: name: otelcol/sqlserverreceiver