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

[Merged by Bors] - api: Add go-http-metrics to collect API metrics #6099

Closed
wants to merge 13 commits into from

Conversation

kacpersaw
Copy link
Contributor

Motivation

By integrating go-http-metrics, we can gain detailed insights into the performance and behavior of our APIs.

Copy link

codecov bot commented Jul 4, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 81.6%. Comparing base (0712be8) to head (fc8a0d8).

Files Patch % Lines
api/grpcserver/http_server.go 46.1% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #6099   +/-   ##
=======================================
  Coverage     81.5%   81.6%           
=======================================
  Files          302     302           
  Lines        32478   32488   +10     
=======================================
+ Hits         26502   26517   +15     
+ Misses        4240    4238    -2     
+ Partials      1736    1733    -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

)

// recorder is a global recorder for http metrics.
var recorder *httpMetrics.Recorder
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why is a global variable needed here? StartService is called once in the whole codebase. It can just live as a variable scoped in the method, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

@fasmat fasmat left a comment

Choose a reason for hiding this comment

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

Why do we need a dedicated dependency for this? We already use github.com/grpc-ecosystem/go-grpc-middleware which has a metrics provider: https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/providers/prometheus

Wouldn't this work too?

@@ -67,6 +72,7 @@ func (s *JSONHTTPServer) Shutdown(ctx context.Context) error {
// StartService starts the json api server and listens for status (started, stopped).
func (s *JSONHTTPServer) StartService(
ctx context.Context,
collectMetrics bool,
Copy link
Member

Choose a reason for hiding this comment

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

In my opinion this flag should be part of the instantiation of the JSONHTTPServer. The NewJSONHTTPServer already takes two values from the app.Config.API object, I see no problem if it takes the whole object.

I think it also makes sense to not use the general app.Config.CollectMetrics flag for this, but instead have a dedicated flag in the API config. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, forgot about this. Fixing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fasmat We can create separate option in API config for this, but then we will need to expose another metrics server.
https://github.com/spacemeshos/go-spacemesh/blob/develop/node/node.go#L2131

If that's ok, let me know

Copy link
Member

Choose a reason for hiding this comment

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

Why do we have 2 metric servers? Can't the information you collect be exposed at the existing one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's fine. I was thinking about the case when the user enables metrics in the API but not in the main configuration itself. However, we can validate that.

Copy link
Member

Choose a reason for hiding this comment

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

ah ok I misunderstood, then yes there should only be one config option (probably the Config.CollectMetrics and that can just be passed to the server 🙂

@kacpersaw
Copy link
Contributor Author

Why do we need a dedicated dependency for this? We already use github.com/grpc-ecosystem/go-grpc-middleware which has a metrics provider: https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/providers/prometheus

Wouldn't this work too?

This middleware does not show metrics for individual endpoints, nor does it indicate whether the response is a success or failure.

@kacpersaw kacpersaw requested a review from fasmat July 5, 2024 12:16
@kacpersaw
Copy link
Contributor Author

bors merge

@spacemesh-bors
Copy link

spacemesh-bors bot commented Jul 5, 2024

👎 Rejected by code reviews

@kacpersaw
Copy link
Contributor Author

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Jul 5, 2024
## Motivation

By integrating go-http-metrics, we can gain detailed insights into the performance and behavior of our APIs.
@spacemesh-bors
Copy link

spacemesh-bors bot commented Jul 5, 2024

Build failed:

  • systest-status

@kacpersaw
Copy link
Contributor Author

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Jul 6, 2024
## Motivation

By integrating go-http-metrics, we can gain detailed insights into the performance and behavior of our APIs.
@spacemesh-bors
Copy link

spacemesh-bors bot commented Jul 6, 2024

Build failed:

@kacpersaw
Copy link
Contributor Author

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Jul 6, 2024
## Motivation

By integrating go-http-metrics, we can gain detailed insights into the performance and behavior of our APIs.
@spacemesh-bors
Copy link

spacemesh-bors bot commented Jul 6, 2024

Pull request successfully merged into develop.

Build succeeded:

@spacemesh-bors spacemesh-bors bot changed the title api: Add go-http-metrics to collect API metrics [Merged by Bors] - api: Add go-http-metrics to collect API metrics Jul 6, 2024
@spacemesh-bors spacemesh-bors bot closed this Jul 6, 2024
@spacemesh-bors spacemesh-bors bot deleted the api-http-metrics branch July 6, 2024 08:33
kacpersaw added a commit that referenced this pull request Jul 10, 2024
## Motivation

By integrating go-http-metrics, we can gain detailed insights into the performance and behavior of our APIs.
kacpersaw added a commit that referenced this pull request Jul 10, 2024
[backport] api: Add go-http-metrics to collect API metrics (#6099)
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.

4 participants