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

Add Prometheus Remote Write Exporter (3/6) #207

Merged
merged 1 commit into from
Dec 2, 2020

Conversation

shovnik
Copy link
Contributor

@shovnik shovnik commented Nov 23, 2020

Description

This is PR 3/6 of adding a Prometheus Remote Write Exporter in Python SDK and address Issue open-telemetry/opentelemetry-python#1302

Part 1/6

  • Adds class skeleton
  • Adds all function signatures

Part 2/6

  • Adds validation of exporter constructor commands
  • Add unit tests for validation

👉 Part 3/6

  • Adds conversion methods from OTel metric types to Prometheus TimeSeries
  • Add unit tests for conversion

Part 4/6

  • Adds methods to export metrics to Remote Write endpoint
  • Add unit tests for exporting

Part 5/6

  • Add integration tests using sample app and instance of Cortex

Part 6/6

  • Add README, Design Doc and other necessary documentation.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Added class TestValidation in test_prometheus_remote_write_exporter.py

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated (change logs will be updated when PR 7/7 is merged and the RW exporter is complete)
  • Unit tests have been added
  • Documentation has been updated
    cc- @AzfaarQureshi , @alolita

@shovnik shovnik requested a review from a team as a code owner November 23, 2020 23:32
@shovnik shovnik requested review from toumorokoshi and hectorhdzg and removed request for a team November 23, 2020 23:32
@shovnik shovnik changed the title Prometheus Remote Write Exporter PR (3/7) Prometheus Remote Write Exporter PR (3/6) Nov 24, 2020
@shovnik shovnik changed the title Prometheus Remote Write Exporter PR (3/6) Add Prometheus Remote Write Exporter (3/6) Nov 24, 2020
Copy link
Contributor

@ocelotl ocelotl left a comment

Choose a reason for hiding this comment

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

Please take a look at the comments and check what can be refactored from the test cases. 👍

@shovnik shovnik force-pushed the 2-prometheus-remote-write branch 4 times, most recently from 07893f4 to f971041 Compare November 27, 2020 00:52

def add_label(label_name, label_value):
# Label name must contain only alphanumeric characters and underscores
label_name = re.sub("[^\\w_]", "_", label_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we might get labels that are supposed to be unique but will be dropped due to removal of these characters. Is the alphanumeric + underscores limitation of the labels specific for Prometheus?

e.g.
testing and ${testing}

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 limitation is specific to the TimeSeries type https://prometheus.io/docs/concepts/data_model/ . You bring up a valid point. Since the non-alphanumeric characters are replaced with underscores: '$testing' and '_testing' will be considered the same label which would be an issue. Also, a label_name cannot start with two underscores. Would it be better to validate label names (raise Error) or add more complex sanitizing? I am not quite sure how to prevent duplicates when addressing label names that contain non-alphanumeric characters.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the limitation is Prometheus specific, I am okay with the current implementation. The only problem was if it were a limitation we imposed on the OT side, then Prometheus users would have unexpected behaviour. But if it's on the Prometheus side, then user's should EXPECT this behaviour.

I wonder in this case if we should DROP labels that defy the TimeSeries definition (and maybe log a warning), instead of only dropping the duplicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the rare case this occurs, I think whoever is misusing the exporter will value the label with the non-ascii characters as much as the valid one, so I suggest dropping the duplicate but logging a warning that after sanitizing, a duplicate label had to be dropped.

Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

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

Some comments.

@shovnik shovnik force-pushed the 2-prometheus-remote-write branch 4 times, most recently from f537701 to 96d22ae Compare November 30, 2020 20:34
@shovnik
Copy link
Contributor Author

shovnik commented Dec 1, 2020

All comments have been addressed @lzchen.

"%s aggregator is not supported, record dropped",
aggregator_type,
)
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to return here? We just want to skip the record.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought to skip the record, I would need to return both here and in the calling "export" method. I was planning on adding this to the export method:
if timeseries is None:
return

Is there a better way to skip the record from an inner method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I misunderstood it as skip the batch. I fixed this to only skip the record and log a warning. I will add an additional check to not send empty requests in the subsequent PR.

@shovnik shovnik force-pushed the 2-prometheus-remote-write branch 2 times, most recently from 7e6ae1b to fd8bb30 Compare December 1, 2020 20:11
Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

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

Nice!

@lzchen lzchen merged commit f71bc2b into open-telemetry:master Dec 2, 2020
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.

None yet

3 participants