Local cache for remote Timestream data

0

We have multiple devices writing into AWS Timestream databases. We have grafana querying timestream. Problems are:

  1. grafana doesnt do any caching
  2. timestream is expensive to query, when doing it in bulk!

So, does anyone have suggestions for some kind of local caching scheme?

Typical queries might be, "(Show me the average value of X across the last 5 hours)", except it gets rerun every 5 seconds.

So the ideal solution would basically stream updates from Timestream, to (this local caching thing), and then grafana would only hit the local cache, "for free".

pbrown
asked 9 months ago289 views
2 Answers
0

If you are looking for free solutions, below 2 options could work:

  1. Setting up an NGINX proxy with caching capabilities can be a viable solution for caching responses from Timestream for Grafana requests.

The configuration you provided seems to be designed for caching InfluxDB requests, but you can adapt it for Timestream by making some modifications. Here's an example:

# Proxy cache formats
proxy_cache_path /path/to/grafana_cache levels=1:2 keys_zone=grafana_cache:25m max_size=500m inactive=5m use_temp_path=off;
proxy_cache_path /path/to/timestream_cache levels=1:2 keys_zone=timestream_cache:25m max_size=500m inactive=5m use_temp_path=off;

# Maps to detect Timestream traffic
map $http_referer $proxyloc {
    ~*timestream timestream;
}

# Timestream API endpoints
map $request_uri $backend {
    ~*query timestream;
    ~*write timestream;
    ~*ping timestream;
}

# Enable caching for queries
map $request_uri $nonquery {
    ~*query 0;
    default 1;
}

# Proxy configuration
server {
    listen 80;
    server_name your_domain.com;

    location / {
        proxy_pass http://backend;
        
        # Cache configuration
        proxy_cache grafana_cache;
        proxy_cache_valid 200 5m;
        proxy_cache_key "$scheme$request_method$host$request_uri";
        proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
        
        # Conditionally enable caching based on request type
        proxy_cache_bypass $nonquery;
        proxy_no_cache $nonquery;
    }
}
  1. Using an application like Trickster can indeed be a suitable solution for caching and accelerating responses from Timestream for Grafana requests. Trickster is a reverse proxy cache specifically designed for time series databases, including Timestream.

https://github.com/trickstercache/trickster

Note: i don't see any reference to Timestream but since it says it will work with any time series query, it could work.

answered 9 months ago
  • Hmm. Sounds like a really neat tool. But given that AWS has some particular security connection constraints, I would imagine trickster would need to explicitly support it

0

Hi @pbrown - Thank you for your question.

Grafana does offer a caching solution, and a recent blog post describes how to configure the cache. For more info and to get started, read the blog post here:

https://aws.amazon.com/blogs/database/make-your-dashboards-faster-and-more-cost-effective-with-grafana-query-caching-and-amazon-timestream/

Additionally, when to optimize larger queries, please review the best practices in the Timestream developer guide:

https://docs.aws.amazon.com/timestream/latest/developerguide/queries-bp.html

If you have any other questions, please feel free to reach out.

AWS
igor
answered 9 months ago
profile picture
EXPERT
reviewed 8 days ago
  • Thanks for the reply. However, you neglected to mention, "Grafana’s query caching feature (available in Grafana Cloud and Grafana Enterprise) "

    So, this caching is not available unless you pay extra for it.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions