autometrics-dev / autometrics-ts

Easily add metrics to your system – and actually understand them using automatically customized Prometheus queries

Home Page:https://autometrics.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add initial experimental support for immediately pushing metrics in a FaaS context

brettimus opened this issue · comments

Motivation

When using autometrics with a push configuration inside, e.g., an edge function, we run into the issue that the library sets up an interval at which it pushes metrics to a push/aggregation gateway.

This makes the assumption that the parent script is a long-running process.

In an environment like that of Supabase's Edge Functions, we run into the issue that when autometrics is imported and configured in an edge function, it will keep the edge function alive (because of its interval) until the edge function either exceeds its allowed CPU time or times out entirely. In production, anyone using autometrics would effectively be faced with extra billing costs due to this.

Solution

As a first pass, we configure autometrics to immediately push new metrics whenever they are available, in the case where the pushInterval configuration parameter is set to 0.

For a future iteration, we can support a more robust push configuration, as there are likely other relevant options for the FaaS usecase (e.g., configuring a timeout of requests to the gateway).