Skip to content

Commit

Permalink
chore(metarepos): do not use unnecessary labels (#445)
Browse files Browse the repository at this point in the history
### What this PR does

Because the metadata repository sets node id as resource `service.instance.id`, it does not need to
use a redundant label - `nodeid`.

### Which issue(s) this PR resolves

Resolve #423
  • Loading branch information
ijsong authored Jun 1, 2023
2 parents cb25d19 + 0d5c17a commit 3d7ff30
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cmd/varlogsn/varlogsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func initTelemetry(ctx context.Context, c *cli.Context, snid types.StorageNodeID
resource.WithAttributes(
semconv.ServiceNameKey.String("sn"),
semconv.ServiceNamespaceKey.String("varlog"),
semconv.ServiceInstanceIDKey.String(snid.String()),
semconv.ServiceInstanceIDKey.Int64(int64(snid)),
))
if err != nil {
return nil, nil, err
Expand Down
8 changes: 1 addition & 7 deletions internal/metarepos/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/wal"
"go.etcd.io/etcd/wal/walpb"
"go.opentelemetry.io/otel/attribute"
"go.uber.org/zap"

vtypes "github.com/kakao/varlog/pkg/types"
Expand Down Expand Up @@ -1008,11 +1007,6 @@ func (rc *raftNode) withTelemetry(ctx context.Context, name string, h handler) (
st := time.Now()
rsp, err := h(ctx)

rc.tmStub.mb.Records(name).Record(ctx,
float64(time.Since(st).Nanoseconds())/float64(time.Millisecond),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(rc.nodeID.String()),
})
rc.tmStub.mb.Records(name).Record(ctx, float64(time.Since(st).Nanoseconds())/float64(time.Millisecond))
return rsp, err
}
39 changes: 6 additions & 33 deletions internal/metarepos/raft_metadata_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go.etcd.io/etcd/pkg/fileutil"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.opentelemetry.io/otel/attribute"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -765,10 +764,7 @@ func (mr *RaftMetadataRepository) applyReport(reports *mrpb.Reports) error {

mr.tmStub.mb.Records("mr.raft.reports.delay").Record(context.TODO(),
float64(time.Since(reports.CreatedTime).Nanoseconds())/float64(time.Millisecond),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(mr.nodeID.String()),
})
)

for _, r := range reports.Reports {
snID := r.StorageNodeID
Expand Down Expand Up @@ -814,10 +810,7 @@ func (mr *RaftMetadataRepository) applyCommit(r *mrpb.Commit, appliedIndex uint6
if r != nil {
mr.tmStub.mb.Records("mr.raft.commit.delay").Record(context.TODO(),
float64(time.Since(r.CreatedTime).Nanoseconds())/float64(time.Millisecond),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(mr.nodeID.String()),
})
)
}

startTime := time.Now()
Expand All @@ -832,19 +825,11 @@ func (mr *RaftMetadataRepository) applyCommit(r *mrpb.Commit, appliedIndex uint6

crs := &mrpb.LogStreamCommitResults{}

mr.tmStub.mb.Records("mr.reports_log.count").Record(context.Background(),
float64(mr.nrReportSinceCommit),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(mr.nodeID.String()),
})
mr.tmStub.mb.Records("mr.reports_log.count").Record(context.Background(), float64(mr.nrReportSinceCommit))

mr.tmStub.mb.Records("mr.update_reports.count").Record(context.Background(),
float64(mr.storage.NumUpdateSinceCommit()),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(mr.nodeID.String()),
})
)

mr.nrReportSinceCommit = 0

Expand Down Expand Up @@ -956,10 +941,7 @@ func (mr *RaftMetadataRepository) applyCommit(r *mrpb.Commit, appliedIndex uint6

mr.tmStub.mb.Records("mr.build_commit_results.pure.duration").Record(context.TODO(),
float64(time.Since(st).Nanoseconds())/float64(time.Millisecond),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(mr.nodeID.String()),
})
)
}
crs.Version = curVer + 1

Expand All @@ -980,10 +962,6 @@ func (mr *RaftMetadataRepository) applyCommit(r *mrpb.Commit, appliedIndex uint6

mr.tmStub.mb.Records("mr.build_commit_results.duration").Record(context.Background(),
float64(time.Since(startTime).Nanoseconds())/float64(time.Millisecond),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(mr.nodeID.String()),
},
)

return err
Expand Down Expand Up @@ -1504,11 +1482,6 @@ type handler func(ctx context.Context) (interface{}, error)
func (mr *RaftMetadataRepository) withTelemetry(ctx context.Context, name string, h handler) (interface{}, error) {
st := time.Now()
rsp, err := h(ctx)
mr.tmStub.mb.Records(name).Record(ctx,
float64(time.Since(st).Nanoseconds())/float64(time.Millisecond),
attribute.KeyValue{
Key: "nodeid",
Value: attribute.StringValue(mr.nodeID.String()),
})
mr.tmStub.mb.Records(name).Record(ctx, float64(time.Since(st).Nanoseconds())/float64(time.Millisecond))
return rsp, err
}
7 changes: 2 additions & 5 deletions internal/metarepos/report_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,8 @@ CatchupLoop:

min, max, recordable := lc.sampleTracer.commit(lc.lsID, cr.CommittedLLSNOffset, cr.CommittedLLSNOffset+types.LLSN(cr.CommittedGLSNLength))
if recordable {
lc.tmStub.mb.Records("mr.report_commit.delay").Record(ctx,
float64(time.Since(min).Nanoseconds())/float64(time.Millisecond))

lc.tmStub.mb.Records("mr.replicate.delay").Record(ctx,
float64(max.Sub(min).Nanoseconds())/float64(time.Millisecond))
lc.tmStub.mb.Records("mr.report_commit.delay").Record(ctx, float64(time.Since(min).Nanoseconds())/float64(time.Millisecond))
lc.tmStub.mb.Records("mr.replicate.delay").Record(ctx, float64(max.Sub(min).Nanoseconds())/float64(time.Millisecond))
}

lc.setSentVersion(crs.Version)
Expand Down

0 comments on commit 3d7ff30

Please sign in to comment.