Skip to content

Commit

Permalink
Merge pull request #285 from richardmarshall/backend-name-healthy
Browse files Browse the repository at this point in the history
Add missing backend.{name}.* variables
  • Loading branch information
ysugimoto authored Apr 1, 2024
2 parents e8871e5 + 08577c8 commit 65518ed
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
15 changes: 15 additions & 0 deletions __generator__/predefined.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
34 changes: 34 additions & 0 deletions context/predefined.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
13 changes: 13 additions & 0 deletions interpreter/variable/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,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
}

Expand Down
3 changes: 3 additions & 0 deletions interpreter/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 65518ed

Please sign in to comment.