Grafana Cloud Enterprise Open source

Avoid API rate limits when provisioning alerting resources

When you manage Grafana Alerting resources as code, tools such as Terraform, the Crossplane Grafana provider, and GitOps engines repeatedly read your resources to detect drift. At scale, these reconciliation loops can hit an API rate limit, and Grafana rejects the extra requests with the 429 Too Many Requests status code.

This page explains why provisioning amplifies API requests and how to tune your tooling to stay under the limits.

Before you begin, ensure you have the following:

  • A Grafana instance or Grafana Cloud stack where you provision alerting resources.
  • Administrative access to the Terraform, Crossplane, or GitOps configuration that manages those resources.
  • Access to the logs of the tool that reports the errors.

Why provisioning at scale triggers rate limits

Rate limits usually depend on how often your tooling reads resources and how many requests each read takes, not on how many resources you manage. The following factors compound each other:

  • Reconciliation loops re-read every resource: Tools poll Grafana on a fixed interval to compare the live state against the desired state, even when nothing changed. Request volume scales with the number of resources multiplied by the polling frequency.
  • Reading provenance takes a request per rule: Provenance, which marks a resource as provisioned, is returned per rule. To determine it for a rule group, the Grafana Terraform provider fetches the group with GET /api/v1/provisioning/folder/{folderUID}/rule-groups/{group}, then fetches each rule with GET /api/v1/provisioning/alert-rules/{UID}. A group of 50 rules makes 51 requests per reconcile.
  • Multiple tools share one stack: Running provider pods in several Kubernetes clusters, or Terraform in CI alongside a Crossplane controller, counts every request against the same limits.

Identify rate limit errors

Rate limited requests fail with the 429 Too Many Requests status code. Check your tool’s logs for that code alongside a provisioning endpoint. For example, the Crossplane Grafana provider reports:

text
observe failed: failed to observe the resource: [{0 [GET /v1/provisioning/alert-rules/acefead6586dbc] GetAlertRule (status 429): {} []}]

Rate limits differ by endpoint and deployment. If requests are throttled, reduce your request volume using the following sections, and contact Grafana Support to confirm which limits apply to your stack.

Retry rate limited requests in Terraform

The Grafana Terraform provider retries failed API calls, including 429, by default. Raise the retry count and wait time to let a plan or apply recover from short bursts of throttling:

terraform
provider "grafana" {
  url  = "<GRAFANA_URL>"
  auth = "<SERVICE_ACCOUNT_TOKEN>"

  retries            = 10
  retry_wait         = 30
  retry_status_codes = ["429", "5xx"]
}

Replace the following values:

  • <GRAFANA_URL>: The URL of your Grafana instance or Grafana Cloud stack.
  • <SERVICE_ACCOUNT_TOKEN>: A service account token with permissions for the alerting provisioning API.

The retry arguments control the following behavior:

  • retries: The number of times to retry a failed API call.
  • retry_wait: The number of seconds to wait between retries.
  • retry_status_codes: The status codes that trigger a retry, where x is a digit wildcard. The default is 429 and any 5xx code.

You can also set these values with the GRAFANA_RETRIES, GRAFANA_RETRY_WAIT, and GRAFANA_RETRY_STATUS_CODES environment variables. Default values can change between provider versions, so confirm them in the provider documentation.

Tune the Crossplane provider

Retries don’t help a Crossplane controller, because it polls continuously. Lower the request rate instead with the following flags:

  • --poll: How often a resource is checked for drift. Increasing it cuts steady-state request volume proportionally.
  • --max-reconcile-rate: The global maximum rate per second at which resources are checked for drift. Lowering it smooths the burst that occurs when the controller starts and reconciles everything at once.
  • --sync: The controller manager sync period.

The following example sets a longer poll interval and a lower reconcile rate than the provider defaults. Confirm the current defaults in the Crossplane provider documentation, as they can change between versions. Set the flags through a DeploymentRuntimeConfig, then reference it from the provider:

YAML
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
  name: tuned-grafana-provider-config
spec:
  deploymentTemplate:
    spec:
      selector: {}
      template:
        spec:
          containers:
            - name: package-runtime
              args:
                - --poll=30m
                - --max-reconcile-rate=5
---
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: provider-grafana
spec:
  package: <PROVIDER_PACKAGE>
  runtimeConfigRef:
    name: tuned-grafana-provider-config

Replace <PROVIDER_PACKAGE> with the package reference and version of the provider you run.

The container must be named package-runtime, or Crossplane adds it as a sidecar instead of tuning the provider. Use longer intervals in non-production environments and tighten them only where you need faster reconciliation.

Reduce redundant syncs in GitOps engines

GitOps engines add reconcile cycles on top of the controller’s polling. To skip unneeded work, apply only changed resources (ApplyOutOfSyncOnly=true in Argo CD), avoid forced re-applies (Force=true or Replace=true), and align the engine’s reconcile interval with the provider’s --poll value.

Migrate to the Grafana App Platform alerting APIs

The legacy provisioning endpoints under /api/v1/provisioning/ are deprecated and will be removed in a future release. Until then, you can keep using tuned legacy configurations while you plan a migration. The Grafana App Platform alerting APIs expose each alert rule as its own resource under /apis/rules.alerting.grafana.app/v0alpha1/namespaces/{namespace}/alertrules/{name}, which avoids the extra per-rule provenance request. In Terraform, the equivalent resource is grafana_apps_rules_alertrule_v0alpha1.

Next steps