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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Prometheus Remote Write Exporter (4/6) #212

Merged
merged 1 commit into from
Dec 8, 2020

Conversation

shovnik
Copy link
Contributor

@shovnik shovnik commented Nov 24, 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
  • 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 24, 2020 20:55
@shovnik shovnik requested review from owais and hectorhdzg and removed request for a team November 24, 2020 20:55
@shovnik shovnik force-pushed the 3-prometheus-remote-write branch 4 times, most recently from 09fe5a2 to ac5f46f Compare November 24, 2020 22:17
@shovnik shovnik changed the title Prometheus Remote Write Exporter PR (4/6) Add Prometheus Remote Write Exporter (4/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.

Some test case result interpretations can be affected by the current implementation, please take a look.

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.

Well done! Just a request to remove unnecessary Mocks.

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.

Great job!

@shovnik shovnik force-pushed the 3-prometheus-remote-write branch 4 times, most recently from b6251fb to f249cc9 Compare December 1, 2020 22:07
@shovnik shovnik force-pushed the 3-prometheus-remote-write branch 2 times, most recently from f199064 to 0dad10e Compare December 3, 2020 17:02
response.reason,
str(response.content),
)
return MetricsExportResult.FAILURE
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we going to be handling retries? Timeouts?, etc?

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 timeout can be adjusted, but if a request fails (timeout or otherwise), we just report failure instead of retrying to avoid requests getting clogged due to records being exported continuously. If we set a timeout, but then retried multiple times, the timeout would no longer limit the time spent attempting to export one set of records. Our reasoning was that missing data is not as bad as delayed data especially in cases of cumulative data where missing data can be interpolated or cases where data is exported on a very short interval. Does not retrying failed requests sound reasonable for this use case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Depends on how robust we want the functionality of this exporter. We can handle it in a different PR in the future if is needed.

@shovnik shovnik force-pushed the 3-prometheus-remote-write branch 3 times, most recently from b1e6880 to 5da9eb2 Compare December 3, 2020 22:16
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

A couple of questions I'd like to have answered before approving.

@@ -16,6 +16,9 @@
import re
from typing import Dict, Sequence

import requests
Copy link
Contributor

Choose a reason for hiding this comment

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

should dependencies be added for python-snappy and requests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One issue that I am running into is that I cannot add python-snappy to the setup.cfg because it depends on the snappy library in C which I had to brew install to get. Is there a way to add a C dependency that a module requires? If not I might have to specify to first manually install snappy library and module before using exporter in README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excluded python-snappy from install-requires for now.

data=message,
headers=headers,
auth=auth,
timeout=self.timeout,
Copy link
Contributor

Choose a reason for hiding this comment

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

would be good to add the default timeout value to the class documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added, will also add to README

self.tls_config["cert_file"],
self.tls_config["key_file"],
)
response = requests.post(
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be wrapped in a try block?

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 did not consider that requests.post could throw exceptions in addition to returning HTTPErrors inside the response. Modified to use a try/except block which handles all request exceptions. (now raises HTTPErrors to be logged as well) This guarantees calling export() will never throw an exception.

@shovnik shovnik force-pushed the 3-prometheus-remote-write branch 3 times, most recently from 5395f9f to c79a4c9 Compare December 4, 2020 18:23
@@ -39,6 +39,8 @@ package_dir=
=src
packages=find_namespace:
install_requires =
protobuf >= 3.13.0
requests == 2.25.0
opentelemetry-api == 0.16.dev0
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you update these dependencies to 0.17.dev0 as well as the current version? It's causing some build failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@shovnik shovnik force-pushed the 3-prometheus-remote-write branch 2 times, most recently from 4847d6a to f9c341e Compare December 7, 2020 16:33
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks for responding to all my comments.

@shovnik shovnik force-pushed the 3-prometheus-remote-write branch 3 times, most recently from 7fea46a to 9c036e1 Compare December 7, 2020 16:44
@lzchen lzchen merged commit b310ec1 into open-telemetry:master Dec 8, 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

4 participants