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(plugins)(datadog): add a datadog tag for the route name to each metric #13494

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tysoekong
Copy link
Contributor

@tysoekong tysoekong commented Aug 12, 2024

Summary

This adds a "route name" tag to each of the Datadog metric outputs, just as it does with service, consumer, status code, and more.

One of our favourite users has been asking for this for ages, so we wanted to help by contribute this back instead of creating them a custom OSS build.

Checklist

@tysoekong tysoekong force-pushed the feat/datadog-plugin-route-tag branch 2 times, most recently from 6a5aca7 to 1bfc807 Compare August 13, 2024 08:49
Copy link
Member

@samugi samugi left a comment

Choose a reason for hiding this comment

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

both new tests appear to be failing atm

local result = {
(conf.service_name_tag or "name") .. ":" .. service_name,
(conf.status_tag or "status") .. ":" .. status
(conf.status_tag or "status") .. ":" .. status,
route_name and route_name ~= "" and ((conf.route_name_tag or "route") .. ":" .. route_name) or nil
Copy link
Member

Choose a reason for hiding this comment

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

is it desidable that route_name is nil when not available or should it have some default? I'm thinking of what would happen if/when we add another value to this result array, then having a nil element in the middle of the array could affect iterations, although it seems we're passing this to generate a statsd_message, not sure how it would be handled there.

I'd like it better if we could keep this consistent with the other metrics and just do: (conf.route_name_tag or "route") .. ":" .. route_name here while passing some default value to this function to ensure route_name is not nil, wdyt?

Copy link
Contributor Author

@tysoekong tysoekong Aug 13, 2024

Choose a reason for hiding this comment

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

Not sure what we can set for default, it might be confusing. But yeah you're right if null/missing, it might bust our user's graphs, for example.

Maybe the route ID instead?

Copy link
Member

@samugi samugi Aug 13, 2024

Choose a reason for hiding this comment

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

yeah that would somehow be similar to what we do with the service name (falls back to host), I think it's a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samugi Okay the logic is now:

  • route must actually be present - nil check
  • if route.name is there: gsub the dots away for _
  • if route.name is not there, use route.id
  • otherwise route is nil for some reason, fall back to empty string

That should do it?

kong/plugins/datadog/handler.lua Outdated Show resolved Hide resolved
@team-eng-enablement team-eng-enablement added author/community PRs from the open-source community (not Kong Inc) and removed author/community PRs from the open-source community (not Kong Inc) labels Aug 13, 2024
@GGabriele
Copy link
Contributor

@tysoekong @samugi is this going to be included in 3.8?

@samugi
Copy link
Member

samugi commented Aug 29, 2024

@tysoekong @samugi is this going to be included in 3.8?

it shouldn't be @GGabriele , the feature freeze ship has sailed, so I think it's correct that the milestone is empty on this one

@team-gateway-bot team-gateway-bot added the author/community PRs from the open-source community (not Kong Inc) label Sep 17, 2024
Copy link
Member

@samugi samugi left a comment

Choose a reason for hiding this comment

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

left a couple comments. Also looks like relevant tests are failing

consumer_id, metric_config.tags, conf)
consumer_id, metric_config.tags,
conf,
message.route and (message.route.name and gsub(message.route.name ~= null and
Copy link
Member

Choose a reason for hiding this comment

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

is this passing false to gsub when message.route.name is null?
When it gets this complex I'd rather be verbose and write down the logic above, assigning the final value to some local variable, and then just pass it to compose_tags, wdyt?

local result = {
(conf.service_name_tag or "name") .. ":" .. service_name,
(conf.status_tag or "status") .. ":" .. status
(conf.status_tag or "status") .. ":" .. status,
route_name and route_name ~= "" and ((conf.route_name_tag or "route") .. ":" .. route_name)
Copy link
Member

Choose a reason for hiding this comment

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

I think the checks route_name and route_name ~= "" can be omitted right? We know it'll either have a value or be "", and in case it's "" we probably want to just use it like that, or else this evaluation will return false, am I right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author/community PRs from the open-source community (not Kong Inc) cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee plugins/datadog schema-change-noteworthy size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants