You can enable or disable the collecting and publishing of events from Google sources for a specific Eventarc Advanced bus.
Events from Google sources are directly triggered by an unmediated event such as the creation of a Cloud Run function or a status change to a Dataflow job. For more information, see Google event types supported by Eventarc.
Note the following:
- There is a limit of one
GoogleApiSource
resource per Google Cloud project. - You can publish events from Google sources only in the same Google Cloud project
as the
GoogleApiSource
resource. - You can publish events to a bus that is in a different Google Cloud project
from the one in which the
GoogleApiSource
resource exists. You can configure this by using the gcloud CLI or by sending a request to the Eventarc API.
Enable events from Google sources
To publish events from Google sources, you must create a
GoogleApiSource
resource. This resource represents a subscription to Google API events in a
specific Google Cloud project for a particular Eventarc Advanced bus.
You can enable the publishing of events from Google sources in the following ways:
- In the Google Cloud console
- By using the Google Cloud CLI in either your terminal or Cloud Shell
By sending a request to the Eventarc API
In the Google Cloud console, go to the Eventarc > Bus page.
You can create a bus or, if you are updating a bus, click Edit.
On the Edit bus page, to add a message source, click
Add source.- In the Add message source pane, for the Google API message
provider, accept the default of
google-api-source
or enter a different message source name. - Click Create.
- In the Add message source pane, for the Google API message
provider, accept the default of
Click Save.
Open a terminal.
You can enable events from Google sources by using the
gcloud beta eventarc google-api-sources create
command:gcloud beta eventarc google-api-source create
GOOGLE_API_SOURCE_NAME \ --destination-message-bus=BUS_NAME \ --destination-message-bus-project=BUS_PROJECT_ID Replace the following:
GOOGLE_API_SOURCE_NAME
: the ID or fully qualified identifier of yourGoogleApiSource
resource which represents a subscription to Google API events for a particular busBUS_NAME
: the ID or fully qualified identifier of the bus for which you want to subscribe to Google API eventsBUS_PROJECT_ID
: the Google Cloud project ID for the bus
Optional: You can also use the following flags:
--async
to return from the command immediately, without waiting for the operation in progress to complete.--crypto-key
to specify the fully qualified name of a customer-managed encryption key; if unspecified, Google-owned and managed keys are used.--logging-config
to configure the logging level which must be one of the following:NONE
,DEBUG
,INFO
,NOTICE
,WARNING
,ERROR
,CRITICAL
,ALERT
,EMERGENCY
. For more information, seeLogSeverity
.
To enable events from Google sources, use the
projects.locations.googleApiSources.create
method.
Before using any of the request data, make the following replacements:
: the display name of theGOOGLE_API_SOURCE_NAME GoogleApiSource
resource which represents a subscription to Google API events for a particular bus—for example,my_google_source
.
andLABEL_KEY
: optional. A map of label key and value pairs that help you organize your Google Cloud resources. For more information, see What are labels?LABEL_VALUE
andANNOTATION_KEY
: optional. A map of annotation key and value pairs of free-form text. You can use them to attach arbitrary information associated with the resource. For more information, see Annotations.ANNOTATION_VALUE
: the fully qualified identifier of the Eventarc Advanced bus to which Google source events should be published in the formatDESTINATION projects/PROJECT_NAME/locations/LOCATION/messageBuses/BUS_NAME
. For more information, see Create a bus to route messages.
: optional. A Cloud KMS key that theENCRYPT_KEY GoogleApiSource
resource should use for data encryption in the formatprojects/PROJECT_NAME/locations/LOCATION/keyRings/RING_NAME/cryptoKeys/KEY_NAME
. For more information, see Use customer-managed encryption keys.
: the Google Cloud project ID in which to create thePROJECT_ID GoogleApiSource
resource.
: the supported region in which to create theLOCATION GoogleApiSource
resource—for example,us-central1
.
: optional. The minimum severity of the event described in a log entry. One of:LOG_SEVERITY NONE
,DEBUG
,INFO
,NOTICE
,WARNING
,ERROR
,CRITICAL
,ALERT
,EMERGENCY
. The default isNONE
. For more information, seeLogSeverity
.
Request JSON body:
{ "displayName": "GOOGLE_API_SOURCE_NAME ", "labels": {"LABEL_KEY ":"LABEL_VALUE "}, "annotations": {"ANNOTATION_KEY ":"ANNOTATION_VALUE "}, "destination": "DESTINATION ", "cryptoKeyName": "ENCRYPT_KEY ", "loggingConfig": {"logSeverity":"LOG_SEVERITY "} }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF' { "displayName": "GOOGLE_API_SOURCE_NAME ", "labels": {"LABEL_KEY ":"LABEL_VALUE "}, "annotations": {"ANNOTATION_KEY ":"ANNOTATION_VALUE "}, "destination": "DESTINATION ", "cryptoKeyName": "ENCRYPT_KEY ", "loggingConfig": {"logSeverity":"LOG_SEVERITY "} } EOF
Then execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://eventarc.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /googleApiSources?googleApiSourceId=GOOGLE_API_SOURCE_NAME "
PowerShell (Windows)
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@' { "displayName": "GOOGLE_API_SOURCE_NAME ", "labels": {"LABEL_KEY ":"LABEL_VALUE "}, "annotations": {"ANNOTATION_KEY ":"ANNOTATION_VALUE "}, "destination": "DESTINATION ", "cryptoKeyName": "ENCRYPT_KEY ", "loggingConfig": {"logSeverity":"LOG_SEVERITY "} } '@ | Out-File -FilePath request.json -Encoding utf8
Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://eventarc.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /googleApiSources?googleApiSourceId=GOOGLE_API_SOURCE_NAME " | Select-Object -Expand Content
APIs Explorer (browser)
Copy the request body and open the method reference page. The APIs Explorer panel opens on the right side of the page. You can interact with this tool to send requests. Paste the request body in this tool, complete any other required fields, and click Execute.
If successful, the response body contains a newly created instance of
Operation
:
{ "name": "projects/PROJECT_ID /locations/LOCATION /operations/OPERATION_ID ", "metadata": { "@type": "type.googleapis.com/google.cloud.eventarc.v1.OperationMetadata", "createTime": "2024-01-25T17:17:45.782370139Z", "target": "projects/PROJECT_ID /locations/LOCATION /googleApiSources/GOOGLE_API_SOURCE_NAME ", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
Events from Google sources in the same Google Cloud project as the
GoogleApiSource
resource are now collected and published to the bus.
Disable events from Google sources
To disable the publishing of events from Google sources in a specific
Google Cloud project to an Eventarc Advanced bus, you must
delete the
GoogleApiSource
resource.
You can disable the publishing of events from Google sources in the following ways:
- In the Google Cloud console
- By using the gcloud CLI in either your terminal or Cloud Shell
By sending a request to the Eventarc API
In the Google Cloud console, go to the Eventarc > Bus details page.
Click
Edit.On the Edit bus page, to delete the Google API message provider, click
Delete resource for the google-api-source message source (or the name you have given it).At the Delete resource prompt, click Confirm.
Click Save.
Open a terminal.
You can disable events from Google sources by using the
gcloud beta eventarc google-api-sources delete
command:gcloud beta eventarc google-api-source delete
GOOGLE_API_SOURCE_NAME \ --location=REGION Replace the following:
GOOGLE_API_SOURCE_NAME
: the ID or fully qualified identifier of theGoogleApiSource
resourceREGION
: the location of theGoogleApiSource
resource
To disable events from Google sources, use the
projects.locations.googleApiSources.delete
method.
Before using any of the request data, make the following replacements:
: the Google Cloud project ID in which thePROJECT_ID GoogleApiSource
resource is created.
: the region in which theLOCATION GoogleApiSource
resource is created—for example,us-central1
.
: the name of theGOOGLE_API_SOURCE_NAME GoogleApiSource
resource you want to delete.
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://eventarc.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /googleApiSources/GOOGLE_API_SOURCE_NAME "
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://eventarc.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /googleApiSources/GOOGLE_API_SOURCE_NAME " | Select-Object -Expand Content
APIs Explorer (browser)
Open the method reference page. The APIs Explorer panel opens on the right side of the page. You can interact with this tool to send requests. Complete any required fields and click Execute.
If successful, the response body contains a newly created instance of
Operation
:
{ "name": "projects/PROJECT_ID /locations/LOCATION /operations/OPERATION_ID ", "metadata": { "@type": "type.googleapis.com/google.cloud.eventarc.v1.OperationMetadata", "createTime": "2024-01-25T17:17:45.782370139Z", "target": "projects/PROJECT_ID /locations/LOCATION /googleApiSources/GOOGLE_API_SOURCE_NAME ", "verb": "delete", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }
Events from Google sources in the same Google Cloud project as the deleted
GoogleApiSource
resource are no longer collected and published.