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 otel instrumentation for http-grpc gateway #522

Merged
merged 7 commits into from
Nov 13, 2024
Merged

Add otel instrumentation for http-grpc gateway #522

merged 7 commits into from
Nov 13, 2024

Conversation

py4chen
Copy link
Contributor

@py4chen py4chen commented Nov 12, 2024

Currently no metrics are collected if the requests come through grpc-gateway because grpc interceptors don't work in http request flow.

PR adds otel instrumentation to http gmux, and collects metrics for panic.

--

Verification

  • Run a local otel collector container
$ cat <<EOF > ./local-collector/otel-collector-config.yaml
receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318

processors:
  batch:

exporters:
  prometheus:
    endpoint: "0.0.0.0:8889"
  debug:
    verbosity: detailed

service:
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [debug, prometheus]
EOF
$ docker run --rm --network host -p 4317:4317 -p 4318:4318 -p 8889:8889 -v ./local-collector/otel-collector-config.yaml:/etc/otel-collector-config.yaml otel/opentelemetry-collector:latest --config /etc/otel-collector-config.yaml
  • Modify Crypki sourcecode adding panic intentionally, and run the crypki container
  • Send requests to the container
❯ curl -X GET https://localhost:4443/v3/sig/ssh-host-cert/keys --cert tls-crt/client.crt --key tls-crt/client.key --cacert tls-crt/ca.crt -v

❯ curl -X GET https://localhost:4443/v3/sig/ssh-user-cert/keys --cert tls-crt/client.crt --key tls-crt/client.key --cacert tls-crt/ca.crt -v
  • find metrics
# HELP http_handler_panic_total Count the number of HTTP handler panic
# TYPE http_handler_panic_total counter
http_handler_panic_total{http_method="GET",http_target="/v3/sig/ssh-user-cert/keys",job="crypki",panic_message="debug panic!"} 2
...
cert/keys",job="crypki",net_host_name="localhost",net_host_port="4443",net_protocol_name="http",net_protocol_version="2.0"} 0.742625
http_server_duration_milliseconds_count{http_method="GET",http_scheme="https",http_status_code="200",http_target="/v3/sig/ssh-host-cert/keys",job="crypki",net_host_name="localhost",net_host_port="4443",net_protocol_name="http",net_protocol_version="2.0"} 1
...

--

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@py4chen py4chen marked this pull request as ready for review November 12, 2024 15:12
@py4chen py4chen changed the title Add otel instrumentation for http gateway Add otel instrumentation for http-grpc gateway Nov 12, 2024
@py4chen py4chen requested review from maditya and hkadakia November 12, 2024 15:20
@py4chen
Copy link
Contributor Author

py4chen commented Nov 13, 2024

@dependenbot rebase

@py4chen py4chen requested a review from adavis10006 November 13, 2024 14:33
@py4chen py4chen merged commit 60b80b7 into main Nov 13, 2024
5 checks passed
@py4chen py4chen deleted the add-otel2 branch November 13, 2024 23:19
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.

3 participants