Autoscaling using Pub/Sub (or other GCP service) metrics
If you want to use metrics for autoscaling which are provided by Google services, like Pub/Sub, you need do the following steps.
In your application’s staging and production project’s IAM module give Monitoring Viewer role to the following service accounts.
- staging: gap-metrics-gap-staging@ems-gap-stage.iam.gserviceaccount.com
- production: gap-metrics-gap-production@ems-gap-production.iam.gserviceaccount.com
In your gap.yaml set your autoscaling settings for your deployment like the example below.
If your staging and production projects, replica counts or targetValues differ use the environment specific override yaml files.
See more info here
deployments:
test-worker:
autoscaling:
enabled: true
minReplicas: 1
maxReplicas: 10
metrics:
- type: External
name: pubsub.googleapis.com|subscription|num_undelivered_messages
selector:
matchLabels:
resource.labels.subscription_id: <subscription-id> # some other identifier of the metric
resource.labels.project_id: <project-id> # the id of project where your resource (eg. pub/sub) lives
targetValue: "50"