diff --git a/receiver/mysqlreceiver/documentation.md b/receiver/mysqlreceiver/documentation.md index 0a6a646c22c8..be394f7f31ba 100644 --- a/receiver/mysqlreceiver/documentation.md +++ b/receiver/mysqlreceiver/documentation.md @@ -84,6 +84,20 @@ The number of bytes in the InnoDB buffer pool. | ---- | ----------- | ------ | | status | The status of buffer pool data. | Str: ``dirty``, ``clean`` | +### mysql.commands + +The number of times each type of command has been executed. + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| 1 | Sum | Int | Cumulative | true | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| command | The command types. | Str: ``delete``, ``insert``, ``select``, ``update`` | + ### mysql.double_writes The number of writes to the InnoDB doublewrite buffer. @@ -246,6 +260,22 @@ The number of times each type of prepared statement command has been issued. | ---- | ----------- | ------ | | command | The prepare statement command types. | Str: ``execute``, ``close``, ``fetch``, ``prepare``, ``reset``, ``send_long_data`` | +### mysql.query.count + +The number of statements executed by the server. + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| 1 | Sum | Int | Cumulative | true | + +### mysql.query.slow.count + +The number of slow queries. + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| 1 | Sum | Int | Cumulative | true | + ### mysql.row_locks The number of InnoDB row locks. @@ -321,6 +351,22 @@ The total count of executed queries per normalized query and schema. | digest | Digest. | Any Str | | digest_text | Text before digestion. | Any Str | +### mysql.statement_event.errors + +the error count of the summarized events + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| 1 | Sum | Int | Cumulative | true | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| schema | The schema of the object. | Any Str | +| digest | Digest. | Any Str | +| digest_text | Text before digestion. | Any Str | + ### mysql.statement_event.wait.time The total wait time of the summarized timed events. @@ -429,20 +475,6 @@ The number of transmitted bytes between server and clients. | ---- | ----------- | ------ | | kind | The name of the transmission direction. | Str: ``received``, ``sent`` | -### mysql.commands - -The number of times each type of command has been executed. - -| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | -| ---- | ----------- | ---------- | ----------------------- | --------- | -| 1 | Sum | Int | Cumulative | true | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| command | The command types. | Str: ``delete``, ``insert``, ``select``, ``update`` | - ### mysql.connection.count The number of connection attempts (successful or not) to the MySQL server. @@ -503,22 +535,6 @@ The number of statements executed by the server. This includes only statements s | ---- | ----------- | ---------- | ----------------------- | --------- | | 1 | Sum | Int | Cumulative | true | -### mysql.query.count - -The number of statements executed by the server. - -| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | -| ---- | ----------- | ---------- | ----------------------- | --------- | -| 1 | Sum | Int | Cumulative | true | - -### mysql.query.slow.count - -The number of slow queries. - -| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | -| ---- | ----------- | ---------- | ----------------------- | --------- | -| 1 | Sum | Int | Cumulative | true | - ### mysql.replica.sql_delay The number of seconds that the replica must lag the source. diff --git a/receiver/mysqlreceiver/internal/metadata/generated_config.go b/receiver/mysqlreceiver/internal/metadata/generated_config.go index d557102c2de6..7dda3f97a7eb 100644 --- a/receiver/mysqlreceiver/internal/metadata/generated_config.go +++ b/receiver/mysqlreceiver/internal/metadata/generated_config.go @@ -58,6 +58,7 @@ type MetricsConfig struct { MysqlSorts MetricConfig `mapstructure:"mysql.sorts"` MysqlStatementEventCount MetricConfig `mapstructure:"mysql.statement_event.count"` MysqlStatementEventCountStars MetricConfig `mapstructure:"mysql.statement_event.count_stars"` + MysqlStatementEventErrors MetricConfig `mapstructure:"mysql.statement_event.errors"` MysqlStatementEventWaitTime MetricConfig `mapstructure:"mysql.statement_event.wait.time"` MysqlTableIoWaitCount MetricConfig `mapstructure:"mysql.table.io.wait.count"` MysqlTableIoWaitTime MetricConfig `mapstructure:"mysql.table.io.wait.time"` @@ -95,7 +96,7 @@ func DefaultMetricsConfig() MetricsConfig { Enabled: false, }, MysqlCommands: MetricConfig{ - Enabled: false, + Enabled: true, }, MysqlConnectionCount: MetricConfig{ Enabled: false, @@ -146,10 +147,10 @@ func DefaultMetricsConfig() MetricsConfig { Enabled: false, }, MysqlQueryCount: MetricConfig{ - Enabled: false, + Enabled: true, }, MysqlQuerySlowCount: MetricConfig{ - Enabled: false, + Enabled: true, }, MysqlReplicaSQLDelay: MetricConfig{ Enabled: false, @@ -172,6 +173,9 @@ func DefaultMetricsConfig() MetricsConfig { MysqlStatementEventCountStars: MetricConfig{ Enabled: true, }, + MysqlStatementEventErrors: MetricConfig{ + Enabled: true, + }, MysqlStatementEventWaitTime: MetricConfig{ Enabled: true, }, diff --git a/receiver/mysqlreceiver/internal/metadata/generated_config_test.go b/receiver/mysqlreceiver/internal/metadata/generated_config_test.go index 6a06266c2fdb..d9ff0b1da5d0 100644 --- a/receiver/mysqlreceiver/internal/metadata/generated_config_test.go +++ b/receiver/mysqlreceiver/internal/metadata/generated_config_test.go @@ -59,6 +59,7 @@ func TestMetricsBuilderConfig(t *testing.T) { MysqlSorts: MetricConfig{Enabled: true}, MysqlStatementEventCount: MetricConfig{Enabled: true}, MysqlStatementEventCountStars: MetricConfig{Enabled: true}, + MysqlStatementEventErrors: MetricConfig{Enabled: true}, MysqlStatementEventWaitTime: MetricConfig{Enabled: true}, MysqlTableIoWaitCount: MetricConfig{Enabled: true}, MysqlTableIoWaitTime: MetricConfig{Enabled: true}, @@ -113,6 +114,7 @@ func TestMetricsBuilderConfig(t *testing.T) { MysqlSorts: MetricConfig{Enabled: false}, MysqlStatementEventCount: MetricConfig{Enabled: false}, MysqlStatementEventCountStars: MetricConfig{Enabled: false}, + MysqlStatementEventErrors: MetricConfig{Enabled: false}, MysqlStatementEventWaitTime: MetricConfig{Enabled: false}, MysqlTableIoWaitCount: MetricConfig{Enabled: false}, MysqlTableIoWaitTime: MetricConfig{Enabled: false}, diff --git a/receiver/mysqlreceiver/internal/metadata/generated_metrics.go b/receiver/mysqlreceiver/internal/metadata/generated_metrics.go index 7fc52fb3590b..4168a2141c2f 100644 --- a/receiver/mysqlreceiver/internal/metadata/generated_metrics.go +++ b/receiver/mysqlreceiver/internal/metadata/generated_metrics.go @@ -2727,6 +2727,61 @@ func newMetricMysqlStatementEventCountStars(cfg MetricConfig) metricMysqlStateme return m } +type metricMysqlStatementEventErrors 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 mysql.statement_event.errors metric with initial data. +func (m *metricMysqlStatementEventErrors) init() { + m.data.SetName("mysql.statement_event.errors") + m.data.SetDescription("the error count of the summarized events") + m.data.SetUnit("1") + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricMysqlStatementEventErrors) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, schemaAttributeValue string, digestAttributeValue string, digestTextAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("schema", schemaAttributeValue) + dp.Attributes().PutStr("digest", digestAttributeValue) + dp.Attributes().PutStr("digest_text", digestTextAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricMysqlStatementEventErrors) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricMysqlStatementEventErrors) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricMysqlStatementEventErrors(cfg MetricConfig) metricMysqlStatementEventErrors { + m := metricMysqlStatementEventErrors{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricMysqlStatementEventWaitTime struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -3363,6 +3418,7 @@ type MetricsBuilder struct { metricMysqlSorts metricMysqlSorts metricMysqlStatementEventCount metricMysqlStatementEventCount metricMysqlStatementEventCountStars metricMysqlStatementEventCountStars + metricMysqlStatementEventErrors metricMysqlStatementEventErrors metricMysqlStatementEventWaitTime metricMysqlStatementEventWaitTime metricMysqlTableIoWaitCount metricMysqlTableIoWaitCount metricMysqlTableIoWaitTime metricMysqlTableIoWaitTime @@ -3425,6 +3481,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting metricMysqlSorts: newMetricMysqlSorts(mbc.Metrics.MysqlSorts), metricMysqlStatementEventCount: newMetricMysqlStatementEventCount(mbc.Metrics.MysqlStatementEventCount), metricMysqlStatementEventCountStars: newMetricMysqlStatementEventCountStars(mbc.Metrics.MysqlStatementEventCountStars), + metricMysqlStatementEventErrors: newMetricMysqlStatementEventErrors(mbc.Metrics.MysqlStatementEventErrors), metricMysqlStatementEventWaitTime: newMetricMysqlStatementEventWaitTime(mbc.Metrics.MysqlStatementEventWaitTime), metricMysqlTableIoWaitCount: newMetricMysqlTableIoWaitCount(mbc.Metrics.MysqlTableIoWaitCount), metricMysqlTableIoWaitTime: newMetricMysqlTableIoWaitTime(mbc.Metrics.MysqlTableIoWaitTime), @@ -3530,6 +3587,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricMysqlSorts.emit(ils.Metrics()) mb.metricMysqlStatementEventCount.emit(ils.Metrics()) mb.metricMysqlStatementEventCountStars.emit(ils.Metrics()) + mb.metricMysqlStatementEventErrors.emit(ils.Metrics()) mb.metricMysqlStatementEventWaitTime.emit(ils.Metrics()) mb.metricMysqlTableIoWaitCount.emit(ils.Metrics()) mb.metricMysqlTableIoWaitTime.emit(ils.Metrics()) @@ -3851,6 +3909,11 @@ func (mb *MetricsBuilder) RecordMysqlStatementEventCountStarsDataPoint(ts pcommo mb.metricMysqlStatementEventCountStars.recordDataPoint(mb.startTime, ts, val, schemaAttributeValue, digestAttributeValue, digestTextAttributeValue) } +// RecordMysqlStatementEventErrorsDataPoint adds a data point to mysql.statement_event.errors metric. +func (mb *MetricsBuilder) RecordMysqlStatementEventErrorsDataPoint(ts pcommon.Timestamp, val int64, schemaAttributeValue string, digestAttributeValue string, digestTextAttributeValue string) { + mb.metricMysqlStatementEventErrors.recordDataPoint(mb.startTime, ts, val, schemaAttributeValue, digestAttributeValue, digestTextAttributeValue) +} + // RecordMysqlStatementEventWaitTimeDataPoint adds a data point to mysql.statement_event.wait.time metric. func (mb *MetricsBuilder) RecordMysqlStatementEventWaitTimeDataPoint(ts pcommon.Timestamp, val int64, schemaAttributeValue string, digestAttributeValue string, digestTextAttributeValue string) { mb.metricMysqlStatementEventWaitTime.recordDataPoint(mb.startTime, ts, val, schemaAttributeValue, digestAttributeValue, digestTextAttributeValue) diff --git a/receiver/mysqlreceiver/internal/metadata/generated_metrics_test.go b/receiver/mysqlreceiver/internal/metadata/generated_metrics_test.go index bd66f6a3c8af..9b4678be91cc 100644 --- a/receiver/mysqlreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/mysqlreceiver/internal/metadata/generated_metrics_test.go @@ -81,6 +81,7 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordMysqlClientNetworkIoDataPoint(ts, "1", AttributeDirectionReceived) + defaultMetricsCount++ allMetricsCount++ mb.RecordMysqlCommandsDataPoint(ts, "1", AttributeCommandDelete) @@ -143,9 +144,11 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordMysqlQueryClientCountDataPoint(ts, "1") + defaultMetricsCount++ allMetricsCount++ mb.RecordMysqlQueryCountDataPoint(ts, "1") + defaultMetricsCount++ allMetricsCount++ mb.RecordMysqlQuerySlowCountDataPoint(ts, "1") @@ -175,6 +178,10 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordMysqlStatementEventCountStarsDataPoint(ts, 1, "schema-val", "digest-val", "digest_text-val") + defaultMetricsCount++ + allMetricsCount++ + mb.RecordMysqlStatementEventErrorsDataPoint(ts, 1, "schema-val", "digest-val", "digest_text-val") + defaultMetricsCount++ allMetricsCount++ mb.RecordMysqlStatementEventWaitTimeDataPoint(ts, 1, "schema-val", "digest-val", "digest_text-val") @@ -808,6 +815,29 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("digest_text") assert.True(t, ok) assert.EqualValues(t, "digest_text-val", attrVal.Str()) + case "mysql.statement_event.errors": + assert.False(t, validatedMetrics["mysql.statement_event.errors"], "Found a duplicate in the metrics slice: mysql.statement_event.errors") + validatedMetrics["mysql.statement_event.errors"] = true + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) + assert.Equal(t, "the error count of the summarized events", ms.At(i).Description()) + assert.Equal(t, "1", ms.At(i).Unit()) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().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("schema") + assert.True(t, ok) + assert.EqualValues(t, "schema-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("digest") + assert.True(t, ok) + assert.EqualValues(t, "digest-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("digest_text") + assert.True(t, ok) + assert.EqualValues(t, "digest_text-val", attrVal.Str()) case "mysql.statement_event.wait.time": assert.False(t, validatedMetrics["mysql.statement_event.wait.time"], "Found a duplicate in the metrics slice: mysql.statement_event.wait.time") validatedMetrics["mysql.statement_event.wait.time"] = true diff --git a/receiver/mysqlreceiver/internal/metadata/testdata/config.yaml b/receiver/mysqlreceiver/internal/metadata/testdata/config.yaml index b1da5665356a..a1b83c7371f1 100644 --- a/receiver/mysqlreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/mysqlreceiver/internal/metadata/testdata/config.yaml @@ -67,6 +67,8 @@ all_set: enabled: true mysql.statement_event.count_stars: enabled: true + mysql.statement_event.errors: + enabled: true mysql.statement_event.wait.time: enabled: true mysql.table.io.wait.count: @@ -160,6 +162,8 @@ none_set: enabled: false mysql.statement_event.count_stars: enabled: false + mysql.statement_event.errors: + enabled: false mysql.statement_event.wait.time: enabled: false mysql.table.io.wait.count: diff --git a/receiver/mysqlreceiver/metadata.yaml b/receiver/mysqlreceiver/metadata.yaml index 5257819fd01e..bca1ec64618a 100644 --- a/receiver/mysqlreceiver/metadata.yaml +++ b/receiver/mysqlreceiver/metadata.yaml @@ -235,7 +235,7 @@ metrics: aggregation_temporality: cumulative attributes: [prepared_statements_command] mysql.commands: - enabled: false + enabled: true description: The number of times each type of command has been executed. unit: 1 sum: @@ -571,7 +571,7 @@ metrics: monotonic: true aggregation_temporality: cumulative mysql.query.count: - enabled: false + enabled: true description: The number of statements executed by the server. unit: 1 sum: @@ -580,7 +580,7 @@ metrics: monotonic: true aggregation_temporality: cumulative mysql.query.slow.count: - enabled: false + enabled: true description: The number of slow queries. unit: 1 sum: @@ -588,3 +588,13 @@ metrics: input_type: string monotonic: true aggregation_temporality: cumulative + + mysql.statement_event.errors: + enabled: true + description: the error count of the summarized events + unit: 1 + sum: + value_type: int + monotonic: true + aggregation_temporality: cumulative + attributes: [schema, digest, digest_text] \ No newline at end of file diff --git a/receiver/mysqlreceiver/scraper.go b/receiver/mysqlreceiver/scraper.go index 8773bf06da40..cd60a598ed4d 100644 --- a/receiver/mysqlreceiver/scraper.go +++ b/receiver/mysqlreceiver/scraper.go @@ -475,7 +475,7 @@ func (m *mySQLScraper) scrapeIndexIoWaitsStats(now pcommon.Timestamp, errs *scra func (m *mySQLScraper) scrapeStatementEventsStats(now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) { statementEventsStats, err := m.sqlclient.getStatementEventsStats() if err != nil { - m.logger.Error("Failed to fetch index io_waits stats", zap.Error(err)) + m.logger.Error("Failed to fetch statement stats", zap.Error(err)) errs.AddPartial(8, err) return } @@ -494,6 +494,7 @@ func (m *mySQLScraper) scrapeStatementEventsStats(now pcommon.Timestamp, errs *s m.mb.RecordMysqlStatementEventCountDataPoint(now, s.countWarnings, s.schema, s.digest, s.digestText, metadata.AttributeEventStateWarnings) m.mb.RecordMysqlStatementEventCountStarsDataPoint(now, s.countStar, s.schema, s.digest, s.digestText) + m.mb.RecordMysqlStatementEventErrorsDataPoint(now, s.countErrors, s.schema, s.digest, s.digestText) m.mb.RecordMysqlStatementEventWaitTimeDataPoint(now, s.sumTimerWait/picosecondsInNanoseconds, s.schema, s.digest, s.digestText) } }