Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/redis] Command latency metrics. #26569

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/redisreceiver_cmd_latency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: redisreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added `redis.cmd.latency` metric.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [6942]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
15 changes: 15 additions & 0 deletions receiver/redisreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ Total number of calls for a command
| ---- | ----------- | ------ |
| cmd | Redis command name | Any Str |

### redis.cmd.latency

Command execution latency

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| us | Gauge | Double |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| cmd | Redis command name | Any Str |
| percentile | Percentile | Str: ``p50``, ``p99``, ``p99.9`` |

### redis.cmd.usec

Total time for all executions of this command
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions receiver/redisreceiver/internal/metadata/generated_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ all_set:
enabled: true
redis.cmd.calls:
enabled: true
redis.cmd.latency:
enabled: true
redis.cmd.usec:
enabled: true
redis.commands:
Expand Down Expand Up @@ -82,6 +84,8 @@ none_set:
enabled: false
redis.cmd.calls:
enabled: false
redis.cmd.latency:
enabled: false
redis.cmd.usec:
enabled: false
redis.commands:
Expand Down
40 changes: 40 additions & 0 deletions receiver/redisreceiver/latencystats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package redisreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver"

import (
"fmt"
"strconv"
"strings"
)

// Holds percentile latencies, e.g. "p99" -> 1.5.
type latencies map[string]float64

// parseLatencyStats parses the values part of one entry in Redis latencystats section,
// e.g. "p50=181.247,p99=309.247,p99.9=1023.999".
func parseLatencyStats(str string) (latencies, error) {
res := make(latencies)

pairs := strings.Split(strings.TrimSpace(str), ",")

for _, pairStr := range pairs {
pair := strings.Split(pairStr, "=")
if len(pair) != 2 {
return nil, fmt.Errorf("unexpected latency percentiles pair '%s'", pairStr)
}

key := pair[0]
valueStr := pair[1]

value, err := strconv.ParseFloat(valueStr, 64)
if err != nil {
return nil, err
}

res[key] = value
}

return res, nil
}
34 changes: 34 additions & 0 deletions receiver/redisreceiver/latencystats_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package redisreceiver

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestParseLatencyStats(t *testing.T) {
ls, err := parseLatencyStats("p50=181.247,p55=182.271,p99=309.247,p99.9=1023.999")
require.Nil(t, err)
require.Equal(t, ls["p50"], 181.247)
require.Equal(t, ls["p55"], 182.271)
require.Equal(t, ls["p99"], 309.247)
require.Equal(t, ls["p99.9"], 1023.999)
}

func TestParseMalformedLatencyStats(t *testing.T) {
tests := []struct{ name, stats string }{
{"missing value", "p50=42.0,p90=50.0,p99.9="},
{"missing equals", "p50=42.0,p90=50.0,p99.9"},
{"extra comma", "p50=42.0,,p90=50.0"},
{"wrong value type", "p50=asdf"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := parseLatencyStats(test.stats)
require.NotNil(t, err)
})
}
}
15 changes: 15 additions & 0 deletions receiver/redisreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ attributes:
cmd:
description: Redis command name
type: string
percentile:
description: Percentile
type: string
enum:
- p50
- p99
- p99.9

metrics:
redis.maxmemory:
Expand Down Expand Up @@ -84,6 +91,14 @@ metrics:
aggregation_temporality: cumulative
attributes: [cmd]

redis.cmd.latency:
enabled: false
description: Command execution latency
unit: us
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this during the review. The OTel spec recommends sticking to basic units, e.g. seconds instead of milliseconds if possible https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/metrics.md#instrument-units. E.g. HTTP latency metrics is in seconds as well https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md#metric-httpserverrequestduration

I think we should convert the values to seconds in a follow-up PR

gauge:
value_type: double
attributes: [cmd, percentile]

redis.uptime:
enabled: true
description: Number of seconds since Redis server start
Expand Down
Loading