Skip to content

Commit aa3772c

Browse files
committed
fix code review comments
Signed-off-by: shankeerthan-kasilingam <shankeerthan1995@gmail.com>
1 parent 573a48d commit aa3772c

6 files changed

Lines changed: 40 additions & 52 deletions

File tree

pkg/debuginfo/metadata.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/go-kit/log"
2626
"github.com/go-kit/log/level"
27+
"github.com/prometheus/client_golang/prometheus"
2728
"github.com/thanos-io/objstore"
2829
)
2930

@@ -90,10 +91,28 @@ type ObjectStoreMetadata struct {
9091
logger log.Logger
9192

9293
bucket objstore.Bucket
94+
95+
metadataUpdateDuration prometheus.Histogram
9396
}
9497

95-
func NewObjectStoreMetadata(logger log.Logger, bucket objstore.Bucket) *ObjectStoreMetadata {
96-
return &ObjectStoreMetadata{logger: log.With(logger, "component", "debuginfo-metadata"), bucket: bucket}
98+
func NewObjectStoreMetadata(
99+
logger log.Logger,
100+
reg prometheus.Registerer,
101+
bucket objstore.Bucket,
102+
) *ObjectStoreMetadata {
103+
metadataUpdateDuration := prometheus.NewHistogram(
104+
prometheus.HistogramOpts{
105+
Name: "debuginfo_metadata_update_duration_seconds",
106+
Help: "How long it took in seconds to finish updating metadata.",
107+
Buckets: []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120},
108+
},
109+
)
110+
111+
return &ObjectStoreMetadata{
112+
logger: log.With(logger, "component", "debuginfo-metadata"),
113+
bucket: bucket,
114+
metadataUpdateDuration: metadataUpdateDuration,
115+
}
97116
}
98117

99118
type Metadata struct {
@@ -170,6 +189,7 @@ func (m *ObjectStoreMetadata) MarkAsUploaded(ctx context.Context, buildID, hash
170189
metaData.BuildID = buildID
171190
metaData.Hash = hash
172191
metaData.UploadFinishedAt = time.Now().Unix()
192+
m.metadataUpdateDuration.Observe(time.Unix(metaData.UploadFinishedAt, 0).Sub(time.Unix(metaData.UploadStartedAt, 0)).Seconds())
173193

174194
metadataBytes, _ := json.MarshalIndent(&metaData, "", "\t")
175195
newData := bytes.NewReader(metadataBytes)

pkg/debuginfo/metadata_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestMetadata(t *testing.T) {
5757
logger,
5858
prometheus.NewRegistry(),
5959
cacheDir,
60-
NewObjectStoreMetadata(logger, bucket),
60+
NewObjectStoreMetadata(logger, prometheus.NewRegistry(), bucket),
6161
bucket,
6262
NopDebugInfodClient{},
6363
)

pkg/debuginfo/store.go

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ type Store struct {
8181
metadata MetadataManager
8282
debuginfodClient DebugInfodClient
8383

84-
validationAttemptsTotal prometheus.Counter
85-
validationErrorsTotal prometheus.CounterVec
86-
metadataUpdateDuration prometheus.Histogram
87-
uploadDebugInfoAttemptsTotal prometheus.Counter
88-
uploadDebugInfoErrorsTotal prometheus.CounterVec
89-
uploadDebugInfoDuration prometheus.Histogram
84+
debugInfoUploadAttemptsTotal prometheus.Counter
85+
debugInfoUploadErrorsTotal prometheus.CounterVec
86+
debugInfoUploadDuration prometheus.Histogram
9087
existsCheckDuration prometheus.Histogram
9188
}
9289

@@ -100,20 +97,20 @@ func NewStore(
10097
bucket objstore.Bucket,
10198
debuginfodClient DebugInfodClient,
10299
) (*Store, error) {
103-
uploadDebugInfoAttemptsTotal := prometheus.NewCounter(
100+
debugInfoUploadAttemptsTotal := prometheus.NewCounter(
104101
prometheus.CounterOpts{
105102
Name: "debuginfo_upload_attempts_total",
106103
Help: "Total attempts to upload debuginfo.",
107104
},
108105
)
109-
uploadDebugInfoErrorsTotal := prometheus.NewCounterVec(
106+
debugInfoUploadErrorsTotal := prometheus.NewCounterVec(
110107
prometheus.CounterOpts{
111108
Name: "debuginfo_upload_errors_total",
112109
Help: "Total number of errors in uploading debuginfo.",
113110
},
114111
[]string{"reason"},
115112
)
116-
uploadDebugInfoDuration := prometheus.NewHistogram(
113+
debugInfoUploadDuration := prometheus.NewHistogram(
117114
prometheus.HistogramOpts{
118115
Name: "debuginfo_upload_duration_seconds",
119116
Help: "How long it took in seconds to upload debuginfo.",
@@ -129,39 +126,16 @@ func NewStore(
129126
},
130127
)
131128

132-
metadataUpdateDuration := prometheus.NewHistogram(
133-
prometheus.HistogramOpts{
134-
Name: "debuginfo_metadata_update_duration_seconds",
135-
Help: "How long it took in seconds to finish updating metadata.",
136-
Buckets: []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120},
137-
},
138-
)
139-
validationAttemptsTotal := prometheus.NewCounter(
140-
prometheus.CounterOpts{
141-
Name: "debuginfo_validate_object_file_attempts_total",
142-
Help: "Total number of validation of object file.",
143-
},
144-
)
145-
validationErrorsTotal := prometheus.NewCounterVec(
146-
prometheus.CounterOpts{
147-
Name: "debuginfo_validate_object_file_errors_total",
148-
Help: "Total number of errors in validationg object file.",
149-
},
150-
[]string{"reason"},
151-
)
152129
return &Store{
153130
tracer: tracer,
154131
logger: log.With(logger, "component", "debuginfo"),
155132
bucket: bucket,
156133
cacheDir: cacheDir,
157134
metadata: metadata,
158135
debuginfodClient: debuginfodClient,
159-
metadataUpdateDuration: metadataUpdateDuration,
160-
validationAttemptsTotal: validationAttemptsTotal,
161-
validationErrorsTotal: *validationErrorsTotal,
162-
uploadDebugInfoAttemptsTotal: uploadDebugInfoAttemptsTotal,
163-
uploadDebugInfoErrorsTotal: *uploadDebugInfoErrorsTotal,
164-
uploadDebugInfoDuration: uploadDebugInfoDuration,
136+
debugInfoUploadAttemptsTotal: debugInfoUploadAttemptsTotal,
137+
debugInfoUploadErrorsTotal: *debugInfoUploadErrorsTotal,
138+
debugInfoUploadDuration: debugInfoUploadDuration,
165139
existsCheckDuration: existsCheckDuration,
166140
}, nil
167141
}
@@ -210,12 +184,12 @@ func (s *Store) Exists(ctx context.Context, req *debuginfopb.ExistsRequest) (*de
210184

211185
func (s *Store) Upload(stream debuginfopb.DebugInfoService_UploadServer) error {
212186
defer func(begin time.Time) {
213-
s.uploadDebugInfoDuration.Observe(time.Since(begin).Seconds())
187+
s.debugInfoUploadDuration.Observe(time.Since(begin).Seconds())
214188
}(time.Now())
215-
s.uploadDebugInfoAttemptsTotal.Inc()
189+
s.debugInfoUploadAttemptsTotal.Inc()
216190
req, err := stream.Recv()
217191
if err != nil {
218-
s.uploadDebugInfoErrorsTotal.WithLabelValues("stream_receive").Inc()
192+
s.debugInfoUploadErrorsTotal.WithLabelValues("stream_receive").Inc()
219193
msg := "failed to receive upload info"
220194
level.Error(s.logger).Log("msg", msg, "err", err)
221195
return status.Errorf(codes.Unknown, msg)
@@ -233,7 +207,7 @@ func (s *Store) Upload(stream debuginfopb.DebugInfoService_UploadServer) error {
233207
span.SetAttributes(attribute.String("hash", hash))
234208

235209
if err := s.upload(ctx, buildID, hash, r); err != nil {
236-
s.uploadDebugInfoErrorsTotal.WithLabelValues("store_upload").Inc()
210+
s.debugInfoUploadErrorsTotal.WithLabelValues("store_upload").Inc()
237211
return err
238212
}
239213

@@ -298,14 +272,13 @@ func (s *Store) upload(ctx context.Context, buildID, hash string, r io.Reader) e
298272
if err != nil {
299273
return status.Error(codes.Internal, err.Error())
300274
}
301-
s.validationAttemptsTotal.Inc()
302275
if err := elfutils.ValidateFile(objFile); err != nil {
276+
s.debugInfoUploadErrorsTotal.WithLabelValues("validation").Inc()
303277
// Failed to validate. Mark the file as corrupted, and let the client try to upload it again.
304278
if err := s.metadata.MarkAsCorrupted(ctx, buildID); err != nil {
305279
level.Warn(s.logger).Log("msg", "failed to update metadata as corrupted", "err", err)
306280
}
307281
level.Error(s.logger).Log("msg", "failed to validate object file", "buildid", buildID)
308-
s.validationErrorsTotal.WithLabelValues("validate_object_file").Inc()
309282
// Client will retry.
310283
return status.Error(codes.Internal, err.Error())
311284
}
@@ -318,7 +291,6 @@ func (s *Store) upload(ctx context.Context, buildID, hash string, r io.Reader) e
318291
hasDWARF, err := elfutils.HasDWARF(f)
319292
if err != nil {
320293
level.Debug(s.logger).Log("msg", "failed to check for DWARF", "err", err)
321-
s.validationErrorsTotal.WithLabelValues("has_dwarf_object_file").Inc()
322294
}
323295
f.Close()
324296
if hasDWARF {
@@ -329,9 +301,6 @@ func (s *Store) upload(ctx context.Context, buildID, hash string, r io.Reader) e
329301

330302
// At this point we know that we received a better version of the debug information file,
331303
// so let the client upload it.
332-
defer func(begin time.Time) {
333-
s.metadataUpdateDuration.Observe(time.Since(begin).Seconds())
334-
}(time.Now())
335304
if err := s.metadata.MarkAsUploading(ctx, buildID); err != nil {
336305
err = fmt.Errorf("failed to update metadata before uploading: %w", err)
337306
return status.Error(codes.Internal, err.Error())
@@ -357,7 +326,6 @@ func (s *Store) upload(ctx context.Context, buildID, hash string, r io.Reader) e
357326
}
358327

359328
if err := elfutils.ValidateHeader(b); err != nil {
360-
s.validationErrorsTotal.WithLabelValues("validate_header_object_file").Inc()
361329
// Failed to validate. Mark the incoming stream as corrupted, and let the client try to upload it again.
362330
if err := s.metadata.MarkAsCorrupted(ctx, buildID); err != nil {
363331
err = fmt.Errorf("failed to update metadata after uploaded, as corrupted: %w", err)

pkg/debuginfo/store_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestStore(t *testing.T) {
6464
logger,
6565
prometheus.NewRegistry(),
6666
cacheDir,
67-
NewObjectStoreMetadata(logger, bucket),
67+
NewObjectStoreMetadata(logger, prometheus.NewRegistry(), bucket),
6868
bucket,
6969
NopDebugInfodClient{},
7070
)

pkg/parca/parca.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func Run(ctx context.Context, logger log.Logger, reg *prometheus.Registry, flags
310310
}
311311
}
312312

313-
dbgInfoMetadata := debuginfo.NewObjectStoreMetadata(logger, bucket)
313+
dbgInfoMetadata := debuginfo.NewObjectStoreMetadata(logger, reg, bucket)
314314
dbgInfo, err := debuginfo.NewStore(
315315
tracerProvider.Tracer("debuginfo"),
316316
logger,

pkg/symbolizer/symbolizer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func setup(t *testing.T) (*grpc.ClientConn, pb.MetastoreServiceClient, *Symboliz
453453
bucket, err := client.NewBucket(logger, cfg, prometheus.NewRegistry(), "parca/store")
454454
require.NoError(t, err)
455455

456-
metadata := debuginfo.NewObjectStoreMetadata(logger, bucket)
456+
metadata := debuginfo.NewObjectStoreMetadata(logger, prometheus.NewRegistry(), bucket)
457457
dbgStr, err := debuginfo.NewStore(
458458
tracer,
459459
logger,

0 commit comments

Comments
 (0)