度量指标导出器
导出路由器指标
诗GraphOS 路由器和Apollo 路由器核心支持使用以下方式收集指标:OpenTelemetry,以下导出器支持:
在 router.yaml
中,您可以配置 router 指标,以下设置如下:
telemetry.exporters.metrics.common
。配置所有指标导出器共有的路由器值。telemetry.exporters.metrics.prometheus
。配置 Prometheus 导出器。telemetry.exporters.metrics.otlp
。配置 OpenTelemetry 导出器。支持将追踪数据发送到 Datadog。
指标通用配置
通用指标配置包含所有导出器的全局设置
service_name
为您的 router 指标设置服务名称,以便您可以在外部指标仪表板中轻松找到它们。
服务名称可以通过环境变量或在 router.yaml
中设置,优先级顺序(从高到低)如下:
OTEL_SERVICE_NAME
环境变量OTEL_RESOURCE_ATTRIBUTES
环境变量telemetry.exporters.metrics.common.service_name
在router.yaml
telemetry.exporters.metrics.common.resource
在router.yaml
如果没有显式设置服务名称,默认为 unknown_service:router
或 unknown_service
(如果无法确定可执行程序名称)。
资源
资源属性是一组键值对,它为导出器提供附加信息。它是 OpenTelemetry 资源 的属性。应用程序性能监控器(APM)可以解释和显示资源信息。
在 router.yaml
中,资源属性在 telemetry.metrics.common.resource
中设置。例如:
telemetry:exporters:metrics:common:resource:"environment.name": "production""environment.namespace": "{env.MY_K8_NAMESPACE_ENV_VARIABLE}"
有关 OpenTelemetry 资源约定,请参阅 资源语义约定。
桶
您可以设置生成的所有直方图的桶边界,通过在 router.yaml
中设置 telemetry.exporters.metrics.common.buckets
。例如:
telemetry:exporters:metrics:common:buckets:- 0.05- 0.10- 0.25- 0.50- 1.00- 2.50- 5.00- 10.00- 20.00
属性
您可以将自定义属性(OpenTelemetry)和标签(Prometheus)添加到 apollo_router_http_requests
指标。属性可以是:
ⓘ 注意
使用 资源属性 来提供关于遥测资源的信息,包括主机和环境。
以下是一个配置这些属性的示例
telemetry:exporters:metrics:common:attributes:supergraph: # Attribute configuration for requests to/responses from the routerstatic:- name: "version"value: "v1.0.0"request:header:- named: "content-type"rename: "payload_type"default: "application/json"- named: "x-custom-header-to-add"response:body:# Apply the value of the provided path of the router's response body as an attribute- path: .errors[0].extensions.http.statusname: error_from_body# Use the unique extension code to identify the kind of error- path: .errors[0].extensions.codename: error_codecontext:# Apply the indicated element from the plugin chain's context as an attribute- named: my_keysubgraph: # Attribute configuration for requests to/responses from subgraphsall:static:# Always apply this attribute to all metrics for all subgraphs- name: kindvalue: subgraph_requesterrors: # Only work if it's a valid GraphQL error (for example if the subgraph returns an http error or if the router can't reach the subgraph)include_messages: true # Will include the error message in a message attributeextensions: # Include extensions data- name: subgraph_error_extended_type # Name of the attributepath: .type # JSON query path to fetch data from extensions- name: messagepath: .reason# Will create this kind of metric for example apollo_router_http_requests_error_total{message="cannot contact the subgraph",subgraph="my_subgraph_name",subgraph_error_extended_type="SubrequestHttpError"}subgraphs:my_subgraph_name: # Apply these rules only for the subgraph named `my_subgraph_name`request:header:- named: "x-custom-header"body:# Apply the value of the provided path of the router's request body as an attribute (here it's the query)- path: .queryname: querydefault: UNKNOWN
视图
通过此配置,您可以覆盖特定指标的自定义属性和默认桶。
telemetry:exporters:metrics:common:service_name: apollo-routerviews:- name: apollo_router_http_request_duration_seconds # Instrument name you want to edit. You can use wildcard in names. If you want to target all instruments just use '*'unit: "ms" # (Optional) override the unitdescription: "my new description of this metric" # (Optional) override the descriptionaggregation: # (Optional)histogram:buckets: # Override default buckets configured for this histogram- 1- 2- 3- 4- 5allowed_attribute_keys: # (Optional) Keep only listed attributes on the metric- status
如果您不希望将特定指标发送到APM,可以删除这些指标。
telemetry:exporters:metrics:common:service_name: apollo-routerviews:- name: apollo_router_http_request_duration_seconds # Instrument name you want to edit. You can use wildcard in names. If you want to target all instruments just use '*'aggregation: drop
指标常用参考
属性 | 默认值 | 描述 |
---|---|---|
service_name | unknown_service:router | OpenTelemetry服务名称。 |
service_namespace | OpenTelemetry命名空间。 | |
资源 | 要将资源附加到指标上的OpenTelemetry资源。 | |
属性 | 针对 apollo_router_http_requests 仪表的定制。 | |
视图 | 覆盖指标的默认桶或配置(包括删除整个指标) |