使用 Eventarc Google Cloud 控制台頁面建立觸發條件,或執行 gcloud 指令時,可以套用路徑模式來篩選事件。
舉例來說,篩選資源名稱或資料庫執行個體 (單一執行個體或路徑) 時,可以套用路徑模式。
建立 Cloud 稽核記錄事件的觸發條件時,以及 resourceName 值時,請指定資源名稱路徑模式。資源名稱會指出透過稽核記錄稽核的資源。資源名稱是由資源本身的 ID 和任何父項資源的 ID 組成,並以正斜線分隔,形成階層式結構,例如:/projects/project-1/datasets/dataset-id。Eventarc 執行的篩選作業會根據這些 ID 的值比對模式。詳情請參閱本文的「資源名稱格式」。
[[["容易理解","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 (世界標準時間)。"],[[["\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)."]]