[NET-9467, NET-9468] Add partitions + exportedServices funcs#1940
Conversation
c8a1fab to
4a33247
Compare
Co-authored-by: Blake Covarrubias <blake.covarrubias@gmail.com>
for exportedServices
| assert.Equal(t, tc.exp, act) | ||
| }) | ||
| } | ||
| fmt.Println("done") |
| exitCh <- m.Run() | ||
| }() | ||
|
|
||
| exit := <-exitCh |
There was a problem hiding this comment.
this channel shenanigans doesn't actually do anything
| runTestConsul(tb) | ||
| clients := NewClientSet() | ||
|
|
||
| defer func() { |
There was a problem hiding this comment.
moved the defer here so we actually catch panics during setup, this won't catch panics during test runs, I spent some time trying to get to a working solution but it would require checking for running instances of consul/nomad/vault that did not previously get cleaned up before running
jmurret
left a comment
There was a problem hiding this comment.
Approving, nothing blocking from my additional comments, but think you do need to address RB's comment about exported services implementing blocking queries. You'll want to remove that logic that does this select based on the sleep time.
|
|
||
| // ListPartitionsQuerySleepTime is the amount of time to sleep between | ||
| // queries, since the endpoint does not support blocking queries. | ||
| ListPartitionsQuerySleepTime = 15 * time.Second |
There was a problem hiding this comment.
[NIT] wonder if we want to create just one LongPollingSleepTime set to 15 seconds for use across all of the non blocking query endpoints?
There was a problem hiding this comment.
so we kinda can, we do some re-assigning of these within tests and I'm not 100% on how that will play out if these tests run in parallel (since we could get a concurrent read and write) what I did though was move this to a DefaultNonBlockingQuerySleepTime constant and assign the individual sleep times to that const
default sleep time
Overview
This pull request adds two new functions to consul-template:
partitions, which lists all partitions in the local datacenter using the existing/v1/partitionsAPIexportedServices, which lists all exported services in a given partition using the existing/v1/exported-servicesAPIExample
By combining these two functions, you can list the services imported into the local partition from all other partitions within the local datacenter.
Note
The following should probably be optimized with a
{{ break }}to end therangeearly once$localPartitionhas been identified as a consumer of a given service; however, I haven't had a chance to test with that change in place yet, so I'm noting it here.{{- $localPartition := "ap2" -}} {{/* Loop through all partitions in the local datacenter */}} {{- range $partition := partitions -}} {{/* Loop through exported services for partition, unless it's our own partition */}} {{- if not (eq $partition.Name $localPartition) -}} {{- range $svc := (exportedServices $partition.Name) -}} {{/* For each service, loop through partition consumers looking for our own partition */}} {{- range $consumer := .Consumers.Partitions -}} {{/* Print only when the service is exported to our own partition */}} {{- if eq $consumer $localPartition -}} {{- printf "Service %q exported from %q to %q\n" $svc.Service $partition.Name $consumer -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}}