Skip to content

Modify



POST /api/v1/aggs_to_metric/{rule_uuid}/modify

Overview

Modify the query, frequency, delay, and display configuration of a Generate Metrics rule.

Prerequisites and Usage Steps

Read the details first, backfill the complete jsonScript and extend, and then modify; you cannot change jsonScript.type, metricInfo.metric, or metricInfo.metricField. If you need to change the output name or type, evaluate creating a new rule and disabling the old one. Modifications are passed as a full replacement: omitting unit/desc clears the display metadata, and omitting delaySeconds restores 0; fields that exist only in the old extend are not retained.

Each workspace checks the output metric+metricField across all non-deleted aggs rules, including disabled rules. When duplicates exist and skipRepeatNameCheck=false, nothing is saved or modified, yet HTTP 200 with success=true is still returned, along with top-level code=409, content.metricRepeat=true, and an English content.message; be sure to check code and metricRepeat rather than judging only by HTTP status or success. skipRepeatNameCheck=true only skips this check; it does not prove that identically named outputs will not affect each other.

When Distribution mode is selected, extend.funcName=distribution is required, and q uses histogram_auto(actual numeric field). Field values, grouping, and filtering are all actually determined by q; extend does not automatically rewrite q. unit only labels the display unit; numeric conversion must be explicitly handled in the query or on the collection side.

Saving configures the periodic schedule and syncs the metric unit/description; it does not execute the configured aggregation q or produce new metric data, and this modification does not repeat the source field schema type check performed at creation; when subsequent tasks run, whether they succeed, and whether metrics are written must be verified in the task/metric queries. The scheduling service and the database/metric metadata are processed in separate steps, so an error or timeout may already have applied partial updates; read the rule and the target metric before retrying. This feature is not available to Free Plan workspaces.

Modification also resets existing custom operation permissions to openPermissionSet=false and permissionSet=[], so verify the historical permission configuration first.

These entry points share common rule handling, and some target queries have no additional type=aggs restriction; use only the UUIDs returned by this module's list to avoid reading or changing other rules.

Path Parameters

Parameter Type Required Description
rule_uuid string Y Path rule UUID, not a metric name, measurement name, or schedule id; do not pass the rul_ UUID of a regular monitor.
Example: rul_aggs_example
How to obtain or fill in: Obtain the aggs rule in this workspace only from the uuid in content.data[].uuid of the Generate Metrics rule list.

Request Headers

Parameter Type Required Description
DF-API-KEY string Y OpenAPI authentication credential for the workspace.
Example: <DF-API-KEY>
How to obtain or fill in: Obtain an OpenAPI Key with this operation permission from the API Key management of the target workspace.

Body Parameters

Parameter Type Required Description
jsonScript.query.q string Required string within the query object. A complete q must be provided even in selector mode; do not put credentials in it. The Distribution example uses histogram_auto(field), not distribution(field).
Example: L('default')::`nginx`:(count(`*`)) BY `host`
How to obtain or fill in: Build the aggregation query according to the actual DQL or PromQL syntax, using real log indexes, sources, and fields.
jsonScript.query.qtype string Optional query syntax; when omitted, dql is used by default; when specified explicitly, only dql/promql are allowed, and an empty string or null cannot be passed. It is recommended to always set it explicitly. PromQL is executed as an instant query; rangeQuery is not set through this object.
Example: dql
How to obtain or fill in: Enter dql for DQL and promql for PromQL.
jsonScript.query.qmode string Optional but recommended. selectorQuery requires extend.fieldKey/funcName; customQuery does not require these echo fields. When omitted, the controller does not trigger selector-mode structure validation, but the plugin may still validate functions according to selector mode, so omission cannot be used to bypass validation.
Example: selectorQuery
How to obtain or fill in: Use selectorQuery for console selector mode and customQuery for hand-written queries.
extend.funcName string Conditionally required aggregation function name for selectorQuery. count counts, count_distinct counts distinct values; numeric aggregation functions require a real numeric field; distribution echoes the histogram_auto in the corresponding q.
Example: count
How to obtain or fill in: Select count/avg/max/sum/min/count_distinct/distribution/p75/p95/p99.
extend.fieldKey string Conditionally required aggregation field echo for selectorQuery. Creation queries the source field type to check compatibility with numeric functions, but unknown fields are not guaranteed to be rejected; modification does not repeat the same field type check.
Example: *
How to obtain or fill in: Take the actual key from the raw data fields; counting may use * according to q.
extend.source string Optional source echo; * indicates all available sources, and the actual scope is still limited by q. When querying the RUM list, sourceInfo can be appended based on this value.
Example: nginx
How to obtain or fill in: Use source for logs, service for APM, app_id for RUM, measurement for metrics, category for security, and the actual synthetic test data source for synthetic tests.
extend.index string Optional log index echo; changing it does not automatically change the L index in q.
Example: default
How to obtain or fill in: Obtain it from the log index configuration of the current workspace; the default index is generally default.
extend.groupBy array Optional grouping echo array; when omitted, this echo field is absent; an empty array means no grouping. The actual grouping is determined by q.
Example: ["host"]
How to obtain or fill in: Select real fields from the BY grouping in q or the PromQL label aggregation.
extend.groupBy[*] string A single grouping key.
Example: host
How to obtain or fill in: Use the raw field name or label name.
extend.filterString string Optional log filter echo string; it is not an automatic entry point for concatenating q, and actual filtering must be written into q.
Example: env:production
How to obtain or fill in: In log selector mode, copy the raw FilterString from the console filter.
extend.filters array Optional array; uses the plural values, unlike the value field in other APIs. Actual filter execution is determined by q.
Example: [{"name": "env", "condition": "and", "op": "=", "values": ["production"]}]
How to obtain or fill in: Filter echo used by non-log selectors.
extend.filters[*] json Filter echo object; it can recursively retain the client's existing format; the current echo structure is not converted into an executable query.
Example: {"name": "env", "condition": "and", "op": "=", "values": ["production"]}
How to obtain or fill in: Retain one selector condition per item.
extend.filters[*].name string Echo field.
Example: env
How to obtain or fill in: Real source field name.
extend.filters[*].condition string Relationship with the previous echo condition.
Example: and
How to obtain or fill in: Use and/or; when omitted, the display convention is and.
extend.filters[*].op string Echo operator; query condition conversion is not performed in this API.
Example: =
How to obtain or fill in: Use =, !=, match, or not match according to the client selector.
extend.filters[*].values array Echo value array; both the actual comparison and the values taken must be reflected in q.
Example: ["production"]
How to obtain or fill in: Use raw field values and preserve the string/number/boolean type.
extend.filters[*].values[*] JSON A single string, number, or boolean value.
Example: production
How to obtain or fill in: Take a single field value from the source data.
extend json Y Required echo object; modification replaces it entirely. None of the echo options replaces jsonScript.query; when hand-written mode does not need an echo, {} can be given.
Null allowed: False
Example: {"funcName": "count", "fieldKey": "*", "source": "nginx", "index": "default", "groupBy": ["host"], "filters": [], "filterString": ""}
How to obtain or fill in: Used for client editor echo, and must be consistent with the selections already written into q.
jsonScript json Y Required rule object; modification replaces it entirely and does not merge fields. Submit only the subfields listed on this page; do not return the entire entity returned by the details.
Null allowed: False
Example: {"type": "logToMetric", "query": {"q": "L('default')::`nginx`:(count(`*`)) BY `host`", "qtype": "dql", "qmode": "selectorQuery"}, "metricInfo": {"every": "5m", "metric": "recording_rules", "metricField": "nginx_requests"}}
How to obtain or fill in: Build it according to the raw data category, query statement, and output metric definition; for modification, first read the complete object from the details.
jsonScript.type string Y Required data category; the public declaration accepts only these six; internal object plugins do not mean they are publicly supported by the current OpenAPI. Modification cannot change the category.
Null allowed: False
Empty string allowed: False
Allowed values: ['logToMetric', 'rumToMetric', 'apmToMetric', 'metricToMetric', 'securityToMetric', 'dialingToMetric']
Example: logToMetric
How to obtain or fill in: Logs use logToMetric, RUM uses rumToMetric, APM uses apmToMetric, metrics use metricToMetric, security uses securityToMetric, and synthetic tests use dialingToMetric.
jsonScript.query json Y Required query object; actual execution is determined by q, and the query is not automatically generated or corrected from extend fields. A successful save does not guarantee that the query syntax, data availability, or generated results meet expectations.
Null allowed: False
Example: {"q": "L('default')::`nginx`:(count(`*`)) BY `host`", "qtype": "dql", "qmode": "selectorQuery"}
How to obtain or fill in: First verify the real data, aggregation results, and grouping fields with the query tool in the same workspace.
jsonScript.metricInfo json Y Required output and scheduling object. Modification backfills it entirely; metric/metricField cannot be changed; unit and description can be changed, and omitting them syncs them as empty strings.
Null allowed: False
Example: {"every": "5m", "metric": "recording_rules", "metricField": "nginx_requests", "unit": "custom/[\"custom\",\"次\"]", "desc": "按host统计nginx请求数。", "delaySeconds": 60}
How to obtain or fill in: The output metric is defined by the business side; first check for duplicates from the existing Generate Metrics rules.
jsonScript.metricInfo.every string Y Required frequency, with no leading zeros; 60m, 0m, seconds, days, or Cron expressions are not supported. It is used for the scheduling frequency and the query window length, not as a delay time.
Empty string allowed: False
Example: 5m
How to obtain or fill in: Select 1m to 59m or 1h to 24h according to the generation frequency, with m/h in lowercase.
jsonScript.metricInfo.metric string Y Required measurement name; only English letters, digits, and underscores, and it cannot contain hyphens, spaces, or Chinese characters. Modification is not allowed to change it.
Empty string allowed: False
Example: recording_rules
How to obtain or fill in: Define the custom output measurement name; confirm the name from Metrics Management or the Generate Metrics list.
jsonScript.metricInfo.metricField string Y Required metric name; the naming character restrictions are the same as metric. Modification is not allowed to change it; do not reuse the 001-test from historical examples.
Empty string allowed: False
Example: nginx_requests
How to obtain or fill in: Define the output metric name under the measurement; check the same metric+metricField from the rule list.
jsonScript.metricInfo.unit string Optional display unit string; omitting it or an empty string clears it; the numeric value of q is not automatically converted according to the unit, so you must ensure that the query result matches the unit.
Empty string allowed: True
Example: custom/["custom","次"]
How to obtain or fill in: See Unit description; the standard format is custom/["time","ms"] and the custom format is custom/["custom","unit"].
jsonScript.metricInfo.desc string Optional metric description; omitting it or an empty string syncs it as empty; it is not the rule name.
Empty string allowed: True
Example: 按host统计nginx请求数。
How to obtain or fill in: Describe the meaning of the output metric, the aggregation logic, and the unit description.
jsonScript.metricInfo.delaySeconds integer Optional wait seconds, defaulting to 0 (no delay). After a scheduled trigger, wait for the source data to be complete; it does not change the query window corresponding to every; if this field is not provided, it is restored to 0 after modification. Must be a JSON integer; booleans or the string "60" are not accepted.
Allowed values: [0, 60, 120, 180, 300, 600, 900, 1200, 1800]
Example: 60
How to obtain or fill in: Choose only from 0/60/120/180/300/600/900/1200/1800.
skipRepeatNameCheck boolean Optional, default false; true skips the metric+metricField duplicate check for non-deleted Generate Metrics rules in the same workspace, but it does not mean the output data will not conflict, and it does not bypass naming/structure/scheduling validation.
Null allowed: False
Example: false
How to obtain or fill in: First check the same output measurement+metric name via the Generate Metrics rule list; usually false.

Additional Parameter Notes

For units, see Unit description. The raw extend and the actual query must remain consistent; the generation frequency uses every, and Cron expressions are not submitted.

Request Example

curl --request POST 'https://openapi.guance.com/api/v1/aggs_to_metric/rul_aggs_example/modify' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"jsonScript":{"type":"logToMetric","query":{"q":"L('"'"'default'"'"')::`nginx`:(count(`*`)) BY `host`","qtype":"dql","qmode":"selectorQuery"},"metricInfo":{"every":"5m","metric":"recording_rules","metricField":"nginx_requests","unit":"custom/[\"custom\",\"次\"]","desc":"按host统计nginx请求数。","delaySeconds":60}},"extend":{"funcName":"count","fieldKey":"*","source":"nginx","index":"default","groupBy":["host"],"filters":[],"filterString":""},"skipRepeatNameCheck":false}'

Response

HTTP 200 with the application/json unified envelope; on success, code=200 returns the rule; for a duplicate output, code=409 still has success=true, so you must check content.metricRepeat.

Field Type Description
content.id integer Database ID of the saved Generate Metrics rule; use uuid for subsequent calls.
content.uuid string rul_ rule UUID.
content.workspaceUUID string Workspace it belongs to.
content.monitorUUID string Associated monitor UUID; usually an empty string for this module.
content.type string Entity type, fixed as aggs, distinct from jsonScript.type.
content.refKey string Association key, usually empty.
content.secret string Compatibility entity field, usually empty for ordinary Generate Metrics rules; do not use it as a call credential or record the actual value.
content.createdWay string manual/import/template or a historical empty value.
content.isLocked integer or boolean Lock flag, usually 0/false.
content.openPermissionSet boolean Custom operation permission switch, usually false for rules created by this module.
content.permissionSet array<string> Custom operation subject array, usually [].
content.permissionSet[] string A single account/team/role identifier.
content.status integer 0 enabled, 2 disabled, 3 deleted; the status does not equal the success of the most recent task execution.
content.creator string Creating identity.
content.updator string Most recent updating identity; may be empty initially.
content.createAt integer Creation Unix seconds.
content.updateAt integer Update Unix seconds; -1 if never updated.
content.deleteAt integer Deletion Unix seconds; -1 if not deleted.
content.crontabInfo object Scheduling configuration summary, not a task execution result.
content.crontabInfo.id string Scheduling configuration identifier, maintained by the system; use uuid to operate on the rule.
content.crontabInfo.crontab string Actual six-field scheduling expression, for example 0 */5 * * * *; the request frequency still uses metricInfo.every.
content.jsonScript object Saved configuration: required rule object; modification replaces it entirely and does not merge fields. Submit only the subfields listed on this page; do not return the entire entity returned by the details.
content.jsonScript.type string Saved configuration: required data category; the public declaration accepts only these six; internal object plugins do not mean they are publicly supported by the current OpenAPI. Modification cannot change the category.
content.jsonScript.query json Saved configuration: required query object; actual execution is determined by q, and the query is not automatically generated or corrected from extend fields. A successful save does not guarantee that the query syntax, data availability, or generated results meet expectations.
content.jsonScript.query.q string Saved configuration: required string within the query object. A complete q must be provided even in selector mode; do not put credentials in it. The Distribution example uses histogram_auto(field), not distribution(field).
content.jsonScript.query.qtype string Saved configuration: optional query syntax; when omitted, dql is used by default; when specified explicitly, only dql/promql are allowed, and an empty string or null cannot be passed. It is recommended to always set it explicitly. PromQL is executed as an instant query; rangeQuery is not set through this object.
content.jsonScript.query.qmode string Saved configuration: optional but recommended. selectorQuery requires extend.fieldKey/funcName; customQuery does not require these echo fields. When omitted, the controller does not trigger selector-mode structure validation, but the plugin may still validate functions according to selector mode, so omission cannot be used to bypass validation.
content.jsonScript.metricInfo json Saved configuration: required output and scheduling object. Modification backfills it entirely; metric/metricField cannot be changed; unit and description can be changed, and omitting them syncs them as empty strings.
content.jsonScript.metricInfo.every string Saved configuration: required frequency, with no leading zeros; 60m, 0m, seconds, days, or Cron expressions are not supported. It is used for the scheduling frequency and the query window length, not as a delay time.
content.jsonScript.metricInfo.metric string Saved configuration: required measurement name; only English letters, digits, and underscores, and it cannot contain hyphens, spaces, or Chinese characters. Modification is not allowed to change it.
content.jsonScript.metricInfo.metricField string Saved configuration: required metric name; the naming character restrictions are the same as metric. Modification is not allowed to change it; do not reuse the 001-test from historical examples.
content.jsonScript.metricInfo.unit string Saved configuration: optional display unit string; omitting it or an empty string clears it; the numeric value of q is not automatically converted according to the unit, so you must ensure that the query result matches the unit.
content.jsonScript.metricInfo.desc string Saved configuration: optional metric description; omitting it or an empty string syncs it as empty; it is not the rule name.
content.jsonScript.metricInfo.delaySeconds integer Saved configuration: optional wait seconds, defaulting to 0 (no delay). After a scheduled trigger, wait for the source data to be complete; it does not change the query window corresponding to every; if this field is not provided, it is restored to 0 after modification. Must be a JSON integer; booleans or the string "60" are not accepted.
content.extend object Saved configuration: required echo object; modification replaces it entirely. None of the echo options replaces jsonScript.query; when hand-written mode does not need an echo, {} can be given.
content.extend.funcName string Saved configuration: conditionally required aggregation function name for selectorQuery. count counts, count_distinct counts distinct values; numeric aggregation functions require a real numeric field; distribution echoes the histogram_auto in the corresponding q.
content.extend.fieldKey string Saved configuration: conditionally required aggregation field echo for selectorQuery. Creation queries the source field type to check compatibility with numeric functions, but unknown fields are not guaranteed to be rejected; modification does not repeat the same field type check.
content.extend.source string Saved configuration: optional source echo; * indicates all available sources, and the actual scope is still limited by q. When querying the RUM list, sourceInfo can be appended based on this value.
content.extend.index string Saved configuration: optional log index echo; changing it does not automatically change the L index in q.
content.extend.groupBy array Saved configuration: optional grouping echo array; when omitted, this echo field is absent; an empty array means no grouping. The actual grouping is determined by q.
content.extend.groupBy[] string Saved configuration: a single grouping key.
content.extend.filterString string Saved configuration: optional log filter echo string; it is not an automatic entry point for concatenating q, and actual filtering must be written into q.
content.extend.filters array Saved configuration: optional array; uses the plural values, unlike the value field in other APIs. Actual filter execution is determined by q.
content.extend.filters[] json Saved configuration: filter echo object; it can recursively retain the client's existing format; the current echo structure is not converted into an executable query.
content.extend.filters[].name string Saved configuration: echo field.
content.extend.filters[].condition string Saved configuration: relationship with the previous echo condition.
content.extend.filters[].op string Saved configuration: echo operator; query condition conversion is not performed in this API.
content.extend.filters[].values array Saved configuration: echo value array; both the actual comparison and the values taken must be reflected in q.
content.extend.filters[].values[] JSON Saved configuration: a single string, number, or boolean value.
content.declaration object or null Workspace public declaration attached to a non-empty business object; it may be null or an empty object when not configured; an empty object is not added.
content.metricRepeat boolean true appears only in the duplicate branch, replacing the normal rule entity.
content.message string A prompt appears only in the duplicate branch; for the English value, see the example.
code integer 200 on success; the duplicate branch returns 409 but HTTP is still 200 and success is still true.
{
  "code": 200,
  "content": {
    "id": 101,
    "uuid": "rul_aggs_example",
    "workspaceUUID": "wksp_example",
    "monitorUUID": "",
    "type": "aggs",
    "refKey": "",
    "secret": "",
    "jsonScript": {
      "type": "logToMetric",
      "query": {
        "q": "L('default')::`nginx`:(count(`*`)) BY `host`",
        "qtype": "dql",
        "qmode": "selectorQuery"
      },
      "metricInfo": {
        "every": "5m",
        "metric": "recording_rules",
        "metricField": "nginx_requests",
        "unit": "custom/[\"custom\",\"次\"]",
        "desc": "按host统计nginx请求数。",
        "delaySeconds": 60
      }
    },
    "extend": {
      "funcName": "count",
      "fieldKey": "*",
      "source": "nginx",
      "index": "default",
      "groupBy": [
        "host"
      ],
      "filters": [],
      "filterString": ""
    },
    "crontabInfo": {
      "id": "cron_example",
      "crontab": "0 */5 * * * *"
    },
    "createdWay": "manual",
    "isLocked": 0,
    "openPermissionSet": false,
    "permissionSet": [],
    "status": 0,
    "creator": "wsak_example",
    "updator": "wsak_example",
    "createAt": 1785427200,
    "updateAt": 1785427300,
    "deleteAt": -1,
    "declaration": {}
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Duplicate output name, HTTP 200:

{
  "code": 409,
  "content": {
    "message": "Data duplication cannot be modified",
    "metricRepeat": true,
    "declaration": {}
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed Request field missing, or a field value violates the declared validation conditions Parameter parsing failed Check the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError Request JSON syntax is invalid Request JSON format error Fix the JSON according to content.reason, line, and column.
400 ft.JsonFormatError JSON top level is not an object Some json file format error Submit a JSON object as shown in the example.
403 ft.InvalidMetricsName The measurement or metric name does not conform to the alphanumeric-underscore format Metric names can contain only letters, digits, and underscores Fix metric/metricField; do not use the hyphen from the historical example.
400 ft.ParamsValidateError query/metricInfo structure, unknown jsonScript fields, frequency or delay values failing business validation, or selector mode missing fieldKey/funcName Parameter validation failed: {} Check the field path in the message; use only the allowed values on this page for frequency and delay, and explicitly provide qmode and qtype.
400 ft.OuterFuncFailed The scheduling service returned an explicit failure External function call failed Verify existing rules and schedules, then retry; if the failure persists, provide the traceId.
400 ft.SameSetTraggerExists The scheduling service found an identical configuration A trigger with the same configuration already exists Check existing rules and tasks first to avoid duplicate scheduling.
500 ft.InternalServerError Downstream timeout/generic 5xx, database, or subsequent metadata processing failure Internal error Read the rule and its status, output metrics, and current schedule state before deciding to retry; provide the traceId.
404 ft.NotFoundRuleInspector The target rule does not exist/is deleted/is in another workspace The specified rule/inspector was not found Obtain the UUID again from this module's list.
400 ft.NotSupportModifyAggsToMetricRuleType The request type differs from the existing rule's jsonScript.type Modifying the Generate Metrics rule type is not supported Backfill the original type; if another category is needed, create a new rule.
400 ft.NotSupportModifyAggsToMetricRuleMetricField metric or metricField differs from the original rule Modifying the Generate Metrics measurement/metric information is not supported Keep the original output name; if a rename is needed, evaluate creating a new rule and disabling the old one.
403 ft.Forbidden The API Key has insufficient permissions or the workspace plan does not support this feature You do not have permission to perform this operation Use an API Key with the required permissions and a workspace that supports Generate Metrics.

Feedback

Is this page helpful?