The Simplest Way to Make Cloud Functions and Cortex Work Like They Should
Teams use cloud functions and cortex to run event code and store metric data. The functions push time series metrics to Cortex for long term storage and alerts. Serverless apps start and stop within a few seconds. They cannot wait for a normal server to pull their health data. Instead, the function sends metrics out before it shuts down. Cortex takes this data, saves it, and lets engineers query it later. This setup helps teams watch short jobs without running extra servers all day. How cloud
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Teams use cloud functions and cortex to run event code and store metric data. The functions push time series metrics to Cortex for long term storage and alerts.
Serverless apps start and stop within a few seconds. They cannot wait for a normal server to pull their health data. Instead, the function sends metrics out before it shuts down. Cortex takes this data, saves it, and lets engineers query it later. This setup helps teams watch short jobs without running extra servers all day.
How cloud functions and cortex pass identity and data
A function starts when an event happens in your cloud account. It runs its task, makes metric numbers, and sends them to Cortex over HTTP. To do this safely, the function needs its own identity role. You set up the cloud platform to give the function a scoped service identity.
The function uses a secret key or token from a safe secret store. It attaches this token to the web request header when it sends data. Cortex checks the token and reads the tenant ID header in the request. If the check passes, Cortex writes the metrics into the right tenant space.
Data flows in one way from the serverless job to the Cortex ingestion endpoint. Because functions disappear fast, they push data at the end of each run. Some teams also use a small helper process inside the function runtime. This helper grabs the metrics and sends them out before the runtime freezes. Cortex then groups these small pushes into blocks for fast read queries.
Common failure modes and how to scope roles
Many teams make the mistake of sharing one service account across all functions. If a bad actor steals that broad token, they can send fake metrics. They could also read data from other teams if the role allows read actions. Shared keys also make it hard to rotate secrets without breaking many apps.
Another common problem is unlogged queries and blind metric pushes. When a thousand functions run at once, they can flood the Cortex write endpoint. Without clear identity logs, you cannot see which function caused the traffic spike. You also risk leaking sensitive strings like emails or phone numbers inside metric labels. If a developer puts a card number or national ID in a label, it stays in storage. Data masking rules help here because masking rewrites matched fields in results.
Cloud Functions IAM + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix these issues, give each function group its own narrow service role. Grant write-only permissions to the ingestion path for that single tenant. Never give read or admin rights to a function that only pushes metrics. Lock down the network path using private cloud links instead of the public web. Set strict rate limits per tenant in Cortex so one runaway job cannot drop the cluster. Finally, log every write request and read query with the caller identity attached.
Keeping metric labels clean and safe
Serverless functions often handle raw user input from web forms or queues. Developers sometimes copy request fields straight into metric tags to help debug errors. This habit creates two big problems for your storage system.
First, unique values like emails or phone numbers create too many time series. High tag counts use up memory fast and slow down every dashboard query. Second, private data ends up in a metric system meant only for system health. Teams must check label names in code reviews and strip out user strings before sending metrics.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.
Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Why do functions push metrics instead of letting Cortex pull them?
Cloud functions only live for a few seconds per event and have no fixed IP. They must push metrics out before shutting down because Cortex cannot reach in to scrape them.
How do I stop one noisy function from breaking Cortex?
Assign each function group a separate tenant ID or scoped write key. Then set per-tenant ingestion rate limits in Cortex to block sudden metric spikes.
Should a cloud function ever have read permissions in Cortex?
No, most functions only need to send telemetry data out. Give them write-only roles and reserve read permissions for dashboards and alert tools.
Related guides
In this post