您可以在使用 Eventarc Google Cloud 控制台页面或通过运行 gcloud 命令来创建触发器时应用路径模式来过滤事件。
例如,在过滤资源名称或数据库实例(单个实例或路径)时,可以应用路径模式。
为 Cloud Audit Logs 事件和 resourceName 值创建触发器时,可以指定资源名称路径模式。资源名称表示通过审核日志进行审核的资源。资源名称使用标识符按层级进行排列,标识符由资源本身的 ID 和任何父资源的 ID 组成,所有 ID 使用正斜杠分隔,例如:/projects/project-1/datasets/dataset-id。Eventarc 所执行的过滤会根据这些标识符的值来匹配模式。如需了解详情,请参阅本文档中的资源名称格式。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eEventarc allows for the application of path patterns when filtering events, enabling users to create triggers that are granular or broad in scope, according to the specific events or resources they need to monitor.\u003c/p\u003e\n"],["\u003cp\u003ePath patterns can be applied to filter on resource names for Cloud Audit Logs events, database instances for Firebase Realtime Database events, or registry/device values for Cloud IoT events.\u003c/p\u003e\n"],["\u003cp\u003eYou can determine if an event provider supports path patterns by using the \u003ccode\u003egcloud eventarc providers describe\u003c/code\u003e command, which will indicate if \u003ccode\u003epathPatternSupported\u003c/code\u003e is \u003ccode\u003etrue\u003c/code\u003e in the output for a given attribute.\u003c/p\u003e\n"],["\u003cp\u003eThe path pattern syntax supports wildcards (\u003ccode\u003e*\u003c/code\u003e, \u003ccode\u003e**\u003c/code\u003e), capture groups (\u003ccode\u003e{ID}\u003c/code\u003e), and name segments to match parts of resource names or paths, with specific rules and limitations for each.\u003c/p\u003e\n"],["\u003cp\u003eResource names follow a hierarchical format, and pattern matching is constrained by resource regionality, meaning that wildcards will only match within the specific region or global scope of a resource.\u003c/p\u003e\n"]]],[],null,["# Understand path patterns\n\n[Standard](/eventarc/standard/docs/overview)\n|\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nEventarc supports applying a path pattern when filtering. The path\npattern syntax lets you define an expression that matches events. This lets\nyou control the granularity of the Eventarc trigger you are\ncreating, and to capture and act on certain events. For example, you can create\na trigger that applies to a single event, such as a change to a specific file,\nor you can extend the scope of the pattern and create a trigger that applies\nmore broadly.\n\nApply a path pattern\n--------------------\n\nYou can apply a path pattern to filter events when you create a trigger\nusing the Eventarc Google Cloud console page or by running\na `gcloud` command.\n\nFor example, you can apply a path pattern when filtering on *resource names* or\n*database instances* (a single instance or a path).\n\n- Specifying a **resource name path pattern** applies when creating a trigger\n for **Cloud Audit Logs events** and to `resourceName` values. A resource\n name indicates the resource being audited through an audit log.\n Resource names are organized hierarchically using identifiers made up of the\n ID of the resource itself and the IDs of any parent resources, all separated by\n forward slashes, like this: `/projects/project-1/datasets/dataset-id`.\n The filtering done by Eventarc matches patterns based on the\n values of these identifiers. For more information, in this document, see\n [Resource name format](#resource-name-format).\n\n- Specifying a **database instance path pattern** applies when creating a\n trigger for **Firebase Realtime Database events** and to `instance` or `ref`\n values. A database instance indicates a Firebase Realtime Database\n instance. You can apply a path pattern to the instance name of the database\n instance, or a document path for which you want to receive events when data is\n created, updated, or deleted in that path, or any of its children.\n\n- Specifying a **resource ID path pattern** applies when creating a trigger\n for **Cloud IoT events** and to `registry` and `device` values.\n You can apply a path pattern to filter changes in registries, and devices in a\n registry, with wildcard matching.\n\nFor details, see the instructions to\n[create a trigger for a specific provider, event type, and destination](/eventarc/standard/docs/event-providers-targets#triggers).\n\nIdentify if you can apply a path pattern\n----------------------------------------\n\nTo confirm if you can apply a path pattern to an attribute of an event from a\nprovider, describe the event provider. For example: \n\n```bash\ngcloud eventarc providers describe cloudaudit.googleapis.com --location=us-central1\n```\n\nThe output is similar to the following and a `pathPatternSupported` value of\n`true` indicates that you can apply a path pattern: \n\n```bash\ndisplayName: Cloud Audit Logs\neventTypes:\n- description: An audit log is created that matches the trigger's filter criteria.\n filteringAttributes:\n - attribute: methodName\n description: The identifier of the service's operation.\n required: true\n - attribute: resourceName\n description: The complete path to a resource. Used to filter events for a specific\n resource.\n pathPatternSupported: true\n - attribute: serviceName\n description: The identifier of the Google Cloud service.\n required: true\n - attribute: type\n required: true\n type: google.cloud.audit.log.v1.written\nname: projects/project-name/locations/us-central1/providers/cloudaudit.googleapis.com\n```\n\nOr, for example: \n\n```bash\ngcloud eventarc providers describe firebasedatabase.googleapis.com --location=us-central1\n```\n\nWhere the output is similar to the following: \n\n```bash\ndisplayName: Firebase Realtime Database\neventTypes:\n- description: New data has been created in the database.\n filteringAttributes:\n - attribute: instance\n description: A single database instance.\n pathPatternSupported: true\n required: true\n - attribute: ref\n description: Pattern to match for the database instance.\n pathPatternSupported: true\n required: true\n - attribute: type\n required: true\n type: google.firebase.database.ref.v1.created\n[...]\n```\n\nFor more information, see\n[`gcloud eventarc providers describe`](/sdk/gcloud/reference/eventarc/providers/describe).\n\nPath pattern syntax\n-------------------\n\nThe path pattern syntax is defined as follows:\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### Legend:\n\n^**1**^ Only listed ASCII characters are supported. Regular expression matching is not supported. Supported metacharacters:\n\n- `\\w` refers to a word; also represented as `[a-zA-Z0-9_]`\n- `\\t` refers to a tab\n- `\\s` refers to a whitespace character\n\n### Expressions\n\nAn expression can be one of the following segment types and cannot be empty:\n\n- A single segment `Wildcard` defined as `*` matches zero or more characters in the pattern.\n- A `MultiSegmentWildcard` defined as `**` matches zero or more segments in the pattern.\n- A `NameSegment`consists of zero or one `*` and other characters. This combination lets you filter by prefix, suffix, or file extension; for example, `file-*.txt`.\n\nNote that a path can contain many single segment wildcards, but only\none multiple segment wildcard. For example, the following path is invalid:\n`/projects/**/buckets/**`.\n\n### Resource regionality\n\nResource names can contain location identifiers. For example:\n\n`/projects/$PROJECT_ID/`**locations/$REGION**`/triggers/my-trigger`\n\nHowever, path pattern matching is constrained by resource regionality. For\nexample, for Cloud Audit Logs triggers, location wildcards only match\ntriggers from the Cloud Audit Logs region, or global triggers.\n\n### Capture groups\n\nA `CaptureGroup` lets you capture the content of an expression. You do this\nby assigning the value to a variable name in braces; for example,\n`buckets/{path=**}/files/{filename=file-*.txt}`. A single segment wildcard can\nomit `=*` in a capture group; for example,\n`/projects/_/buckets/{bucket}/objects/file.*`\n| **Note:** Capture groups have no semantic meaning; only the syntax is supported.\n\nResource name format\n--------------------\n\nThe following table provides examples of full resource names for commonly used\nGoogle Cloud services. **It is not a complete list.** To learn more about how\nfull resource names are formatted, see the\n[Resource names](/apis/design/resource_names) section of the API design guide.\n\n^1^ For Cloud Firestore, don't specify a leading slash\nwhen creating a trigger\n(see [examples](/eventarc/standard/docs/run/route-trigger-cloud-firestore#create-trigger)).\nFor more information, see\n[Cloud Firestore data model](https://firebase.google.com/docs/firestore/data-model).\n\n^2^ For Cloud Storage, resource names contain an\nunderscore (`_`) rather than a project ID. You *cannot* replace the underscore\nwith a project ID, project name, or project number.\n\n^3^ For Cloud Storage, use the entire object name, including\nforward slashes. These characters are\n[part of the object name](/storage/docs/objects#naming), not path separators.\n\nExamples\n--------\n\nThe following examples demonstrate how you can and can't use the syntax.\n\n### Valid patterns\n\n### Invalid patterns\n\n### Pattern matching\n\nWhat's next\n-----------\n\n- For a list of the events supported by Eventarc, see [Google event types supported by Eventarc](/eventarc/docs/reference/supported-events)."]]