Skip to content

Commit

Permalink
[metrics] Clone latency and resp-code (only HTTP) metrics values (clo…
Browse files Browse the repository at this point in the history
  • Loading branch information
manugarg authored Aug 5, 2023
1 parent 7b235ee commit 00d71c6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion probes/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (prr probeRunResult) Metrics() *metrics.EventMetrics {
return metrics.NewEventMetrics(time.Now()).
AddMetric("total", &prr.total).
AddMetric("success", &prr.success).
AddMetric(prr.latencyMetricName, prr.latency).
AddMetric(prr.latencyMetricName, prr.latency.Clone()).
AddMetric("timeouts", &prr.timeouts).
AddMetric("validation_failure", prr.validationFailure)
}
Expand Down
22 changes: 11 additions & 11 deletions probes/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ type Probe struct {
l *logger.Logger

// book-keeping params
labelKeys map[string]bool // Labels for substitution
requestID int32
cmdRunning bool
labelKeys map[string]bool // Labels for substitution
requestID int32
cmdRunning bool
cmdRunningMu sync.Mutex // synchronizes cmdRunning
cmdStdin io.Writer
cmdStdout io.ReadCloser
cmdStderr io.ReadCloser
replyChan chan *serverpb.ProbeReply
targets []endpoint.Endpoint
results map[string]*result // probe results keyed by targets
dataChan chan *metrics.EventMetrics
cmdStdin io.Writer
cmdStdout io.ReadCloser
cmdStderr io.ReadCloser
replyChan chan *serverpb.ProbeReply
targets []endpoint.Endpoint
results map[string]*result // probe results keyed by targets
dataChan chan *metrics.EventMetrics

// This is used for overriding run command logic for testing.
runCommandFunc func(ctx context.Context, cmd string, args, envVars []string) ([]byte, []byte, error)
Expand Down Expand Up @@ -313,7 +313,7 @@ func (p *Probe) defaultMetrics(target string, result *result) *metrics.EventMetr
em := metrics.NewEventMetrics(time.Now()).
AddMetric("success", metrics.NewInt(result.success)).
AddMetric("total", metrics.NewInt(result.total)).
AddMetric(p.opts.LatencyMetricName, result.latency).
AddMetric(p.opts.LatencyMetricName, result.latency.Clone()).
AddLabel("ptype", "external").
AddLabel("probe", p.name).
AddLabel("dst", target)
Expand Down
6 changes: 3 additions & 3 deletions probes/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,14 @@ func (p *Probe) exportMetrics(ts time.Time, result *probeResult, target endpoint
em := metrics.NewEventMetrics(ts).
AddMetric("total", metrics.NewInt(result.total)).
AddMetric("success", metrics.NewInt(result.success)).
AddMetric(p.opts.LatencyMetricName, result.latency).
AddMetric(p.opts.LatencyMetricName, result.latency.Clone()).
AddMetric("timeouts", metrics.NewInt(result.timeouts)).
AddMetric("resp-code", result.respCodes)
AddMetric("resp-code", result.respCodes.Clone())

em.LatencyUnit = p.opts.LatencyUnit

if result.respBodies != nil {
em.AddMetric("resp-body", result.respBodies)
em.AddMetric("resp-body", result.respBodies.Clone())
}

if p.c.GetKeepAlive() {
Expand Down
15 changes: 8 additions & 7 deletions probes/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ local port to find the correct destination socket.
More about these sockets: http://lwn.net/Articles/420800/
Note: On some linux distributions these sockets are not enabled by default; you
can enable them by doing something like the following:
sudo sysctl -w net.ipv4.ping_group_range="0 5000"
sudo sysctl -w net.ipv4.ping_group_range="0 5000"
*/
package ping

Expand Down Expand Up @@ -472,11 +473,11 @@ func (p *Probe) newRunID() uint16 {

// runProbe is called by Run for each probe interval. It does the following on
// each run:
// * Resolve targets if target resolve interval has elapsed.
// * Increment run count (runCnt).
// * Get a new run ID.
// * Starts a goroutine to receive packets.
// * Send packets.
// - Resolve targets if target resolve interval has elapsed.
// - Increment run count (runCnt).
// - Get a new run ID.
// - Starts a goroutine to receive packets.
// - Send packets.
func (p *Probe) runProbe() {
// Resolve targets if target resolve interval has elapsed.
if (p.runCnt % uint64(p.c.GetResolveTargetsInterval())) == 0 {
Expand Down Expand Up @@ -528,7 +529,7 @@ func (p *Probe) Start(ctx context.Context, dataChan chan *metrics.EventMetrics)
em := metrics.NewEventMetrics(ts).
AddMetric("total", metrics.NewInt(result.sent)).
AddMetric("success", metrics.NewInt(success)).
AddMetric(p.opts.LatencyMetricName, result.latency).
AddMetric(p.opts.LatencyMetricName, result.latency.Clone()).
AddLabel("ptype", "ping").
AddLabel("probe", p.name).
AddLabel("dst", target.Name)
Expand Down
2 changes: 1 addition & 1 deletion probes/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (result *probeResult) Metrics(ts time.Time, opts *options.Options) *metrics
em := metrics.NewEventMetrics(ts).
AddMetric("total", metrics.NewInt(result.total)).
AddMetric("success", metrics.NewInt(result.success)).
AddMetric(opts.LatencyMetricName, result.latency).
AddMetric(opts.LatencyMetricName, result.latency.Clone()).
AddLabel("ptype", "tcp")

if result.validationFailure != nil {
Expand Down

0 comments on commit 00d71c6

Please sign in to comment.