Skip to content

Cache FileSecret reads - #954

Open
prymitive wants to merge 1 commit into
prometheus:mainfrom
prymitive:cache
Open

Cache FileSecret reads#954
prymitive wants to merge 1 commit into
prometheus:mainfrom
prymitive:cache

Conversation

@prymitive

Copy link
Copy Markdown

FileSecret reads files on every request, which means that if I configure a scrape job with:

tls_config:
  ca_file: ca.pem
  cert_file: cert.pem
  key_file: key.pem

All three files will be read using FileSecret every time a scrape starts for that target. With 1k targets and 1m scrape interval this means 50 file reads per second (1000 targets * 3 files / 60s).
File reads require a blocking syscall so having to re-read files all the time isn't ideal on busy instances with a lot of targets. These files are normally small and reads are fast, but the overhead is still there.

Make FileSecret cache file reads, for 1m by default, configurable via cache_ttl YAML key.

FileSecret reads files on every request, which means that if I configure a scrape job with:

```yaml
tls_config:
  ca_file: ca.pem
  cert_file: cert.pem
  key_file: key.pem
```

All three files will be read using FileSecret every time a scrape starts for that target.
With 1k targets and 1m scrape interval this means 50 file reads per second
(1000 targets * 3 files / 60s).
File reads require a blocking syscall so having to re-read files all the time isn't ideal on busy instances with a lot of targets.
These files are normally small and reads are fast, but the overhead is still there.

Make FileSecret cache file reads, for 1m by default, configurable via cache_ttl YAML key.

Signed-off-by: Lukasz Mierzwa <lukasz@cloudflare.com>

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While more scalable, this will break scrapes for maximum of 1m on key rotation, just to be fair. Perhaps ok trade-off.

cc @roidelapluie

@SuperQ

SuperQ commented Aug 11, 2026

Copy link
Copy Markdown
Member

I would recommend changing the default to be 0, no caching, to preserve the existing behavior.

These reads should pull from page cache and be essentially free.

@roidelapluie

Copy link
Copy Markdown
Member

I agree with Ben's comment. Is there any numbers to bake that this is noticeable? I do not think we had complaints in the past 10 years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants