diff --git a/__generator__/predefined.yml b/__generator__/predefined.yml index 4bb74236..3da5d01d 100644 --- a/__generator__/predefined.yml +++ b/__generator__/predefined.yml @@ -182,6 +182,21 @@ backend.socket.tcpi_total_retrans: on: [FETCH] get: INTEGER +backend.%any%.connections_open: + reference: "https://www.fastly.com/documentation/reference/vcl/variables/backend-connection/backend-connections-open/" + on: [RECV, HASH, HIT, MISS, PASS, FETCH, ERROR, DELIVER, LOG] + get: INTEGER + +backend.%any%.connections_used: + reference: "https://www.fastly.com/documentation/reference/vcl/variables/backend-connection/backend-connections-used/" + on: [RECV, HASH, HIT, MISS, PASS, FETCH, ERROR, DELIVER, LOG] + get: INTEGER + +backend.%any%.healthy: + reference: "https://developer.fastly.com/reference/vcl/variables/backend-connection/backend-healthy/" + on: [RECV, HASH, HIT, MISS, PASS, FETCH, ERROR, DELIVER, LOG] + get: INTEGER + bereq.between_bytes_timeout: reference: "https://developer.fastly.com/reference/vcl/variables/backend-connection/bereq-between-bytes-timeout/" on: [PASS, MISS] diff --git a/context/predefined.go b/context/predefined.go index 732be5c5..cb929bfc 100644 --- a/context/predefined.go +++ b/context/predefined.go @@ -20,6 +20,40 @@ func predefinedVariables() Variables { }, "backend": &Object{ Items: map[string]*Object{ + "%any%": &Object{ + Items: map[string]*Object{ + "connections_open": &Object{ + Items: map[string]*Object{}, + Value: &Accessor{ + Get: types.IntegerType, + Set: types.NeverType, + Unset: false, + Scopes: RECV | HASH | HIT | MISS | PASS | FETCH | ERROR | DELIVER | LOG, + Reference: "https://www.fastly.com/documentation/reference/vcl/variables/backend-connection/backend-connections-open/", + }, + }, + "connections_used": &Object{ + Items: map[string]*Object{}, + Value: &Accessor{ + Get: types.IntegerType, + Set: types.NeverType, + Unset: false, + Scopes: RECV | HASH | HIT | MISS | PASS | FETCH | ERROR | DELIVER | LOG, + Reference: "https://www.fastly.com/documentation/reference/vcl/variables/backend-connection/backend-connections-used/", + }, + }, + "healthy": &Object{ + Items: map[string]*Object{}, + Value: &Accessor{ + Get: types.IntegerType, + Set: types.NeverType, + Unset: false, + Scopes: RECV | HASH | HIT | MISS | PASS | FETCH | ERROR | DELIVER | LOG, + Reference: "https://developer.fastly.com/reference/vcl/variables/backend-connection/backend-healthy/", + }, + }, + }, + }, "conn": &Object{ Items: map[string]*Object{ "is_tls": &Object{ diff --git a/docs/variables.md b/docs/variables.md index 75797098..88d32674 100644 --- a/docs/variables.md +++ b/docs/variables.md @@ -97,6 +97,9 @@ Will be updated when we find or implement a way to get accurate values. | backend.socket.tcpi_snd_mss | 0 | | backend.socket.tcpi_snd_ssthresh | 0 | | backend.socket.tcpi_total_retrans | 0 | +| backend.{name}.connections_open | 0 | +| backend.{name}.connections_used | 0 | +| backend.{name}.healthy | true | | beresp.backend.alternate_ips | (empty string) | | beresp.backend.ip | 0 | | beresp.backend.requests | 1 | diff --git a/interpreter/variable/all.go b/interpreter/variable/all.go index 4078fa72..98323607 100644 --- a/interpreter/variable/all.go +++ b/interpreter/variable/all.go @@ -664,6 +664,19 @@ func (v *AllScopeVariables) getFromRegex(name string) value.Value { Value: val, } } + + if match := backendConnectionsOpenRegex.FindStringSubmatch(name); match != nil { + return &value.Integer{} + } + + if match := backendConnectionsUsedRegex.FindStringSubmatch(name); match != nil { + return &value.Integer{} + } + + if match := backendHealthyRegex.FindStringSubmatch(name); match != nil { + return &value.Boolean{Value: true} + } + return nil } diff --git a/interpreter/variable/variable.go b/interpreter/variable/variable.go index aad74a18..0fdb7ff5 100644 --- a/interpreter/variable/variable.go +++ b/interpreter/variable/variable.go @@ -23,6 +23,9 @@ var ( objectHttpHeaderRegex = regexp.MustCompile(`^obj\.http\.(.+)`) rateCounterRegex = regexp.MustCompile(`ratecounter\.([^\.]+)\.(.+)`) regexMatchedRegex = regexp.MustCompile(`re\.group\.([0-9]+)`) + backendConnectionsOpenRegex = regexp.MustCompile(`backend\.([^\.]+)\.connections_open`) + backendConnectionsUsedRegex = regexp.MustCompile(`backend\.([^\.]+)\.connections_used`) + backendHealthyRegex = regexp.MustCompile(`backend\.([^\.]+)\.healthy`) ) func doAssign(left value.Value, operator string, right value.Value) error {