Skip to content

Commit

Permalink
fix(prometheus): improve logging when having the inconsistent labels …
Browse files Browse the repository at this point in the history
…count (#13020)

Currently, the Prometheus plugin will log the following error if we have encountered an inconsistent label count while debugging:

```
[error]... inconsistent labels count, expected 6, got 5
```

It's hard to identify which metric is going wrong, and it will be helpful if we can bring the metric name as well:

```
[error]... metric 'bandwidth_bytes' has the inconsistent labels count, expected 6, got 5
```

Co-authored-by: Qi <44437200+ADD-SP@users.noreply.github.com>
  • Loading branch information
git-hulk and ADD-SP authored Jun 4, 2024
1 parent 3066f50 commit f46a957
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message: |
**Prometheus**: Improved error logging when having inconsistent labels count.
type: bugfix
scope: Plugin
4 changes: 2 additions & 2 deletions kong/plugins/prometheus/prometheus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ local function lookup_or_create(self, label_values)
local cnt = label_values and #label_values or 0
-- specially, if first element is nil, # will treat it as "non-empty"
if cnt ~= self.label_count or (self.label_count > 0 and label_values[1] == nil) then
return nil, string.format("inconsistent labels count, expected %d, got %d",
self.label_count, cnt)
return nil, string.format("metric '%s' has inconsistent labels count, expected %d, got %d",
self.name, self.label_count, cnt)
end
local t = self.lookup
if label_values then
Expand Down

1 comment on commit f46a957

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Bazel Build

Docker image available kong/kong:f46a9572b359a0d02fed1defe997d400436ba822
Artifacts available https://github.com/Kong/kong/actions/runs/9360855437

Please sign in to comment.