Skip to content

Commit 49a983c

Browse files
Eric Fritzsourcegraph-bot
authored andcommitted
sourcegraph: codeintel: Fix observability on upload/lsifstore (#44865)
Commit: d61f40b2f1aed793d13c393e66bf8d10fc8fff41
1 parent 022a54b commit 49a983c

5 files changed

Lines changed: 57 additions & 7 deletions

File tree

sourcegraph/enterprise/internal/codeintel/uploads/internal/lsifstore/lsifstore_delete.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88

99
"github.com/keegancsmith/sqlf"
10-
"github.com/opentracing/opentracing-go/log"
10+
otlog "github.com/opentracing/opentracing-go/log"
1111

1212
"github.com/sourcegraph/sourcegraph/internal/observation"
1313
)
@@ -28,9 +28,9 @@ var tableNames = []string{
2828

2929
// DeleteLsifDataByUploadIds deletes LSIF data by UploadIds from the lsif database.
3030
func (s *store) DeleteLsifDataByUploadIds(ctx context.Context, bundleIDs ...int) (err error) {
31-
ctx, trace, endObservation := s.operations.deleteLsifDataByUploadIds.With(ctx, &err, observation.Args{LogFields: []log.Field{
32-
log.Int("numBundleIDs", len(bundleIDs)),
33-
log.String("bundleIDs", intsToString(bundleIDs)),
31+
ctx, trace, endObservation := s.operations.deleteLsifDataByUploadIds.With(ctx, &err, observation.Args{LogFields: []otlog.Field{
32+
otlog.Int("numBundleIDs", len(bundleIDs)),
33+
otlog.String("bundleIDs", intsToString(bundleIDs)),
3434
}})
3535
defer endObservation(1, observation.Args{})
3636

@@ -57,7 +57,7 @@ func (s *store) DeleteLsifDataByUploadIds(ctx context.Context, bundleIDs ...int)
5757
}()
5858

5959
for _, tableName := range tableNames {
60-
trace.Log(log.String("tableName", tableName))
60+
trace.Log(otlog.String("tableName", tableName))
6161

6262
query := sqlf.Sprintf(deleteQuery, sqlf.Sprintf(tableName), sqlf.Join(ids, ","))
6363
if err := tx.Exec(ctx, query); err != nil {

sourcegraph/enterprise/internal/codeintel/uploads/internal/lsifstore/lsifstore_documents.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ import (
44
"context"
55

66
"github.com/keegancsmith/sqlf"
7+
otlog "github.com/opentracing/opentracing-go/log"
78

89
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
10+
"github.com/sourcegraph/sourcegraph/internal/observation"
911
)
1012

1113
const documentsLimit = 100
1214

13-
func (s *store) GetUploadDocumentsForPath(ctx context.Context, bundleID int, pathPattern string) ([]string, int, error) {
15+
func (s *store) GetUploadDocumentsForPath(ctx context.Context, bundleID int, pathPattern string) (_ []string, _ int, err error) {
16+
ctx, _, endObservation := s.operations.getUploadDocumentsForPath.With(ctx, &err, observation.Args{LogFields: []otlog.Field{
17+
otlog.Int("bundleID", bundleID),
18+
otlog.String("pathPattern", pathPattern),
19+
}})
20+
defer endObservation(1, observation.Args{})
21+
1422
totalCount, _, err := basestore.ScanFirstInt(s.db.Query(ctx, sqlf.Sprintf(documentsCountQuery, bundleID, pathPattern)))
1523
if err != nil {
1624
return nil, 0, err

sourcegraph/enterprise/internal/codeintel/uploads/internal/lsifstore/lsifstore_reconcile.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ import (
55

66
"github.com/keegancsmith/sqlf"
77
"github.com/lib/pq"
8+
otlog "github.com/opentracing/opentracing-go/log"
89

910
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
11+
"github.com/sourcegraph/sourcegraph/internal/observation"
1012
)
1113

12-
func (s *store) IDsWithMeta(ctx context.Context, ids []int) (_ []int, error error) {
14+
func (s *store) IDsWithMeta(ctx context.Context, ids []int) (_ []int, err error) {
15+
ctx, _, endObservation := s.operations.idsWithMeta.With(ctx, &err, observation.Args{LogFields: []otlog.Field{
16+
otlog.Int("numIDs", len(ids)),
17+
otlog.String("ids", intsToString(ids)),
18+
}})
19+
defer endObservation(1, observation.Args{})
20+
1321
return basestore.ScanInts(s.db.Query(ctx, sqlf.Sprintf(idsWithMetaQuery, pq.Array(ids))))
1422
}
1523

@@ -18,6 +26,11 @@ SELECT m.dump_id FROM lsif_data_metadata m WHERE m.dump_id = ANY(%s)
1826
`
1927

2028
func (s *store) ReconcileCandidates(ctx context.Context, batchSize int) (_ []int, err error) {
29+
ctx, _, endObservation := s.operations.reconcileCandidates.With(ctx, &err, observation.Args{LogFields: []otlog.Field{
30+
otlog.Int("batchSize", batchSize),
31+
}})
32+
defer endObservation(1, observation.Args{})
33+
2134
return basestore.ScanInts(s.db.Query(ctx, sqlf.Sprintf(reconcileQuery, batchSize)))
2235
}
2336

sourcegraph/enterprise/internal/codeintel/uploads/internal/lsifstore/observability.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import (
99

1010
type operations struct {
1111
deleteLsifDataByUploadIds *observation.Operation
12+
idsWithMeta *observation.Operation
13+
reconcileCandidates *observation.Operation
14+
getUploadDocumentsForPath *observation.Operation
15+
scanDocuments *observation.Operation
16+
scanResultChunks *observation.Operation
17+
scanLocations *observation.Operation
1218
writeMeta *observation.Operation
1319
writeDocuments *observation.Operation
1420
writeResultChunks *observation.Operation
@@ -35,6 +41,12 @@ func newOperations(observationContext *observation.Context) *operations {
3541

3642
return &operations{
3743
deleteLsifDataByUploadIds: op("DeleteLsifDataByUploadIds"),
44+
idsWithMeta: op("IDsWithMeta"),
45+
reconcileCandidates: op("ReconcileCandidates"),
46+
getUploadDocumentsForPath: op("GetUploadDocumentsForPath"),
47+
scanDocuments: op("ScanDocuments"),
48+
scanResultChunks: op("ScanResultChunks"),
49+
scanLocations: op("ScanLocations"),
3850
writeMeta: op("WriteMeta"),
3951
writeDocuments: op("WriteDocuments"),
4052
writeResultChunks: op("WriteResultChunks"),

sourcegraph/enterprise/internal/codeintel/uploads/internal/lsifstore/stream.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import (
44
"context"
55

66
"github.com/keegancsmith/sqlf"
7+
otlog "github.com/opentracing/opentracing-go/log"
78

89
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
910
"github.com/sourcegraph/sourcegraph/internal/database/dbutil"
11+
"github.com/sourcegraph/sourcegraph/internal/observation"
1012
"github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
1113
)
1214

1315
func (s *store) ScanDocuments(ctx context.Context, id int, f func(path string, ranges map[precise.ID]precise.RangeData) error) (err error) {
16+
ctx, _, endObservation := s.operations.scanDocuments.With(ctx, &err, observation.Args{LogFields: []otlog.Field{
17+
otlog.Int("id", id),
18+
}})
19+
defer endObservation(1, observation.Args{})
20+
1421
return runQuery(ctx, s.db, sqlf.Sprintf(scanDocumentsQuery, id), func(dbs dbutil.Scanner) error {
1522
var path string
1623
var rawRanges []byte
@@ -35,6 +42,11 @@ ORDER BY path
3542
`
3643

3744
func (s *store) ScanResultChunks(ctx context.Context, id int, f func(idx int, resultChunk precise.ResultChunkData) error) (err error) {
45+
ctx, _, endObservation := s.operations.scanResultChunks.With(ctx, &err, observation.Args{LogFields: []otlog.Field{
46+
otlog.Int("id", id),
47+
}})
48+
defer endObservation(1, observation.Args{})
49+
3850
return runQuery(ctx, s.db, sqlf.Sprintf(scanResultChunksQuery, id), func(dbs dbutil.Scanner) error {
3951
var idx int
4052
var rawData []byte
@@ -59,6 +71,11 @@ ORDER BY idx
5971
`
6072

6173
func (s *store) ScanLocations(ctx context.Context, id int, f func(scheme, identifier, monikerType string, locations []precise.LocationData) error) (err error) {
74+
ctx, _, endObservation := s.operations.scanLocations.With(ctx, &err, observation.Args{LogFields: []otlog.Field{
75+
otlog.Int("id", id),
76+
}})
77+
defer endObservation(1, observation.Args{})
78+
6279
return runQuery(ctx, s.db, sqlf.Sprintf(scanLocationsQuery, id, id), func(dbs dbutil.Scanner) error {
6380
var scheme, identifier, monikerType string
6481
var rawData []byte

0 commit comments

Comments
 (0)