From 82c048d7818a2394e8a9cdce001649959474a4ae Mon Sep 17 00:00:00 2001 From: Joan Fontanals Martinez Date: Thu, 10 Nov 2022 18:54:46 +0100 Subject: [PATCH] docs: add covered metrics in docs --- docs/fundamentals/flow/instrumenting-flow.md | 6 +- jina/serve/runtimes/head/request_handling.py | 62 +++++++++++++------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/docs/fundamentals/flow/instrumenting-flow.md b/docs/fundamentals/flow/instrumenting-flow.md index 3e0d4cd9fab42..350bd478a8b16 100644 --- a/docs/fundamentals/flow/instrumenting-flow.md +++ b/docs/fundamentals/flow/instrumenting-flow.md @@ -166,9 +166,13 @@ You can find more information on the different type of metrics in Prometheus [he |-----------------------------------------|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------| | `jina_receiving_request_seconds` | [Histogram](https://opentelemetry.io/docs/reference/specification/metrics/api/#histogram) | Measures the time elapsed between receiving a request from the Gateway and sending back the response. | | `jina_sending_request_seconds` | [Histogram](https://opentelemetry.io/docs/reference/specification/metrics/api/#histogram) | Measures the time elapsed between sending a downstream request to an Executor and receiving the response back. | -| `jina_sent_request_bytes` | [Histogram](https://opentelemetry.io/docs/reference/specification/metrics/api/#histogram) | Measures the size in bytes of the request sent by the Head to the Executor. | +| `jina_number_of_pending_requests` | [UpDownCounter](https://opentelemetry.io/docs/reference/specification/metrics/api/#updowncounter)| Counts the number of pending requests. | +| `jina_successful_requests` | [Counter](https://opentelemetry.io/docs/reference/specification/metrics/api/#counter) | Counts the number of successful requests returned by the Head. | +| `jina_failed_requests` | [Counter](https://opentelemetry.io/docs/reference/specification/metrics/api/#counter) | Counts the number of failed requests returned by the Head. | | `jina_sent_request_bytes` | [Histogram](https://opentelemetry.io/docs/reference/specification/metrics/api/#histogram) | Measures the size in bytes of the request sent by the Head to the Executor. | | `jina_received_response_bytes` | [Histogram](https://opentelemetry.io/docs/reference/specification/metrics/api/#histogram) | Measures the size in bytes of the response returned by the Executor. | +| `jina_received_request_bytes` | [Histogram](https://opentelemetry.io/docs/reference/specification/metrics/api/#histogram) | Measures the size of the request in bytes received at the Head level. | +| `jina_sent_response_bytes` | [Histogram](https://opentelemetry.io/docs/reference/specification/metrics/api/#histogram) | Measures the size in bytes of the response returned from the Head to the Gateway. | #### Executor Pods diff --git a/jina/serve/runtimes/head/request_handling.py b/jina/serve/runtimes/head/request_handling.py index 858dc12df80c3..025898b267735 100644 --- a/jina/serve/runtimes/head/request_handling.py +++ b/jina/serve/runtimes/head/request_handling.py @@ -1,15 +1,14 @@ import asyncio -from typing import TYPE_CHECKING, Dict, List, Optional, Tuple +from typing import TYPE_CHECKING, Dict, Optional, Tuple from jina.serve.runtimes.monitoring import MonitoringRequestMixin from jina.serve.runtimes.worker.request_handling import WorkerRequestHandler if TYPE_CHECKING: # pragma: no cover - from jina.logging.logger import JinaLogger - from opentelemetry.metrics import Meter from prometheus_client import CollectorRegistry + from jina.logging.logger import JinaLogger from jina.types.request.data import DataRequest @@ -22,11 +21,11 @@ class HeaderRequestHandler(MonitoringRequestMixin): """ def __init__( - self, - logger: 'JinaLogger', - metrics_registry: Optional['CollectorRegistry'] = None, - meter: Optional['Meter'] = None, - runtime_name: Optional[str] = None + self, + logger: 'JinaLogger', + metrics_registry: Optional['CollectorRegistry'] = None, + meter: Optional['Meter'] = None, + runtime_name: Optional[str] = None, ): super().__init__(metrics_registry, meter, runtime_name) self.logger = logger @@ -34,7 +33,15 @@ def __init__( self._gathering_endpoints = False self.runtime_name = runtime_name - async def _gather_worker_tasks(self, requests, connection_pool, deployment_name, polling_type, timeout_send, retries): + async def _gather_worker_tasks( + self, + requests, + connection_pool, + deployment_name, + polling_type, + timeout_send, + retries, + ): worker_send_tasks = connection_pool.send_requests( requests=requests, deployment=deployment_name, @@ -62,11 +69,11 @@ async def _gather_worker_tasks(self, requests, connection_pool, deployment_name, @staticmethod def _merge_metadata( - metadata, - uses_after_metadata, - uses_before_metadata, - total_shards, - failed_shards, + metadata, + uses_after_metadata, + uses_before_metadata, + total_shards, + failed_shards, ): merged_metadata = {} if uses_before_metadata: @@ -84,9 +91,17 @@ def _merge_metadata( return merged_metadata async def _handle_data_request( - self, requests: List[DataRequest], connection_pool, uses_before_address, uses_after_address, - timeout_send, retries, reduce, polling_type, deployment_name - ) -> Tuple[DataRequest, Dict]: + self, + requests, + connection_pool, + uses_before_address, + uses_after_address, + timeout_send, + retries, + reduce, + polling_type, + deployment_name, + ) -> Tuple['DataRequest', Dict]: for req in requests: self._update_start_request_metrics(req) WorkerRequestHandler.merge_routes(requests) @@ -110,9 +125,14 @@ async def _handle_data_request( exceptions, total_shards, failed_shards, - ) = await self._gather_worker_tasks(requests=requests, deployment_name=deployment_name, - timeout_send=timeout_send, connection_pool=connection_pool, - polling_type=polling_type, retries=retries) + ) = await self._gather_worker_tasks( + requests=requests, + deployment_name=deployment_name, + timeout_send=timeout_send, + connection_pool=connection_pool, + polling_type=polling_type, + retries=retries, + ) if len(worker_results) == 0: if exceptions: @@ -157,4 +177,4 @@ async def _handle_data_request( self._update_end_request_metrics(response_request) - return response_request, merged_metadata \ No newline at end of file + return response_request, merged_metadata