Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit c80b023

Browse files
sourcegraph-release-botunknwonbobheadxi
authored
[Backport 5.2] telemetry-export: add teestore, queue store metrics (#57256)
Co-authored-by: Joe Chen <[email protected]> Co-authored-by: Robert Lin <[email protected]>
1 parent f434aa2 commit c80b023

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

internal/database/telemetry_export_store.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package database
22

33
import (
44
"context"
5+
"strconv"
56
"time"
67

78
"go.opentelemetry.io/otel/attribute"
89
"google.golang.org/protobuf/proto"
910

1011
"github.com/lib/pq"
12+
"github.com/prometheus/client_golang/prometheus"
13+
"github.com/prometheus/client_golang/prometheus/promauto"
1114
"github.com/sourcegraph/log"
1215

1316
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
@@ -23,6 +26,13 @@ import (
2326
// queued for export via (TelemetryEventsExportQueueStore).QueueForExport
2427
const FeatureFlagTelemetryExport = "telemetry-export"
2528

29+
var counterQueuedEvents = promauto.NewCounterVec(prometheus.CounterOpts{
30+
Namespace: "src",
31+
Subsystem: "telemetry_export_store",
32+
Name: "queued_events",
33+
Help: "Events added to the telemetry export queue",
34+
}, []string{"failed"})
35+
2636
type TelemetryEventsExportQueueStore interface {
2737
basestore.ShareableStore
2838

@@ -80,7 +90,8 @@ func (s *telemetryEventsExportQueueStore) QueueForExport(ctx context.Context, ev
8090
if len(events) == 0 {
8191
return nil
8292
}
83-
return batch.InsertValues(ctx,
93+
94+
err := batch.InsertValues(ctx,
8495
s.Handle(),
8596
"telemetry_events_export_queue",
8697
batch.MaxNumPostgresParameters,
@@ -90,6 +101,10 @@ func (s *telemetryEventsExportQueueStore) QueueForExport(ctx context.Context, ev
90101
"payload_pb",
91102
},
92103
insertChannel(logger, events))
104+
counterQueuedEvents.
105+
WithLabelValues(strconv.FormatBool(err != nil)).
106+
Add(float64(len(events)))
107+
return err
93108
}
94109

95110
func insertChannel(logger log.Logger, events []*telemetrygatewayv1.Event) <-chan []any {

internal/telemetry/teestore/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ go_library(
1616
"//internal/telemetrygateway/v1:telemetrygateway",
1717
"//lib/errors",
1818
"//lib/pointers",
19+
"@com_github_prometheus_client_golang//prometheus",
20+
"@com_github_prometheus_client_golang//prometheus/promauto",
1921
"@com_github_sourcegraph_conc//pool",
2022
],
2123
)

internal/telemetry/teestore/teestore.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"strconv"
88
"time"
99

10+
"github.com/prometheus/client_golang/prometheus"
11+
"github.com/prometheus/client_golang/prometheus/promauto"
1012
"github.com/sourcegraph/conc/pool"
1113

1214
"github.com/sourcegraph/sourcegraph/internal/database"
@@ -17,6 +19,13 @@ import (
1719
"github.com/sourcegraph/sourcegraph/lib/pointers"
1820
)
1921

22+
var counterV1Events = promauto.NewCounterVec(prometheus.CounterOpts{
23+
Namespace: "src",
24+
Subsystem: "telemetry_teestore",
25+
Name: "v1_events",
26+
Help: "Events tee'd to the V1 event_logs table",
27+
}, []string{"failed"})
28+
2029
// Store tees events into both the event_logs table and the new telemetry export
2130
// queue, translating the message into the existing event_logs format on a
2231
// best-effort basis.
@@ -40,7 +49,11 @@ func (s *Store) StoreEvents(ctx context.Context, events []*telemetrygatewayv1.Ev
4049
})
4150
if !shouldDisableV1(ctx) {
4251
wg.Go(func() error {
43-
if err := s.eventLogs.BulkInsert(ctx, toEventLogs(time.Now, events)); err != nil {
52+
err := s.eventLogs.BulkInsert(ctx, toEventLogs(time.Now, events))
53+
counterV1Events.
54+
WithLabelValues(strconv.FormatBool(err != nil)).
55+
Add(float64(len(events)))
56+
if err != nil {
4457
return errors.Wrap(err, "bulk inserting events logs")
4558
}
4659
return nil

0 commit comments

Comments
 (0)