Categorygithub.com/sapcc/swift-s3-cache-prewarmer
modulepackage
0.0.0-20241019010759-837d1e73f34e
Repository: https://github.com/sapcc/swift-s3-cache-prewarmer.git
Documentation: pkg.go.dev

# README

swift-s3-cache-prewarmer

CI

We have a few customers making extensive use of the S3 API in our Swift cluster. To avoid putting too much load on Keystone, Swift can cache S3 credentials in a Memcache. However, when the customer traffic is high enough to keep multiple parallel Swift API workers busy, once a cache entry expires, they all hit Keystone simultaneously. To avoid this high request load on Keystone caused by expiring cache entries, this tool periodically refreshes the cache entries so that they never expire.

Usage

Build with make/make install or go get or docker build. Check out the --help for how to run this.

Metrics

The prewarm command exposes two gauges for each credential that was prewarmed:

  • swift_s3_cache_prewarm_last_run_secs: UNIX timestamp in seconds of last successful cache prewarm (or 0 before the first successful prewarm)
  • swift_s3_cache_prewarm_duration_secs: duration in seconds of last successful cache prewarm (or absent before the first successful prewarm)

Each time series has the labels userid and accesskey identifying the credential in question.

# Functions

GetCredentialFromKeystone fetches an EC2 credential from Keystone.
GetCredentialFromMemcache fetches an EC2 credential from Memcache.
MustConnectToKeystone connects to Keystone or dies trying.
MustParseCredentials parses CredentialIDs passed in as CLI arguments.
SetCredentialInMemcache writes an EC2 credential into Memcache.

# Structs

CredentialID identifies an EC2 credential.
CredentialPayload contains the payload for a credential which we write into memcached.