From 638be862fffe2fcc0e88be0f24a1b40303024ec4 Mon Sep 17 00:00:00 2001 From: viglia Date: Fri, 29 Nov 2024 11:36:13 +0100 Subject: [PATCH] ref: remove generic metrics ingestion (#534) * remove generic metrics ingestion * update changelog --- CHANGELOG.md | 1 + cmd/vroom/chunk.go | 14 ------ cmd/vroom/main.go | 11 ----- cmd/vroom/profile.go | 15 ------- cmd/vroom/utils.go | 104 ------------------------------------------- 5 files changed, 1 insertion(+), 144 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a799df8..03ec34c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ - Support writing functions metrics we extract from chunks into the functions dataset ([#524](https://github.com/getsentry/vroom/pull/524)) - Keep top N samples in flamegraph. ([#526](https://github.com/getsentry/vroom/pull/526)) - Remove unused legacy flamegraph code path. ([#533](https://github.com/getsentry/vroom/pull/533)) +- Remove generic metrics ingestion ([#534](https://github.com/getsentry/vroom/pull/534)) ## 23.12.0 diff --git a/cmd/vroom/chunk.go b/cmd/vroom/chunk.go index 3c90d4c..0839d2d 100644 --- a/cmd/vroom/chunk.go +++ b/cmd/vroom/chunk.go @@ -192,20 +192,6 @@ func (env *environment) postChunk(w http.ResponseWriter, r *http.Request) { hub.CaptureException(err) } } - - // this block is writing into the generic metrics dataset - // TODO: remove once we fully move to functions dataset - s = sentry.StartSpan(ctx, "processing") - s.Description = "Extract metrics from functions" - metrics := extractMetricsFromSampleChunkFunctions(sc, functions) - s.Finish() - - if len(metrics) > 0 { - s = sentry.StartSpan(ctx, "processing") - s.Description = "Send functions metrics to generic metrics platform" - sendMetrics(ctx, options.ProjectDSN, metrics, env.metricsClient) - s.Finish() - } } w.WriteHeader(http.StatusNoContent) diff --git a/cmd/vroom/main.go b/cmd/vroom/main.go index 6f4f7e8..385eca7 100644 --- a/cmd/vroom/main.go +++ b/cmd/vroom/main.go @@ -37,8 +37,6 @@ type environment struct { metricSummaryWriter KafkaWriter storage *blob.Bucket - - metricsClient *http.Client } var ( @@ -83,15 +81,6 @@ func newEnvironment() (*environment, error) { ReadTimeout: 3 * time.Second, WriteTimeout: 3 * time.Second, } - e.metricsClient = &http.Client{ - Timeout: time.Second * 5, - Transport: &http.Transport{ - MaxIdleConns: 100, - MaxIdleConnsPerHost: 100, - MaxConnsPerHost: 100, - IdleConnTimeout: time.Second * 60, - }, - } return &e, nil } diff --git a/cmd/vroom/profile.go b/cmd/vroom/profile.go index bfc8d5a..37c492f 100644 --- a/cmd/vroom/profile.go +++ b/cmd/vroom/profile.go @@ -181,21 +181,6 @@ func (env *environment) postProfile(w http.ResponseWriter, r *http.Request) { if err != nil { hub.CaptureException(err) } - if p.GetOptions().ProjectDSN != "" { - s = sentry.StartSpan(ctx, "processing") - s.Description = "Extract metrics from functions" - // Cap and filter out system frames. - functionsMetricPlatform := metrics.CapAndFilterFunctions(functions, maxUniqueFunctionsPerProfile, true) - metrics, _ := extractMetricsFromFunctions(&p, functionsMetricPlatform) - s.Finish() - - if len(metrics) > 0 { - s = sentry.StartSpan(ctx, "processing") - s.Description = "Send functions metrics to generic metrics platform" - sendMetrics(ctx, p.GetOptions().ProjectDSN, metrics, env.metricsClient) - s.Finish() - } - } } if p.IsSampled() { diff --git a/cmd/vroom/utils.go b/cmd/vroom/utils.go index 3689020..32871fe 100644 --- a/cmd/vroom/utils.go +++ b/cmd/vroom/utils.go @@ -1,112 +1,8 @@ package main -import ( - "context" - "net/http" - "strconv" - "strings" - "time" - - "github.com/google/uuid" - - "github.com/getsentry/sentry-go" - "github.com/getsentry/vroom/internal/chunk" - "github.com/getsentry/vroom/internal/nodetree" - "github.com/getsentry/vroom/internal/profile" -) - -func extractMetricsFromFunctions(p *profile.Profile, functions []nodetree.CallTreeFunction) ([]sentry.Metric, []MetricSummary) { - metrics := make([]sentry.Metric, 0, len(functions)) - metricsSummary := make([]MetricSummary, 0, len(functions)) - - for _, function := range functions { - if len(function.SelfTimesNS) == 0 { - continue - } - tags := map[string]string{ - "project_id": strconv.FormatUint(p.ProjectID(), 10), - "fingerprint": strconv.FormatUint(uint64(function.Fingerprint), 10), - "function": function.Function, - "package": function.Package, - "is_application": strconv.FormatBool(function.InApp), - "platform": string(p.Platform()), - "environment": p.Environment(), - "release": p.Release(), - "profile_type": "transaction", - } - duration := float64(function.SelfTimesNS[0] / 1e6) - summary := MetricSummary{ - Min: duration, - Max: duration, - Sum: duration, - Count: 1, - } - dm := sentry.NewDistributionMetric("profiles/function.duration", sentry.MilliSecond(), tags, p.Metadata().Timestamp, duration) - // loop remaining selfTime durations - for i := 1; i < len(function.SelfTimesNS); i++ { - duration := float64(function.SelfTimesNS[i] / 1e6) - dm.Add(duration) - summary.Min = min(summary.Min, duration) - summary.Max = max(summary.Max, duration) - summary.Sum = summary.Sum + duration - summary.Count = summary.Count + 1 - } - metrics = append(metrics, dm) - metricsSummary = append(metricsSummary, summary) - } - return metrics, metricsSummary -} - -func sendMetrics(ctx context.Context, dsn string, metrics []sentry.Metric, mClient *http.Client) { - id := strings.Replace(uuid.New().String(), "-", "", -1) - e := sentry.NewEvent() - e.EventID = sentry.EventID(id) - e.Type = "statsd" - e.Metrics = metrics - tr := sentry.NewHTTPSyncTransport() - tr.Timeout = 5 * time.Second - tr.Configure(sentry.ClientOptions{ - Dsn: dsn, - HTTPTransport: mClient.Transport, - HTTPClient: mClient, - }) - - tr.SendEventWithContext(ctx, e) -} - type MetricSummary struct { Min float64 Max float64 Sum float64 Count uint64 } - -func extractMetricsFromSampleChunkFunctions(c *chunk.SampleChunk, functions []nodetree.CallTreeFunction) []sentry.Metric { - metrics := make([]sentry.Metric, 0, len(functions)) - - for _, function := range functions { - if len(function.SelfTimesNS) == 0 { - continue - } - tags := map[string]string{ - "project_id": strconv.FormatUint(c.ProjectID, 10), - "fingerprint": strconv.FormatUint(uint64(function.Fingerprint), 10), - "function": function.Function, - "package": function.Package, - "is_application": strconv.FormatBool(function.InApp), - "platform": string(c.Platform), - "environment": c.Environment, - "release": c.Release, - "profile_type": "continuous", - } - duration := float64(function.SelfTimesNS[0] / 1e6) - dm := sentry.NewDistributionMetric("profiles/function.duration", sentry.MilliSecond(), tags, int64(c.Received), duration) - // loop remaining selfTime durations - for i := 1; i < len(function.SelfTimesNS); i++ { - duration := float64(function.SelfTimesNS[i] / 1e6) - dm.Add(duration) - } - metrics = append(metrics, dm) - } - return metrics -}