Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"net/http"
"net/url"
"strings"
"sync"

"github.com/prometheus/client_golang/prometheus"

Expand All @@ -48,7 +49,10 @@
type Collector struct {
metrics []prometheus.Metric
}

type probeResult struct {
metrics []prometheus.Metric
ok bool
}
type TargetMetadata struct {
VersionMajor int
VersionMinor int
Expand Down Expand Up @@ -124,9 +128,9 @@
includedProbes := savedConfig.AuthKeys[config.Target(u.String())].Probes.Include
excludedProbes := savedConfig.AuthKeys[config.Target(u.String())].Probes.Exclude

// TODO: Make parallel
success := true
for _, aProbe := range []probeDetailedFunc{
var wg sync.WaitGroup
var mu sync.Mutex
allProbes := []probeDetailedFunc{
// Always keep probeSystemTime on top of the list to have the probe processed first.
// Therefore time returned is more accurate when integrated in Prometheus because
// timestamp for the metrics probe, in Prometheus, is obtained from the query time, not the reply time.
Expand Down Expand Up @@ -171,7 +175,10 @@
{"Wifi/ManagedAP", probeWifiManagedAP},
{"Switch/ManagedSwitch", probeManagedSwitch},
{"OSPF/Neighbors", probeOSPFNeighbors},
} {
}
success := true
results := make(chan probeResult, len(allProbes))
for _, aProbe := range allProbes {
wanted := false

if len(includedProbes) == 0 {
Expand All @@ -197,14 +204,32 @@
if !wanted {
continue
}
wg.Add(1)
go func(probe probeDetailedFunc) {

Check failure on line 208 in pkg/probe/probe.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'probe' seems to be unused, consider removing or renaming it as _ (revive)
defer wg.Done()
m, ok := aProbe.function(c, meta)
results <- probeResult{
metrics: m,
ok: ok,
}
}(aProbe)

m, ok := aProbe.function(c, meta)
if !ok {
}
go func() {
wg.Wait()
close(results)
}()
for res := range results {
mu.Lock()
p.metrics = append(p.metrics, res.metrics...)
mu.Unlock()

if !res.ok {
mu.Lock()
success = false
mu.Unlock()
}
p.metrics = append(p.metrics, m...)
}

return success, nil
}

Expand Down
Loading