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: implement otlp exporter #360

Merged
merged 7 commits into from
Dec 20, 2022

Conversation

alexandrebrg
Copy link
Contributor

@alexandrebrg alexandrebrg commented Nov 23, 2022

This PR adds the ability to export metrics through OpenTelemetry protocol.

Description

This PR implements a way to use metrics given by OpenFGA. The default behavior is that no metrics are exposed NoopMeter is used.

How OTLP is implemented ?

Metrics export can be either done by gRPC or by HTTP. The endpoint can also be configured. There isn't a lot of parameters implemented as the SDK can contain a lot of breaking changes through time. Moreover, OpenTelemetry SDK can be configured through environment variables (see SDK).

How to test OTLP implementation ?

openfga run --metrics-exporter "otlp" --metrics-endpoint "localhost:9000" --metrics-protocol "grpc"

(An Otel Collector can be installed easily with opentelemetry-collector-contrib/examples/demo)

References

#254

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • (Pending) I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 23, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@alexandrebrg alexandrebrg marked this pull request as ready for review November 23, 2022 11:33
@alexandrebrg alexandrebrg requested a review from a team as a code owner November 23, 2022 11:33
@craigpastro
Copy link
Contributor

Wow! Thanks for this great PR. The OpenFGA team is on vacation this week, but we’ll try to get around to reviewing this early next week. Thanks again for the contribution!

@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2022

Codecov Report

Base: 84.68% // Head: 84.54% // Decreases project coverage by -0.14% ⚠️

Coverage data is based on head (7c79a3e) compared to base (e96509a).
Patch coverage: 62.50% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #360      +/-   ##
==========================================
- Coverage   84.68%   84.54%   -0.15%     
==========================================
  Files          84       84              
  Lines       13834    13895      +61     
==========================================
+ Hits        11716    11747      +31     
- Misses       1736     1759      +23     
- Partials      382      389       +7     
Impacted Files Coverage Δ
server/commands/check.go 87.50% <ø> (-0.53%) ⬇️
cmd/run.go 51.54% <31.81%> (-0.59%) ⬇️
pkg/telemetry/metrics.go 76.92% <76.00%> (-23.08%) ⬇️
server/commands/check_utils.go 97.60% <0.00%> (-1.44%) ⬇️
storage/mysql/mysql.go 69.21% <0.00%> (-0.53%) ⬇️
storage/memory/memory.go 93.97% <0.00%> (+0.40%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jon-whit
Copy link
Member

@alexandrebrg thanks for contributing 👍 We've had telemetry on the todo list for a hot-minute.

I like the approach you've taken here, and we'd love to move forward with your contribution. However, we'd like to minimize the maintenance footprint of the OpenTelemetry integration in OpenFGA. For this reason, we'd prefer to support a single OpenTelemetry exporter and encourage the community to use the OTEL Collector if they need to collect and transform to an alternative format (e.g. prometheus, jaeger, etc..).

Would you mind repurposing this PR to expose only the otlp exporter ?

cmd/run.go Outdated Show resolved Hide resolved
@alexandrebrg
Copy link
Contributor Author

@alexandrebrg thanks for contributing 👍 We've had telemetry on the todo list for a hot-minute.

I like the approach you've taken here, and we'd love to move forward with your contribution. However, we'd like to minimize the maintenance footprint of the OpenTelemetry integration in OpenFGA. For this reason, we'd prefer to support a single OpenTelemetry exporter and encourage the community to use the OTEL Collector if they need to collect and transform to an alternative format (e.g. prometheus, jaeger, etc..).

Would you mind repurposing this PR to expose only the otlp exporter ?

Thank you! I'll update the PR accordingly with your request 😄

@alexandrebrg alexandrebrg changed the title feat: add metrics exporters feat: implement otlp exporter Dec 5, 2022
.config-schema.json Outdated Show resolved Hide resolved
Copy link
Contributor

@craigpastro craigpastro left a comment

Choose a reason for hiding this comment

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

Hi @alexandrebrg, great PR! Thank you for this work. I left a couple of very small comments. I suppose the big issue is the change from gauge to counter. I don't have an opinion yet, but I'll form one and join the conversation there.

Thanks again!

pkg/telemetry/metrics.go Outdated Show resolved Hide resolved
pkg/telemetry/metrics.go Outdated Show resolved Hide resolved
cmd/run.go Outdated Show resolved Hide resolved
cmd/run.go Outdated Show resolved Hide resolved
cmd/run.go Outdated Show resolved Hide resolved
cmd/run.go Outdated Show resolved Hide resolved
cmd/run.go Outdated Show resolved Hide resolved
cmd/run_test.go Outdated Show resolved Hide resolved
cmd/run_test.go Outdated Show resolved Hide resolved
cmd/run_test.go Outdated Show resolved Hide resolved
@alexandrebrg
Copy link
Contributor Author

Hello, I applied all of your reviews, thank you for the time given on this PR :)

pkg/telemetry/metrics.go Outdated Show resolved Hide resolved
pkg/telemetry/metrics.go Outdated Show resolved Hide resolved
pkg/telemetry/metrics.go Outdated Show resolved Hide resolved
Copy link
Contributor

@craigpastro craigpastro left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution @alexandrebrg 🙌 This is great!

I added host and runtime metrics to your PR just so we can get it in quickly.

Thanks again!

@rhamzeh
Copy link
Member

rhamzeh commented Feb 8, 2023

@alexandrebrg, we're considering replacing our OpenTelemetry metrics for Prometheus metrics. @jon-whit expanded more on our reasoning here: #514 (comment)

We wanted to check in with you and get your opinion on this change, please feel free to add any comments on @jon-whit's PR here

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

6 participants