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

Fix dataSource dimension decoration in SQLExecutionReporter Metrics #17744

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ashwintumma23
Copy link
Contributor

Fixes #17743.

Description

  • For the sqlQuery/* metrics, [ and ] are added when the data source names are being converted from a List to a String.
  • This decorated dataSource value gets emitted by the emitters in decorated format as shown in the screenshots on the linked issue.

Fixed the bug ...

  • In this PR, we are explicitly removing the heading [ and trailing ] characters from the dataSource name in the SQLExecutionReporter itself, so that the decorated values are not carried to the emitters.
    • Side Note: Prometheus Emitter replaces all non-alphanumeric characters with _; so dataSource names in Prometheus will not contain the heading _ and trailing _ automatically!
  • We are also adding a test case to cover this scenario, wherein the expected value of dataSource should be foo. Before making the code change, I ran the unit test on the current codebase, and I can clearly see the actual value was [foo]. Attaching reference screenshot here:
    image
  • With the code changes in this PR, the dataSource value is correctly passed as foo

Release note

  • dataSource names for sqlQuery metrics will not include heading [ and trailing ] or any other character decorations; making them consistent across other Druid metrics.

Key changed/added classes in this PR
  • SqlExecutionReporter
  • SqlResourceTest

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

.stream()
.map(action -> action.getResource().getName())
.collect(Collectors.toList())
.toString();
Copy link
Member

Choose a reason for hiding this comment

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

I was looking into this a bit; it seems odd to remove the [ with string operations;
actually there is a setDimension method which may accept a List

I wonder if it would be a better fix be to remove this toString() here and fix the PrometheusEmitter to alter the serialization of List -s to do adjustments there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @kgyrtkirk ,
That's right, setDimension(String dim, Object value) can accept a List as well.

About fixing it in the PrometheusEmitter: Initially, even I started with the same thought process, but later realized that the issue impacts all the emitters. A few examples (Prometheus, Kafka, Logging) cited in #17743 . Hence, decided to perform the string clean up operation here.

Copy link
Member

Choose a reason for hiding this comment

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

wow; didn't know about that - then you might want to fix the handling of when the passed value is List in the builder to deliver it for all cases - and not just for this one case?

note: I wonder how the case when the list has a "," in it should be handled...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By Builder, do you mean, stmt.authResult.sqlResourceActions above? This is a Set of ResourceActions; so we will have to iterate on that and form a list.

This PR will fix the metrics coming from SQL query execution only. For other metrics, there's the separate issue that we are working on.

note: I wonder how the case when the list has a "," in it should be handled...

Currently, we see that a list that has , in it, gets translated to "[a,b]" as a string. With the change in this PR, it will be "a,b". Furthermore, Prometheus Emitter replaces all non alphanumeric and non underscore characters with _; so it would look like "_a_b_"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @kgyrtkirk, any thoughts on the above comment? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

41712b7
Looks like this has been the behavior for a long time.
Changing it here means its a backward incompatible change since dashboards start breaking.

Copy link
Contributor

@kfaraz kfaraz Mar 6, 2025

Choose a reason for hiding this comment

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

+1, I think the existing behaviour is fine the way it is.

I don't think Druid docs mention anywhere that the values of a dimension must adhere to the same format across different metrics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataSource values are decorated with extra characters for metrics emitters
4 participants