Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a metric for counting metrics received. #985

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Config struct {
type Features struct {
DiagnosticsMetricsEnabled bool `yaml:"diagnostics_metrics_enabled"`
EnableMetricSinkRouting bool `yaml:"enable_metric_sink_routing"`
EnableSourceMetricCount bool `yaml:"enable_source_metric_count"`
}

type HttpConfig struct {
Expand Down
42 changes: 33 additions & 9 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,23 @@ func scopesFromConfig(conf Config) (scopedstatsd.MetricScopes, error) {
}

type ingest struct {
server *Server
tags []string
sourceName string
server *Server
tags []string
}

var _ sources.Ingest = &ingest{}

func (ingest *ingest) IngestMetric(metric *samplers.UDPMetric) {
metric.Tags = append(metric.Tags, ingest.tags...)

if ingest.server.Config.Features.EnableSourceMetricCount {
ingest.server.Statsd.Count(
"source.metrics_count", int64(1), []string{
"protocol:udp",
"source:" + ingest.sourceName,
}, 1.0)
}
ingest.server.ingestMetric(metric)
}

Expand All @@ -349,8 +358,15 @@ func (ingest *ingest) IngestMetricProto(metric *metricpb.Metric) {
for _, tag := range metric.Tags {
h = fnv1a.AddString32(h, tag)
}

workerIndex := h % uint32(len(ingest.server.Workers))

if ingest.server.Config.Features.EnableSourceMetricCount {
ingest.server.Statsd.Count(
"source.metrics_count", int64(1), []string{
"protocol:proto",
"source:" + ingest.sourceName,
}, 1.0)
}
ingest.server.Workers[workerIndex].ImportMetricChan <- metric
}

Expand Down Expand Up @@ -510,20 +526,27 @@ func NewFromConfig(config ServerConfig) (*Server, error) {
}
ret.HistogramAggregates.Count = len(conf.Aggregates)

stats, err := statsd.New(conf.StatsAddress, statsd.WithoutTelemetry(), statsd.WithMaxMessagesPerPayload(4096))
statsClient, err := statsd.New(
conf.StatsAddress,
statsd.WithAggregationInterval(conf.Interval),
statsd.WithChannelMode(),
statsd.WithChannelModeBufferSize(64),
statsd.WithClientSideAggregation(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turning on client side aggregation appears to be breaking tests

statsd.WithMaxMessagesPerPayload(4096),
statsd.WithoutTelemetry())
if err != nil {
return ret, err
}
stats.Namespace = "veneur."
statsClient.Namespace = "veneur."

scopes, err := scopesFromConfig(conf)
if err != nil {
return ret, err
}
ret.Statsd = scopedstatsd.NewClient(stats, conf.VeneurMetricsAdditionalTags, scopes)
ret.Statsd = scopedstatsd.NewClient(statsClient, conf.VeneurMetricsAdditionalTags, scopes)

ret.TraceClient, err = trace.NewChannelClient(ret.SpanChan,
trace.ReportStatistics(stats, 1*time.Second, []string{"ssf_format:internal"}),
trace.ReportStatistics(statsClient, 1*time.Second, []string{"ssf_format:internal"}),
normalizeSpans(conf),
)
if err != nil {
Expand Down Expand Up @@ -1343,8 +1366,9 @@ func (s *Server) Serve() {
for _, source := range s.sources {
go func(source internalSource) {
source.source.Start(&ingest{
server: s,
tags: source.tags,
sourceName: source.source.Name(),
server: s,
tags: source.tags,
})
done <- struct{}{}
}(source)
Expand Down
3 changes: 2 additions & 1 deletion testdata/http_test_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"ExtendTags": null,
"Features": {
"DiagnosticsMetricsEnabled": false,
"EnableMetricSinkRouting": false
"EnableMetricSinkRouting": false,
"EnableSourceMetricCount": false
},
"FlushOnShutdown": false,
"FlushWatchdogMissedFlushes": 0,
Expand Down
1 change: 1 addition & 0 deletions testdata/http_test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extend_tags: []
features:
diagnostics_metrics_enabled: false
enable_metric_sink_routing: false
enable_source_metric_count: false
flush_on_shutdown: false
flush_watchdog_missed_flushes: 0
forward_address: ""
Expand Down