Skip to content

Commit

Permalink
ref: remove generic metrics ingestion (#534)
Browse files Browse the repository at this point in the history
* remove generic metrics ingestion

* update changelog
  • Loading branch information
viglia authored Nov 29, 2024
1 parent 7261703 commit 638be86
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 144 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 0 additions & 14 deletions cmd/vroom/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions cmd/vroom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ type environment struct {
metricSummaryWriter KafkaWriter

storage *blob.Bucket

metricsClient *http.Client
}

var (
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 0 additions & 15 deletions cmd/vroom/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
104 changes: 0 additions & 104 deletions cmd/vroom/utils.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 638be86

Please sign in to comment.