Skip to content

Commit

Permalink
fixed two metrics taking wrong fields added tests.
Browse files Browse the repository at this point in the history
* fixed connected_client_idle_since_timestamp and connected_client_shard_channel_watched_keys taking wrong fields.
* added bytes to obl and qbuf
* add test to all new metrics
  • Loading branch information
mindw committed Sep 10, 2024
1 parent 5bcb5cd commit 7ead98b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 18 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ test:
TEST_REDIS_URI="redis://localhost:16384" \
TEST_REDIS5_URI="redis://localhost:16383" \
TEST_REDIS6_URI="redis://localhost:16379" \
TEST_REDIS74_URI="redis://localhost:16385" \
TEST_VALKEY7_URI="redis://localhost:16384" \
TEST_REDIS_2_8_URI="redis://localhost:16381" \
TEST_KEYDB01_URI="redis://localhost:16401" \
Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:

valkey7:
Expand All @@ -20,6 +19,12 @@ services:
ports:
- "16379:6379"

redis74:
image: redis:7.4
command: "redis-server --protected-mode no --dbfilename dump74.rdb"
ports:
- "16385:6379"

pwd-redis5:
image: redis:5
command: "redis-server --requirepass redis-password --dbfilename dump5-pwd.rdb"
Expand Down
20 changes: 10 additions & 10 deletions exporter/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (e *Exporter) extractConnectedClientMetrics(ch chan<- prometheus.Metric, c
clientBaseLabels,
)
e.registerConstMetricGauge(
ch, "connected_client_idle_since_timestamp", float64(info.CreatedAt),
ch, "connected_client_idle_since_timestamp", float64(info.IdleSince),
clientBaseLabelsValues...,
)

Expand Down Expand Up @@ -313,19 +313,19 @@ func (e *Exporter) extractConnectedClientMetrics(ch chan<- prometheus.Metric, c
clientBaseLabels,
)
e.registerConstMetricGauge(
ch, "connected_client_shard_channel_watched_keys", float64(info.Ssub),
ch, "connected_client_shard_channel_watched_keys", float64(info.Watch),
clientBaseLabelsValues...,
)
}

e.metricDescriptions["connected_client_query_buffer_length"] = newMetricDescr(
e.metricDescriptions["connected_client_query_buffer_length_bytes"] = newMetricDescr(
e.options.Namespace,
"connected_client_query_buffer_length",
"A connected client's query buffer length (0 means no query pending)",
"connected_client_query_buffer_length_bytes",
"A connected client's query buffer length in bytes (0 means no query pending)",
clientBaseLabels,
)
e.registerConstMetricGauge(
ch, "connected_client_query_buffer_length", float64(info.Qbuf),
ch, "connected_client_query_buffer_length_bytes", float64(info.Qbuf),
clientBaseLabelsValues...,
)

Expand All @@ -340,14 +340,14 @@ func (e *Exporter) extractConnectedClientMetrics(ch chan<- prometheus.Metric, c
clientBaseLabelsValues...,
)

e.metricDescriptions["connected_client_output_buffer_length"] = newMetricDescr(
e.metricDescriptions["connected_client_output_buffer_length_bytes"] = newMetricDescr(
e.options.Namespace,
"connected_client_output_buffer_length",
"A connected client's output buffer length",
"connected_client_output_buffer_length_bytes",
"A connected client's output buffer length in bytes",
clientBaseLabels,
)
e.registerConstMetricGauge(
ch, "connected_client_output_buffer_length", float64(info.Obl),
ch, "connected_client_output_buffer_length_bytes", float64(info.Obl),
clientBaseLabelsValues...,
)

Expand Down
87 changes: 80 additions & 7 deletions exporter/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,51 @@ func TestExportClientList(t *testing.T) {
close(chM)
}()

found := false
tsts := []struct {
in string
found bool
}{
{
in: "connected_client_info",
}, {
in: "connected_clients_details",
}, {
in: "connected_client_output_buffer_memory_usage_bytes",
}, {
in: "connected_client_total_memory_consumed_bytes",
}, {
in: "connected_client_created_at_timestamp",
}, {
in: "connected_client_idle_since_timestamp",
}, {
in: "connected_client_channel_subscriptions_count",
}, {
in: "connected_client_pattern_matching_subscriptions_count",
}, {
in: "connected_client_query_buffer_length_bytes",
}, {
in: "connected_client_query_buffer_free_space_bytes",
}, {
in: "connected_client_output_buffer_length_bytes",
}, {
in: "connected_client_output_list_length",
},
}
for m := range chM {
if strings.Contains(m.Desc().String(), "connected_client_info") {
found = true
desc := m.Desc().String()
for i := range tsts {
if strings.Contains(desc, tsts[i].in) {
tsts[i].found = true
}
}
}

if isExportClientList && !found {
t.Errorf("connected_client_info was *not* found in isExportClientList metrics but expected")
} else if !isExportClientList && found {
t.Errorf("connected_client_info was *found* in isExportClientList metrics but *not* expected")
for _, tst := range tsts {
if isExportClientList && !tst.found {
t.Errorf("%s was *not* found in isExportClientList metrics but expected", tst.in)
} else if !isExportClientList && tst.found {
t.Errorf("%s was *found* in isExportClientList metrics but *not* expected", tst.in)
}
}
}
}
Expand Down Expand Up @@ -162,6 +196,45 @@ func TestExportClientListInclPort(t *testing.T) {
}
}

func TestExportClientListRedis7(t *testing.T) {
redisSevenAddr := os.Getenv("TEST_REDIS74_URI")
e := getTestExporterWithAddrAndOptions(redisSevenAddr, Options{
Namespace: "test", Registry: prometheus.NewRegistry(),
ExportClientList: true,
})

chM := make(chan prometheus.Metric)
go func() {
e.Collect(chM)
close(chM)
}()

tsts := []struct {
in string
found bool
}{
{
in: "connected_client_shard_channel_subscriptions_count",
}, {
in: "connected_client_shard_channel_watched_keys",
},
}
for m := range chM {
desc := m.Desc().String()
for i := range tsts {
if strings.Contains(desc, tsts[i].in) {
tsts[i].found = true
}
}
}

for _, tst := range tsts {
if !tst.found {
t.Errorf(`%s was *not* found in isExportClientList metrics but expected`, tst.in)
}
}
}

func TestExportClientListResp(t *testing.T) {
redisSevenAddr := os.Getenv("TEST_VALKEY7_URI")
e := getTestExporterWithAddrAndOptions(redisSevenAddr, Options{
Expand Down

0 comments on commit 7ead98b

Please sign in to comment.