Skip to content

Commit

Permalink
docs: add covered metrics in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Nov 10, 2022
1 parent d910673 commit 82c048d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
6 changes: 5 additions & 1 deletion docs/fundamentals/flow/instrumenting-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
62 changes: 41 additions & 21 deletions jina/serve/runtimes/head/request_handling.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -22,19 +21,27 @@ 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
self._executor_endpoint_mapping = None
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,
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -157,4 +177,4 @@ async def _handle_data_request(

self._update_end_request_metrics(response_request)

return response_request, merged_metadata
return response_request, merged_metadata

0 comments on commit 82c048d

Please sign in to comment.