GAP Documentation
GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage
Edit page

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.

Enable access to the metrics from your service project

In your application’s staging and production project’s IAM module give Monitoring Viewer role to the following service accounts.

Create a HorizontalPodAutoscaler

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"