Skip to content

Commit

Permalink
Cleaned up stats
Browse files Browse the repository at this point in the history
  • Loading branch information
auduny committed Apr 11, 2024
1 parent 1de585f commit f4e1a2a
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 85 deletions.
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run Varnish",
"type": "shell",
"command": "varnishd -F -a :8180 -f $PWD/varnish.vcl"
},
{
"label": "Chaosbackend",
"type": "shell",
"command": "docker run -p 8181:8181 -p 8182:8182 ghcr.io/auduny/chaosbackend:latest -a 0.0.0.0 -p 8181,8182"
}
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /varnishprom

#Testing Varnish Enterprise needs payed varnsh enterprise subscription
#Testing Varnish Enterprise needs payed varnish enterprise subscription
#FROM quay.io/varnish-software/varnish-plus:latest
#Testing Varnish Open Source 6.0
#FROM:varnish:6.0
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require github.com/prometheus/client_golang v1.19.0

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.50.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.52.3 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sys v0.19.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand All @@ -10,11 +12,15 @@ github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7km
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos=
github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.50.0 h1:YSZE6aa9+luNa2da6/Tik0q0A5AbR+U003TItK57CPQ=
github.com/prometheus/common v0.50.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ=
github.com/prometheus/common v0.52.3 h1:5f8uj6ZwHSscOGNdIQg6OiZv/ybiK2CO2q2drVZAQSA=
github.com/prometheus/common v0.52.3/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U=
github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o=
github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
33 changes: 21 additions & 12 deletions varnish.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import std;
import directors;

backend chaos1 {
.host = "127.0.0.1:8180";
.host = "127.0.0.1:8181";
}

backend chaos2 {
.host = "127.0.0.1:8180";
.host = "127.0.0.1:8182";
}

sub vcl_init {
Expand All @@ -16,7 +16,6 @@ sub vcl_init {
chaos.add_backend(chaos2);
}


sub vcl_recv {
unset req.http.cookie;
if (req.url ~ "^/foo") {
Expand All @@ -26,33 +25,43 @@ sub vcl_recv {
} else {
set req.backend_hint = chaos.backend();
}
set req.http.X-Director = req.backend_hint;
set req.http.X-Varnish-Director = req.backend_hint;
}

sub vcl_hit {
set req.http.V-Cache = "HIT";
set req.http.x-cache = "HIT";
if (obj.ttl <= 0s && obj.grace > 0s) {
set req.http.x-cache = "STALE";
}
}

sub vcl_miss {
set req.http.V-Cache = "MISS";
set req.http.X-Varnish-Cache = "MISS";
}

sub vcl_pass {
set req.http.V-Cache = "PASS";
set req.http.X-Varnish-Cache = "PASS";
}

sub vcl_pipe {
set req.http.V-Cache = "PIPE";
set req.http.X-Varnish-Cache = "PIPE";
}

sub vcl_synth {
set req.http.X-Varnish-Cache = "SYNTH";
}

sub vcl_backend_response {
set beresp.http.V-Backend = beresp.backend;
set beresp.http.Varnish-Backend = beresp.backend;
}

sub vcl_deliver {
set resp.http.V-Cache = req.http.V-Cache + ":" + obj.hits;
set resp.http.V-Director = req.http.X-Director;
std.log("prom=backends backend=" + resp.http.V-Backend + ",director="+ resp.http.V-Director + ",cache=" + req.http.V-Cache + ",status=" + resp.status +",desc=vcl_deliver");
if (obj.uncacheable) {
set resp.http.X-Varnish-Cache = resp.http.X-Varnish-Cache + " uncacheable" ;
}
set resp.http.X-Varnish-Hits = obj.hits;
set resp.http.X-Varnish-Director = req.http.X-Varnish-Director;
std.log("prom=backends backend=" + resp.http.X-Varnish-Backend + ",director="+ resp.http.X-Varnish-Director + ",cache=" + req.http.X-Varnish-Cache + ",status=" + resp.status +",desc=vcl_deliver");
}

sub vcl_synth {
Expand Down
Loading

0 comments on commit f4e1a2a

Please sign in to comment.