Warning
You are currently viewing v2.22 of the documentation and it is not the latest. For the most recent documentation, kindly click here.
Google Cloud Platform Spanner
Scale applications based on the result of a Google Cloud Spanner SQL query.
This specification describes the gcp-spanner trigger for Google Cloud Spanner.
triggers:
- type: gcp-spanner
metadata:
projectId: my-gcp-project # Required
instanceId: my-spanner-instance # Required
databaseId: my-database # Required
query: "SELECT COUNT(*) FROM jobs WHERE status = 'pending'" # Required
targetValue: "5" # Optional - Default: 5
activationValue: "0" # Optional - Default: 0
credentialsFromEnv: GOOGLE_APPLICATION_CREDENTIALS_JSON # Optional
Parameter list:
projectId - The GCP project that owns the Spanner instance.instanceId - The Spanner instance ID.databaseId - The Spanner database ID.query - A SQL statement. Only the first column of the first row is used; it must be a non-NULL INT64. When the query matches no rows the value is treated as 0. Use COALESCE(..., 0) for aggregates (e.g. SUM, MAX) that may return NULL. AVG returns FLOAT64, so cast it to INT64 explicitly and still wrap it in COALESCE (e.g. COALESCE(CAST(AVG(...) AS INT64), 0)), since the cast itself returns NULL over an empty set.targetValue - Average target value to trigger scaling actions. Must be greater than 0. (Default: 5, Optional)activationValue - Target value for activating the scaler. Learn more about activation here. (Default: 0, Optional)The metric name will be generated automatically based on the trigger index and the resource identifiers, for example: s0-gcp-spanner-instanceId-databaseId-projectId.
You can provide in the metadata either credentialsFromEnv or credentialsFromEnvFile.
credentialsFromEnv - Set to the name of the environment variable that holds the credential information.credentialsFromEnvFile - Set to the name of a json file that holds the credential information.You can use TriggerAuthentication CRD to configure the authentication by providing the service account credentials in JSON.
Credential based authentication:
GoogleApplicationCredentials - Service account credentials in JSON.Identity based authentication:
You can also use TriggerAuthentication CRD to configure the authentication using the associated service account of the running machine in Google Cloud. You only need to create a TriggerAuthentication as this example, and reference it in the ScaledObject. ClusterTriggerAuthentication can also be used if you intend to use it globally in your cluster.
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: spanner-scaledobject
namespace: my-namespace
spec:
scaleTargetRef:
name: job-processor
triggers:
- type: gcp-spanner
metadata:
projectId: my-gcp-project
instanceId: my-spanner-instance
databaseId: my-database
query: "SELECT COUNT(*) FROM jobs WHERE status = 'pending'"
targetValue: "5"
credentialsFromEnv: GOOGLE_APPLICATION_CREDENTIALS_JSON
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: keda-trigger-auth-gcp-credentials
spec:
secretTargetRef:
- parameter: GoogleApplicationCredentials
name: gcp-spanner-secret # Required. Refers to the name of the secret
key: GOOGLE_APPLICATION_CREDENTIALS_JSON # Required.
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: spanner-scaledobject
spec:
scaleTargetRef:
name: job-processor
triggers:
- type: gcp-spanner
authenticationRef:
name: keda-trigger-auth-gcp-credentials
metadata:
projectId: my-gcp-project
instanceId: my-spanner-instance
databaseId: my-database
query: "SELECT COUNT(*) FROM jobs WHERE status = 'pending'"
targetValue: "5"
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: keda-trigger-auth-gcp-credentials
spec:
podIdentity:
provider: gcp
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: spanner-scaledobject
spec:
scaleTargetRef:
name: job-processor
triggers:
- type: gcp-spanner
authenticationRef:
name: keda-trigger-auth-gcp-credentials
metadata:
projectId: my-gcp-project
instanceId: my-spanner-instance
databaseId: my-database
query: "SELECT COUNT(*) FROM jobs WHERE status = 'pending'"
targetValue: "5"