측정항목 계산은 데이터 관측 가능성을 위해 기존 로그 또는 측정항목을 기반으로 새 측정항목을 생성하는 것을 의미합니다. LoggingRule 커스텀 리소스에서 기록 규칙을 구성하여 GDC에서 측정항목을 계산합니다. 기록 규칙은 자주 필요하거나 계산 비용이 많이 드는 표현식을 미리 계산합니다. 이러한 규칙은 결과를 새로운 시계열 집합으로 저장합니다. 사전 계산된 결과를 쿼리하는 것이 필요할 때마다 원래 표현식을 실행하는 것보다 빠릅니다. 이 사전 계산은 새로고침되거나 평가될 때마다 동일한 표현식을 반복적으로 쿼리해야 하는 대시보드와 복잡한 알림에 특히 유용합니다.
LoggingRule 커스텀 리소스에서 기록 규칙을 구성하여 시스템 로깅 데이터를 기반으로 측정항목을 계산합니다. LoggingRule 커스텀 리소스에는 기존 로그를 기반으로 새 측정항목을 계산하는 조건을 설명하는 녹화 규칙이 포함되어 있습니다.
시작하기 전에
로그에서 측정항목을 계산하는 데 필요한 권한을 얻으려면 프로젝트 IAM 관리자에게 프로젝트 네임스페이스에 다음 역할 중 하나를 부여해 달라고 요청하세요.
로깅 레코드 규칙에 LoggingRule CR 템플릿을 사용하여 CR의 YAML 파일을 열거나 만듭니다.
CR의 namespace 필드에 프로젝트의 네임스페이스를 입력합니다.
name 필드에 규칙 구성의 이름을 입력합니다.
선택사항: source 필드에서 로그 소스를 선택할 수 있습니다. 예를 들어 operational 또는 audit과 같은 값을 입력합니다.
interval 필드에 규칙 평가 간격의 지속 시간(초)을 입력합니다.
(선택사항) limit 필드에 최대 알림 수를 입력합니다. 알림을 무제한으로 설정하려면 0를 입력합니다.
recordRules 필드에 다음 정보를 입력하여 측정항목을 계산합니다.
record 필드에 레코드 이름을 입력합니다. 이 값은 레코드 규칙을 작성할 시계열을 정의하며 유효한 측정항목 이름이어야 합니다.
expr 필드에 로그 규칙의 LogQL 표현식을 입력합니다.
이 표현식은 새 측정항목으로 기록되려면 숫자 값으로 평가되어야 합니다.
선택사항: labels 필드에서 추가하거나 덮어쓸 라벨을 키-값 쌍으로 정의합니다.
CR의 YAML 파일을 저장합니다.
관리자 클러스터의 프로젝트 네임스페이스에 CR을 배포하여 레코드 규칙을 만듭니다.
LoggingRule 레코드 규칙
LoggingRule 맞춤 리소스에는 관측 가능성을 위해 기존 시스템 로깅 데이터를 기반으로 새 측정항목을 계산하는 조건을 설명하는 녹화 규칙이 포함되어 있습니다.
다음 YAML 파일은 LoggingRule CR의 recordRules 필드 템플릿을 보여줍니다.
# Configures either an alert or a target record for precomputationapiVersion:logging.gdc.goog/v1alpha1kind:LoggingRulemetadata:# Choose namespace that matches the project's namespace# Note: The alert or record will be produced in the same namespacenamespace:PROJECT_NAMESPACEname:alerting-configspec:# Choose which log source to base alerts on (Operational/Audit/Security Logs)# Optional, Default: Operationalsource:<string>
# Rule evaluation intervalinterval:<duration>
# Configure limit for number of alerts (0: no limit)# Optional, Default: 0 (no limit)limit:<int>
# Configure record rules to generate new metrics based on pre-existing logs.# Record rules generate metrics based on logs.# Use record rules for complex alerts, which query the same expression repeatedly every time they are evaluated.recordRules:# Define which timeseries to write to (must be a valid metric name)-record:<string>
# Define LogQL expression to evaluate for this rule# https://grafana.com/docs/loki/latest/rules/expr:<string>
# Define labels to add or overwrite# Optional, Map of {key, value} pairslabels:<labelname>:<labelvalue>
...
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eMetrics can be calculated in GDC by configuring recording rules within a \u003ccode\u003eLoggingRule\u003c/code\u003e custom resource, precomputing frequently needed or complex expressions for faster querying.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eLoggingRule\u003c/code\u003e custom resource defines the conditions for creating new metrics derived from existing system logs, making it useful for dashboards and complex alerts.\u003c/p\u003e\n"],["\u003cp\u003eUsers require specific IAM roles such as Logging Rule Creator, Editor, or Viewer to interact with \u003ccode\u003eLoggingRule\u003c/code\u003e custom resources for calculating metrics.\u003c/p\u003e\n"],["\u003cp\u003eCreating a recording rule involves defining a record name and a LogQL expression that evaluates to a numeric value, and then deploying the custom resource within the project's namespace on the org admin cluster.\u003c/p\u003e\n"],["\u003cp\u003eWhen configuring a recording rule in the \u003ccode\u003eLoggingRule\u003c/code\u003e custom resource, you can specify the log source, evaluation interval, and limit for the number of alerts, along with the record name, expression, and optional labels.\u003c/p\u003e\n"]]],[],null,["# Calculate metrics from logs\n\nCalculating metrics means generating new metrics based on pre-existing logs or metrics for data observability. You calculate metrics in GDC by configuring recording rules in a `LoggingRule` custom resource. Recording rules precompute expressions that are frequently needed or computationally expensive. These rules save their result as a new set of time series. Querying the precomputed result is faster than executing the original expression whenever needed. This precomputation is especially useful for dashboards and complex alerts, which must query the same expression repeatedly every time they refresh or are evaluated.\n\nYou configure recording rules in the `LoggingRule` custom resource to calculate metrics based on system logging data. The `LoggingRule` custom resource contains recording rules that describe the conditions to calculate new metrics based on pre-existing logs.\n\nBefore you begin\n----------------\n\nTo get the permissions you need to calculate metrics from logs, ask your Project IAM Admin to grant you one of the following roles in your project namespace:\n\n- **Logging Rule Creator** : creates `LoggingRule` custom resources. Request the Logging Rule Creator (`loggingrule-creator`) role.\n- **Logging Rule Editor** : edits or modifies `LoggingRule` custom resources. Request the Logging Rule Editor (`loggingrule-editor`) role.\n- **Logging Rule Viewer** : views `LoggingRule` custom resources. Request the Logging Rule Viewer (`loggingrule-viewer`) role.\n\nCreate recording rules\n----------------------\n\nDefine a record name and a valid expression that evaluates the rule. The expression must resolve to a numeric value to record it as a new metric. Deploy the custom resource in your project namespace on the org admin cluster to create the recording rules for the Observability platform.\n| **Important:** To create rules, verify that a project is deployed with workloads. To have data your rules can act on, verify that you configured log collection.\n\nFor more information about recording rules for Observability, see \u003chttps://grafana.com/docs/loki/latest/rules/\u003e\n\nWork through the following steps to create record rules and calculate metrics in your project's namespace:\n\n1. Open or create the YAML file for the CR using [the `LoggingRule` CR](#loggingrule-recordrules) template for logging record rules.\n2. In the `namespace` field of the CR, enter your project's namespace.\n3. In the `name` field, enter the name for the rule configuration.\n4. Optional: You can choose the log source in the `source` field. For example, enter a value such as `operational` or `audit`.\n5. In the `interval` field, enter the number of seconds for the duration of the rule evaluation interval.\n6. Optional: In the `limit` field, enter the maximum number of alerts. Enter `0` for unlimited alerts.\n7. In the `recordRules` field, enter the following information to calculate metrics:\n\n - In the `record` field, enter the record name. This value defines the time series in which to write the record rule and it must be a valid metric name.\n - In the `expr` field, enter a LogQL expression for the log rule.\n\n This expression must resolve to a numeric value to be recorded as a new metric.\n - Optional: In the `labels` field, define the labels that you want to add or overwrite as key-value pairs.\n\n8. Save the YAML file of the CR.\n\n9. Deploy the CR in your project's namespace of the admin cluster to create the record rules.\n\nThe `LoggingRule` record rules\n------------------------------\n\nA `LoggingRule` custom resource contains recording rules that describe the conditions to calculate new metrics based on pre-existing system logging data for observability.\n\nThe following YAML file shows a template for the `recordRules` field of the `LoggingRule` CR. \n\n # Configures either an alert or a target record for precomputation\n apiVersion: logging.gdc.goog/v1alpha1\n kind: LoggingRule\n metadata:\n # Choose namespace that matches the project's namespace\n # Note: The alert or record will be produced in the same namespace\n namespace: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_NAMESPACE\u003c/span\u003e\u003c/var\u003e\n name: alerting-config\n spec:\n # Choose which log source to base alerts on (Operational/Audit/Security Logs)\n # Optional, Default: Operational\n source: \u003cstring\u003e\n\n # Rule evaluation interval\n interval: \u003cduration\u003e\n\n # Configure limit for number of alerts (0: no limit)\n # Optional, Default: 0 (no limit)\n limit: \u003cint\u003e\n\n # Configure record rules to generate new metrics based on pre-existing logs.\n # Record rules generate metrics based on logs.\n # Use record rules for complex alerts, which query the same expression repeatedly every time they are evaluated.\n recordRules:\n # Define which timeseries to write to (must be a valid metric name)\n - record: \u003cstring\u003e\n\n # Define LogQL expression to evaluate for this rule\n # https://grafana.com/docs/loki/latest/rules/\n expr: \u003cstring\u003e\n\n # Define labels to add or overwrite\n # Optional, Map of {key, value} pairs\n labels:\n \u003clabelname\u003e: \u003clabelvalue\u003e\n ...\n\nReplace \u003cvar translate=\"no\"\u003ePROJECT_NAMESPACE\u003c/var\u003e with the namespace of your project."]]