이 페이지에서는 Google Distributed Cloud (GDC) 에어 갭 어플라이언스에 LoggingRule 커스텀 리소스를 배포하여 기존 로그에서 새 측정항목을 생성하는 방법을 설명합니다.
기록 규칙을 사용하면 자주 사용되거나 계산 비용이 많이 드는 표현식을 미리 계산하여 대시보드와 알림의 성능을 개선할 수 있습니다. LoggingRule 맞춤 리소스 내에 정의된 이러한 규칙은 기존 로그에서 새로운 시계열 측정항목을 생성하여 데이터 관측 가능성을 향상합니다.
사전 계산된 결과를 저장함으로써 기록 규칙은 표현식이 필요할 때마다 중복 계산을 제거합니다. 이 메서드는 특히 동일한 표현식을 반복적으로 평가해야 하는 복잡한 대시보드와 알림의 경우 쿼리 시간을 크게 단축합니다. 기본적으로 LoggingRule 리소스를 사용하면 기록 규칙 내에서 필요한 계산을 지정하여 기존 로깅 데이터에서 새 측정항목을 파생할 수 있습니다.
시작하기 전에
LoggingRule 커스텀 리소스를 관리하는 데 필요한 권한을 얻으려면 조직 IAM 관리자 또는 프로젝트 IAM 관리자에게 연결된 LoggingRule 역할 중 하나를 부여해 달라고 요청하세요.
필요한 액세스 수준과 권한에 따라 조직 또는 프로젝트에서 이 리소스에 대한 생성자, 편집자 또는 뷰어 역할을 획득할 수 있습니다. 자세한 내용은 IAM 권한 준비를 참고하세요.
녹화 규칙 만들기
기록 규칙을 만들려면 기록된 로그의 이름과 숫자 값을 생성하는 유효한 표현식을 정의합니다. 이 표현식은 평가될 때 새 측정항목을 생성합니다. 관리 API 서버의 프로젝트 네임스페이스에 LoggingRule 커스텀 리소스를 배포하여 녹화 규칙을 활성화합니다.
LoggingRule 커스텀 리소스에는 관측 가능성을 위해 기존 로그를 기반으로 새 측정항목을 만드는 조건을 설명하는 기록 규칙이 포함되어 있습니다.
다음 YAML 파일은 LoggingRule 맞춤 리소스의 템플릿을 보여줍니다. 자세한 내용은 API 참조 문서를 참고하세요.
# Configures either an alert or a target record for precomputation.apiVersion:logging.gdc.goog/v1kind:LoggingRulemetadata:# Choose a namespace that matches the project namespace.# The alert or record is produced in the same namespace.namespace:PROJECT_NAMESPACEname:LOGGING_RULE_NAMEspec:# Choose the log source to base alerts on (operational or audit logs).# Optional.# Valid options: 'operational' and 'audit'# Default value: 'operational'source:operational# Rule evaluation interval.interval:60s# Configure the limit for the number of alerts.# A value of '0' means no limit.# Optional.# Default value: '0'limit:0# Configure recording rules to generate new metrics based on existing logs.# Recording rules precompute expressions that are frequently needed or computationally expensive.# Results are saved as a new set of time series.recordRules:# Define the time series where you want to write the recording rule.# The value must be a valid metric name.-record:MyMetricsName# Define the LogQL expression to evaluate for this rule.expr:rate({service_name="bob-service"} [1m])# Define labels to add or overwrite.# Map of key-value pairs.# Optional.labels:verb:read
[[["이해하기 쉬움","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)"],[],[],null,["# Create metrics from logs\n\nThis page describes how to generate new metrics from existing logs by deploying\na `LoggingRule` custom resource in Google Distributed Cloud (GDC) air-gapped appliance.\n\nRecording rules allow you to precompute frequently used or computationally\nexpensive expressions, improving performance for dashboards and alerts. Defined\nwithin `LoggingRule` custom resources, these rules generate new time series\nmetrics from existing logs, enhancing data observability.\n\nBy storing precomputed results, recording rules eliminate redundant calculations\neach time an expression is needed. This method significantly speeds up query\ntimes, particularly for complex dashboards and alerts that require repeated\nevaluations of the same expression. Essentially, `LoggingRule` resources let you\nderive new metrics from existing logging data by specifying the necessary\ncalculations within their recording rules.\n\nBefore you begin\n----------------\n\nTo get the permissions that you need to manage `LoggingRule` custom\nresources, ask your Organization IAM Admin or Project IAM Admin to grant you one\nof the associated `LoggingRule` roles.\n\nDepending on the level of access and permissions you need, you might obtain\ncreator, editor, or viewer roles for this resource in an organization or a\nproject. For more information, see [Prepare IAM permissions](/distributed-cloud/hosted/docs/latest/appliance/platform/pa-user/obs-iam-permissions).\n\nCreate recording rules\n----------------------\n\nTo create a recording rule, define a name for the recorded log and a valid\nexpression that produces a numeric value. This expression, when evaluated,\ngenerates the new metric. Deploy the `LoggingRule` custom resource in your\nproject namespace on the Management API server to activate the recording rule.\n\nFor more information about recording rules, see\n\u003chttps://grafana.com/docs/loki/latest/rules/\u003e.\n| **Important:** Before creating recording rules, ensure you have a deployed project with active workloads and configured logging targets. In this way, the rules have data to operate on. For more information, see [Collect logs](/distributed-cloud/hosted/docs/latest/appliance/platform/pa-user/collect-logs).\n\nFollow these steps to create recording rules in your project namespace:\n\n1. Determine the GDC project from which you want to create recording rules.\n2. Create a YAML file defining the `LoggingRule` custom resource.\n\n [The complete `LoggingRule` specification](#loggingrule-recording-rules)\n shows an example for log-based recording rules. For more information, see\n the [API reference documentation](/distributed-cloud/hosted/docs/latest/appliance/apis/service/logging/v1/logging-v1#loggingrule).\n3. Replace the following values in the YAML file according to your needs:\n\n4. Save the YAML file.\n\n5. Apply the `LoggingRule` configuration to the Management API server within\n the same namespace as your recording rules:\n\n kubectl --kubeconfig \u003cvar translate=\"no\"\u003eKUBECONFIG_PATH\u003c/var\u003e apply -f \u003cvar translate=\"no\"\u003eLOGGING_RULE_NAME\u003c/var\u003e.yaml\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eKUBECONFIG_PATH\u003c/var\u003e: the path to the kubeconfig file for the Management API server.\n - \u003cvar translate=\"no\"\u003eLOGGING_RULE_NAME\u003c/var\u003e: the name of the `LoggingRule` definition file.\n\nComplete `LoggingRule` specification\n------------------------------------\n\nA `LoggingRule` custom resource contains recording rules that describe the\nconditions to create new metrics based on existing logs for observability.\n\nThe following YAML file shows a template for the `LoggingRule` custom\nresource. For more information, see the\n[API reference documentation](/distributed-cloud/hosted/docs/latest/appliance/apis/service/logging/v1/logging-v1#loggingrule). \n\n # Configures either an alert or a target record for precomputation.\n apiVersion: logging.gdc.goog/v1\n kind: LoggingRule\n metadata:\n # Choose a namespace that matches the project namespace.\n # The alert or record is 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: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eLOGGING_RULE_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n # Choose the log source to base alerts on (operational or audit logs).\n # Optional.\n # Valid options: 'operational' and 'audit'\n # Default value: 'operational'\n source: operational\n\n # Rule evaluation interval.\n interval: 60s\n\n # Configure the limit for the number of alerts.\n # A value of '0' means no limit.\n # Optional.\n # Default value: '0'\n limit: 0\n\n # Configure recording rules to generate new metrics based on existing logs.\n # Recording rules precompute expressions that are frequently needed or computationally expensive.\n # Results are saved as a new set of time series.\n recordRules:\n # Define the time series where you want to write the recording rule.\n # The value must be a valid metric name.\n - record: MyMetricsName\n\n # Define the LogQL expression to evaluate for this rule.\n expr: rate({service_name=\"bob-service\"} [1m])\n\n # Define labels to add or overwrite.\n # Map of key-value pairs.\n # Optional.\n labels:\n verb: read\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NAMESPACE\u003c/var\u003e: your project namespace.\n- \u003cvar translate=\"no\"\u003eLOGGING_RULE_NAME\u003c/var\u003e: the name of the `LoggingRule` definition file."]]