Skip to content
Snippets Groups Projects
Commit c2719b5e authored by skorpy's avatar skorpy :construction_worker:
Browse files

update grafana.vcl

parent f7a66b62
No related branches found
No related tags found
Loading
......@@ -3,18 +3,38 @@ import vsthrottle;
backend default {
{%- if frontend == 'traefik' %}
.host = "grafana";
.host = "grafana";
{%- elif frontend == 'nginx' %}
.host = "127.0.0.1";
.host = "127.0.0.1";
{%- endif %}
.port = "3000";
.port = "3000";
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
# Removing Google Analytics added parameters
if(req.url ~ "(\?|&)(_t|utm_[a-z]+|mr:[A-z]+|gclid|cx|ie|cof|siteurl)=") {
set req.url = regsuball(req.url, "(_t|utm_[a-z]+|mr:[A-z]+|gclid|cx|ie|cof|siteurl)=[%.+-_A-z0-9]+&?", "");
}
set req.url = regsub(req.url, "\?&", "?");
set req.url = regsub(req.url, "(\?|&)+$", "");
if (req.method != "GET" && req.method != "HEAD") {
return (pass);
return (pass);
}
# grace period (stale content delivery while revalidating)
set req.http.grace = "none";
# Accept-Encoding header clean-up
if (req.http.Accept-Encoding) {
# use gzip when possible, otherwise use deflate
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} elsif (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
}
}
# Goodbye incoming cookies:
......@@ -24,10 +44,6 @@ sub vcl_recv {
unset req.http.user-agent;
unset req.http.referer;
if(req.url ~ "(\?|&)(_t|utm_[a-z]+|mr:[A-z]+)=") {
set req.url = regsuball(req.url, "(_t|utm_[a-z]+|mr:[A-z]+)=[%.+-_A-z0-9]+&?", "");
}
set req.url = regsub(req.url, "(\?|&)+$", "");
return (hash);
}
......@@ -36,6 +52,35 @@ sub vcl_hash {
return(lookup);
}
sub vcl_backend_fetch {
/*
* we force keep-alive to the upstream
*/
set bereq.http.Connection = "Keep-Alive";
unset bereq.http.X-Varnish;
}
sub vcl_hit {
if (obj.ttl >= 0s) {
# normal hit
return (deliver);
}
# Looking at stale content
if (std.healthy(req.backend_hint)) {
# Backend is healthy. Limit age to 10s.
if (obj.ttl + 10s > 0s) {
set req.http.grace = "normal(limited)";
return (deliver);
} else {
# backend is sick - use full grace
if (obj.ttl + obj.grace > 0s) {
set req.http.grace = "full";
return (deliver);
}
}
}
}
sub vcl_miss {
if (req.url ~ "^/render/") {
if (vsthrottle.is_denied(req.http.X-Real-IP, 10, 30s, 10s)) {
......@@ -70,4 +115,22 @@ sub vcl_deliver {
# response to the client.
#
# You can do accounting or modifying the final object here.
/*
* generic synthetic handler
*/
set resp.http.Date = now;
unset resp.http.via;
unset resp.http.x-varnish;
unset resp.http.Server;
set resp.http.Server = "nginx";
set resp.http.grace = req.http.grace;
# could be useful to know if the object was in cache or not
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
return (deliver);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment