diff --git a/receiver/mysqlreceiver/client.go b/receiver/mysqlreceiver/client.go index b0c3d6c7ba44..efacc9fd52a8 100644 --- a/receiver/mysqlreceiver/client.go +++ b/receiver/mysqlreceiver/client.go @@ -253,16 +253,7 @@ func (c *mySQLClient) getRowOperationStats() (RowOperationStats, error) { rows, err := c.client.Query(query) rowOpsStats := new(RowOperationStats) - /* - +----------------+-----------------+---------------+-----------+---------------+ - | statement_type | execution_count | rows_affected | rows_sent | rows_examined | - +----------------+-----------------+---------------+-----------+---------------+ - | SELECT | 4862 | 0 | 246533 | 43871844 | - | UPDATE | 2800 | 395 | 0 | 480395 | - | DELETE | 400 | 0 | 0 | 79800 | - | INSERT | 800 | 400 | 0 | 80200 | - +----------------+-----------------+---------------+-----------+---------------+ - */ + if err != nil { return *rowOpsStats, err } diff --git a/receiver/mysqlreceiver/metadata.yaml b/receiver/mysqlreceiver/metadata.yaml index 58b7e6ea4689..40faad297612 100644 --- a/receiver/mysqlreceiver/metadata.yaml +++ b/receiver/mysqlreceiver/metadata.yaml @@ -722,7 +722,7 @@ metrics: attributes: [dbname] mysql.statement_event.errors: - enabled: true + enabled: true description: the error count of the summarized events unit: 1 sum: diff --git a/receiver/mysqlreceiver/scraper.go b/receiver/mysqlreceiver/scraper.go index 35eda1db95a1..02c271395188 100644 --- a/receiver/mysqlreceiver/scraper.go +++ b/receiver/mysqlreceiver/scraper.go @@ -16,7 +16,6 @@ import ( "go.opentelemetry.io/collector/receiver/scrapererror" "go.uber.org/zap" - "github.com/k0kubun/pp" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver/internal/metadata" ) @@ -136,7 +135,6 @@ func (m *mySQLScraper) scrape(context.Context) (pmetric.Metrics, error) { func (m *mySQLScraper) scrapeRowOperationStats(now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) { rowOperationStats, err := m.sqlclient.getRowOperationStats() if err != nil { - pp.Print(err) m.logger.Error("Failed to fetch row operation stats from performance schema", zap.Error(err)) errs.AddPartial(4, err) return @@ -146,11 +144,6 @@ func (m *mySQLScraper) scrapeRowOperationStats(now pcommon.Timestamp, errs *scra rowsUpdated := strconv.FormatInt(rowOperationStats.rowsUpdated, 10) rowsRead := strconv.FormatInt(rowOperationStats.rowsInserted, 10) - pp.Println(rowsDeleted) - pp.Println(rowsInserted) - pp.Println(rowsUpdated) - pp.Println(rowsRead) - m.mb.RecordMysqlPerformanceRowsDeletedDataPoint(now, rowsDeleted) m.mb.RecordMysqlPerformanceRowsInsertedDataPoint(now, rowsInserted) m.mb.RecordMysqlPerformanceRowsUpdatedDataPoint(now, rowsUpdated) diff --git a/receiver/mysqlreceiver/scraper_test.go b/receiver/mysqlreceiver/scraper_test.go index 74e54e9ff850..edd42d05c779 100644 --- a/receiver/mysqlreceiver/scraper_test.go +++ b/receiver/mysqlreceiver/scraper_test.go @@ -72,6 +72,7 @@ func TestScrape(t *testing.T) { innodbStatusStatsFile: "innodb_status_stats", totalRowsFile: "total_rows_stats", totalErrorsFile: "total_error_stats", + rowOperationsStatsFile: "row_operations_status", } scraper.renameCommands = true @@ -119,6 +120,7 @@ func TestScrape(t *testing.T) { innodbStatusStatsFile: "innodb_status_stats_empty", totalRowsFile: "total_rows_empty", totalErrorsFile: "total_errors_empty", + rowOperationsStatsFile: "row_operations_status_empty", } actualMetrics, scrapeErr := scraper.scrape(context.Background()) @@ -127,9 +129,15 @@ func TestScrape(t *testing.T) { expectedFile := filepath.Join("testdata", "scraper", "expected_partial.yaml") expectedMetrics, err := golden.ReadMetrics(expectedFile) require.NoError(t, err) - assert.NoError(t, pmetrictest.CompareMetrics(actualMetrics, expectedMetrics, - pmetrictest.IgnoreMetricDataPointsOrder(), pmetrictest.IgnoreStartTimestamp(), - pmetrictest.IgnoreTimestamp())) + assert.NoError(t, pmetrictest.CompareMetrics( + actualMetrics, + expectedMetrics, + pmetrictest.IgnoreMetricsOrder(), + pmetrictest.IgnoreMetricDataPointsOrder(), + pmetrictest.IgnoreStartTimestamp(), + pmetrictest.IgnoreTimestamp(), + ), + ) var partialError scrapererror.PartialScrapeError require.True(t, errors.As(scrapeErr, &partialError), "returned error was not PartialScrapeError") @@ -154,6 +162,7 @@ type mockClient struct { innodbStatusStatsFile string totalRowsFile string totalErrorsFile string + rowOperationsStatsFile string } func readFile(fname string) (map[string]string, error) { @@ -188,6 +197,45 @@ func (c *mockClient) getInnodbStats() (map[string]string, error) { return readFile(c.innodbStatsFile) } +func (c *mockClient) getRowOperationStats() (RowOperationStats, error) { + rowOpsStats := new(RowOperationStats) + file, err := os.Open(filepath.Join("testdata", "scraper", c.rowOperationsStatsFile+".txt")) + + if err != nil { + return *rowOpsStats, err + } + + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + + text := strings.Fields(scanner.Text()) + rowsInserted, err := strconv.Atoi(text[0]) + if err != nil { + return *rowOpsStats, err + } + rowsUpdated, err := strconv.Atoi(text[1]) + if err != nil { + return *rowOpsStats, err + } + rowsRead, err := strconv.Atoi(text[2]) + if err != nil { + return *rowOpsStats, err + } + rowsDeleted, err := strconv.Atoi(text[3]) + if err != nil { + return *rowOpsStats, err + } + + rowOpsStats.rowsDeleted = int64(rowsDeleted) + rowOpsStats.rowsInserted = int64(rowsInserted) + rowOpsStats.rowsRead = int64(rowsRead) + rowOpsStats.rowsUpdated = int64(rowsUpdated) + } + return *rowOpsStats, nil +} + func (c *mockClient) getInnodbStatusStats() (map[string]int64, error, int) { ret := make(map[string]int64) var totalErrs int diff --git a/receiver/mysqlreceiver/testdata/scraper/expected.yaml b/receiver/mysqlreceiver/testdata/scraper/expected.yaml index 2512d944dc56..85092cfb733e 100644 --- a/receiver/mysqlreceiver/testdata/scraper/expected.yaml +++ b/receiver/mysqlreceiver/testdata/scraper/expected.yaml @@ -49,6 +49,46 @@ resourceMetrics: timeUnixNano: "2000000" isMonotonic: true unit: "1" + - description: The number of rows inserted in the database as per the performance schema. + name: mysql.performance.rows_inserted + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "100" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: '{row}' + - description: The number of rows read in the database as per the performance schema. + name: mysql.performance.rows_read + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "100" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: '{row}' + - description: The number of rows updated in the database as per the performance schema. + name: mysql.performance.rows_updated + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "100" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: '{row}' + - description: The number of rows deleted in the database as per the performance schema. + name: mysql.performance.rows_deleted + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "100" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: '{row}' - description: Rate at which rows are being deleted in InnoDB. name: mysql.innodb.rows_deleted sum: diff --git a/receiver/mysqlreceiver/testdata/scraper/expected_partial.yaml b/receiver/mysqlreceiver/testdata/scraper/expected_partial.yaml index 475b64064057..36c998853df7 100644 --- a/receiver/mysqlreceiver/testdata/scraper/expected_partial.yaml +++ b/receiver/mysqlreceiver/testdata/scraper/expected_partial.yaml @@ -22,6 +22,46 @@ resourceMetrics: startTimeUnixNano: "1000000" timeUnixNano: "2000000" unit: "1" + - description: The number of rows inserted in the database as per the performance schema. + name: mysql.performance.rows_inserted + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: '{row}' + - description: The number of rows read in the database as per the performance schema. + name: mysql.performance.rows_read + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: '{row}' + - description: The number of rows updated in the database as per the performance schema. + name: mysql.performance.rows_updated + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: '{row}' + - description: The number of rows deleted in the database as per the performance schema. + name: mysql.performance.rows_deleted + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "0" + startTimeUnixNano: "1000000" + timeUnixNano: "2000000" + isMonotonic: true + unit: '{row}' scope: name: otelcol/mysqlreceiver version: latest diff --git a/receiver/mysqlreceiver/testdata/scraper/row_operations_status.txt b/receiver/mysqlreceiver/testdata/scraper/row_operations_status.txt new file mode 100644 index 000000000000..a1bca508d89a --- /dev/null +++ b/receiver/mysqlreceiver/testdata/scraper/row_operations_status.txt @@ -0,0 +1 @@ +100 100 100 100 \ No newline at end of file diff --git a/receiver/mysqlreceiver/testdata/scraper/row_operations_status_empty.txt b/receiver/mysqlreceiver/testdata/scraper/row_operations_status_empty.txt new file mode 100644 index 000000000000..e69de29bb2d1