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

feat(prometheus): extra labels from nginx var for http request metrics #7549

Merged
merged 10 commits into from
Aug 1, 2022

Conversation

kingluo
Copy link
Contributor

@kingluo kingluo commented Jul 27, 2022

close #4273

Description

Add extra labels from nginx variables for http request metrics.

Fixes #4273

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@@ -522,6 +522,14 @@ plugin_attr:
export_addr:
ip: 127.0.0.1
port: 9091
# ngx_var_labels:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't need to highlight the var. Instead, we can just use the name custom_labels.

@@ -522,6 +522,14 @@ plugin_attr:
export_addr:
ip: 127.0.0.1
port: 9091
# custom_labels:
Copy link
Member

Choose a reason for hiding this comment

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

Would be better to use:

metrics:
    xxx:
       extra_labels:
           label_name_xxx: $label_var
     yyy:

So we can add more options to a metric in the future. And we don't need to require the label name should be the variable name.

Copy link
Member

Choose a reason for hiding this comment

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

And please add a comment to show that the commented configurations are the example but not the default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The labels of extra_labels should be a list, because fields of dictionary in lua table are out of order, which would cause the metric full name may change each time it reloads the conf.

Copy link
Member

Choose a reason for hiding this comment

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

We can provide order on the implementation side, for example sorting them before using them.

for _, name in ipairs(labels) do
local val = ctx.var[name]
if val == nil then
val = "nil"
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest using "", which is language-independent.

end
}
}
--- error_code: 200
Copy link
Member

Choose a reason for hiding this comment

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

Actually we don't need to specify --- error_code: 200 as it is checked by default

custom_labels:
http_status:
- dummy
bandwidth:
Copy link
Member

Choose a reason for hiding this comment

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

We don't need the bandwidth?

tzssangglass
tzssangglass previously approved these changes Jul 29, 2022
- upstream_status: $upstream_status
--- request
GET /hello
--- error_code: 200
Copy link
Member

Choose a reason for hiding this comment

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

Actually we don't need to specify --- error_code: 200 as it is checked by default




=== TEST 6: fetch the prometheus metric data, with nil label
Copy link
Member

Choose a reason for hiding this comment

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

It is no longer a nil label?

@@ -53,6 +53,29 @@ plugin_attr:
export_uri: /apisix/metrics
```

### Specifying `metrics`

For http request related metrics, you could specify extra labels, which match the nginx variables.
Copy link
Member

Choose a reason for hiding this comment

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

Let's use APISIX variable like elsewhere in the doc.

@spacewander spacewander merged commit 3d9e2fd into apache:master Aug 1, 2022
Liu-Junlin pushed a commit to Liu-Junlin/apisix that referenced this pull request Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

discuss: enrich the Available metrics of plugin prometheus
5 participants