Skip to content

Commit

Permalink
Provide an option to change the latency metric name. (cloudprober#669)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 401625320
  • Loading branch information
manugarg authored Oct 7, 2021
1 parent b5860e3 commit 9b743cb
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 104 deletions.
4 changes: 3 additions & 1 deletion probes/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ type probeRunResult struct {
latency metrics.Value
timeouts metrics.Int
validationFailure *metrics.Map
latencyMetricName string
}

// Metrics converts probeRunResult into metrics.EventMetrics object
func (prr probeRunResult) Metrics() *metrics.EventMetrics {
return metrics.NewEventMetrics(time.Now()).
AddMetric("total", &prr.total).
AddMetric("success", &prr.success).
AddMetric("latency", prr.latency).
AddMetric(prr.latencyMetricName, prr.latency).
AddMetric("timeouts", &prr.timeouts).
AddMetric("validation_failure", prr.validationFailure)
}
Expand Down Expand Up @@ -217,6 +218,7 @@ func (p *Probe) runProbe(resultsChan chan<- statskeeper.ProbeResult, resolveF re

result := probeRunResult{
target: target.Name,
latencyMetricName: p.opts.LatencyMetricName,
validationFailure: validators.ValidationFailureMap(p.opts.Validators),
}

Expand Down
2 changes: 1 addition & 1 deletion probes/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,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("latency", result.latency).
AddMetric(p.opts.LatencyMetricName, result.latency).
AddLabel("ptype", "external").
AddLabel("probe", p.name).
AddLabel("dst", target)
Expand Down
7 changes: 4 additions & 3 deletions probes/external/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ func createTestProbe(cmd string) *Probe {
}

p.Init("testProbe", &options.Options{
ProbeConf: probeConf,
Timeout: 1 * time.Second,
LogMetrics: func(em *metrics.EventMetrics) {},
ProbeConf: probeConf,
Timeout: 1 * time.Second,
LogMetrics: func(em *metrics.EventMetrics) {},
LatencyMetricName: "latency",
})

return p
Expand Down
3 changes: 1 addition & 2 deletions probes/external/serverutils/serverutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ func WriteMessage(pb proto.Message, w io.Writer) error {
// make use of it. Example usage:
// import (
// serverpb "github.com/google/cloudprober/probes/external/proto"
// "github.com/google/cloudprober/probes/external/serverutils"
// "google.golang.org/protobuf/proto"
// "github.com/google/cloudprober/probes/external/serverutils"
// )
// func runProbe(opts []*cppb.ProbeRequest_Option) {
// ...
Expand Down
2 changes: 1 addition & 1 deletion probes/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (p *Probe) Start(ctx context.Context, dataChan chan *metrics.EventMetrics)
em := metrics.NewEventMetrics(ts).
AddMetric("total", result.total.Clone()).
AddMetric("success", result.success.Clone()).
AddMetric("latency", result.latency.Clone()).
AddMetric(p.opts.LatencyMetricName, result.latency.Clone()).
AddMetric("connecterrors", result.connectErrors.Clone()).
AddLabel("ptype", "grpc").
AddLabel("probe", p.name).
Expand Down
2 changes: 1 addition & 1 deletion probes/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (p *Probe) exportMetrics(ts time.Time, result *probeResult, targetName stri
em := metrics.NewEventMetrics(ts).
AddMetric("total", metrics.NewInt(result.total)).
AddMetric("success", metrics.NewInt(result.success)).
AddMetric("latency", result.latency).
AddMetric(p.opts.LatencyMetricName, result.latency).
AddMetric("timeouts", metrics.NewInt(result.timeouts)).
AddMetric("resp-code", result.respCodes).
AddLabel("ptype", "http").
Expand Down
8 changes: 5 additions & 3 deletions probes/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Options struct {
ProbeConf interface{} // Probe-type specific config
LatencyDist *metrics.Distribution
LatencyUnit time.Duration
LatencyMetricName string
Validators []*validators.Validator
SourceIP net.IP
IPVersion int
Expand Down Expand Up @@ -113,9 +114,10 @@ func getSourceIPFromConfig(p *configpb.ProbeDef, l *logger.Logger) (net.IP, erro
// global params.
func BuildProbeOptions(p *configpb.ProbeDef, ldLister endpoint.Lister, globalTargetsOpts *targetspb.GlobalTargetsOptions, l *logger.Logger) (*Options, error) {
opts := &Options{
Interval: time.Duration(p.GetIntervalMsec()) * time.Millisecond,
Timeout: time.Duration(p.GetTimeoutMsec()) * time.Millisecond,
IPVersion: ipv(p.IpVersion),
Interval: time.Duration(p.GetIntervalMsec()) * time.Millisecond,
Timeout: time.Duration(p.GetTimeoutMsec()) * time.Millisecond,
IPVersion: ipv(p.IpVersion),
LatencyMetricName: p.GetLatencyMetricName(),
}

var err error
Expand Down
2 changes: 1 addition & 1 deletion probes/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,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(result.rcvd)).
AddMetric("latency", result.latency).
AddMetric(p.opts.LatencyMetricName, result.latency).
AddLabel("ptype", "ping").
AddLabel("probe", p.name).
AddLabel("dst", target.Name)
Expand Down
Loading

0 comments on commit 9b743cb

Please sign in to comment.