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 metrics for inbound HTTP requests #97

Merged

Conversation

jhernand
Copy link
Collaborator

This patch adds to all the servers a metrics server that provides the default metrics generated by the Prometheus Go instrumentation library as well as metrics for the number of duration of inbound HTTP requests.

The metrics handler will listen by default in port 8001, but that can be changed with the following options:

  • --metrics-listener-address - Metrics listen address. (default "localhost:8001")
  • --metrics-listener-tls-crt - Metrics TLS certificate in PEM format.
  • --metrics-listener-tls-key - Metrics TLS key in PEM format.

The metrics generated are the following:

  • inbound_request_count - Number of API requests sent.
  • inbound_inbound_request_duration_sum - Total time to send API requests, in seconds.
  • inbound_inbound_request_duration_count - Total number of API requests measured.
  • inbound_inbound_request_duration_bucket - Number of API requests organized in buckets.

With the following labels:

  • method - Name of the HTTP method, for example GET or POST.
  • path - Request path, for example /api/my/v1/resources.
  • code - HTTP response code, for example 200 or 500.

In order to reduce the cardinality of the metrics the path label is modified to remove the identifiers of the objects. For example, if the original path is .../deploymentManagers/123 then it will be replaced by .../deploymentManagers/-, and the values will be accumulated. The line returned by the metrics server will be like this:

inbound_request_count{code="200",method="GET",path=".../deploymentManagers/-"} 56

For example, these are some metrics generated by the deployment manager server:

inbound_request_count{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers"} 4
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="0.1"} 0
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="1"} 0
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="10"} 0
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="30"} 0
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="+Inf"} 4
inbound_request_duration_sum{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers"} 602.541828752
inbound_request_duration_count{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers"} 4

@openshift-ci openshift-ci bot requested review from danielerez and irinamihai April 30, 2024 11:04
Copy link

openshift-ci bot commented Apr 30, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from jhernand. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

This patch adds to all the servers a metrics server that provides the
default metrics generated by the Prometheus Go instrumentation library
as well as metrics for the number of duration of inbound HTTP requests.

The metrics handler will listen by default in port 8001, but that can be
changed with the following options:

- `--metrics-listener-address` - Metrics listen address. (default "localhost:8001")
- `--metrics-listener-tls-crt` - Metrics TLS certificate in PEM format.
- `--metrics-listener-tls-key` - Metrics TLS key in PEM format.

The metrics generated are the following:

- `inbound_request_count` - Number of API requests sent.
- `inbound_inbound_request_duration_sum` - Total time to send API requests, in seconds.
- `inbound_inbound_request_duration_count` - Total number of API requests measured.
- `inbound_inbound_request_duration_bucket` - Number of API requests organized in buckets.

With the following labels:

- `method` - Name of the HTTP method, for example GET or POST.
- `path` - Request path, for example /api/my/v1/resources.
- `code` - HTTP response code, for example 200 or 500.

In order to reduce the cardinality of the metrics the path label is
modified to remove the identifiers of the objects. For example, if the
original path is `.../deploymentManagers/123` then it will be replaced
by `.../deploymentManagers/-`, and the values will be accumulated. The
line returned by the metrics server will be like this:

```
inbound_request_count{code="200",method="GET",path=".../deploymentManagers/-"} 56
```

For example, these are some metrics generated by the deployment manager
server:

```
inbound_request_count{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers"} 4
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="0.1"} 0
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="1"} 0
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="10"} 0
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="30"} 0
inbound_request_duration_bucket{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers",le="+Inf"} 4
inbound_request_duration_sum{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers"} 602.541828752
inbound_request_duration_count{code="500",method="GET",path="/o2ims-infrastructureInventory/-/deploymentManagers"} 4
```

Signed-off-by: Juan Hernandez <[email protected]>
@jhernand jhernand force-pushed the add_metrics_for_inbound_http_requests branch from 2a35ad6 to 7984a54 Compare April 30, 2024 11:28
@jhernand jhernand merged commit b1a7a90 into openshift-kni:main May 2, 2024
7 of 8 checks passed
@jhernand jhernand deleted the add_metrics_for_inbound_http_requests branch May 2, 2024 06:15
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.

1 participant