Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/metering #517

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pipeline/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ func (p *Pipeline) processBlock(
}
case bstream.StepNew:
p.blockStepMap[bstream.StepNew]++

dmetering.GetBytesMeter(ctx).AddBytesRead(execOutput.Len())
err = p.handleStepNew(ctx, clock, cursor, execOutput)
if err != nil && err != io.EOF {
return fmt.Errorf("step new: handler step new: %w", err)
Expand Down
18 changes: 13 additions & 5 deletions service/metering.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ func sendMetering(ctx context.Context, meter dmetering.Meter, userID, apiKeyID,
inputBytes := meter.GetCount("wasm_input_bytes")
meter.ResetCount("wasm_input_bytes")

uncompressedBytesRead := meter.GetCount("uncompressed_bytes_read")
meter.ResetCount("uncompressed_bytes_read")

uncompressedLiveBytesRead := meter.GetCount("uncompressed_live_bytes_read")
meter.ResetCount("uncompressed_live_bytes_read")

event := dmetering.Event{
UserID: userID,
ApiKeyID: apiKeyID,
Expand All @@ -25,11 +31,13 @@ func sendMetering(ctx context.Context, meter dmetering.Meter, userID, apiKeyID,

Endpoint: endpoint,
Metrics: map[string]float64{
"egress_bytes": float64(egressBytes),
"written_bytes": float64(bytesWritten),
"read_bytes": float64(bytesRead),
"wasm_input_bytes": float64(inputBytes),
"message_count": 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y'avait-il pas déjà une convention d'avoir l'unité à la fin? donc uncompressed_read_bytes plutôt que uncompressed_bytes_read ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, i will make the change

"egress_bytes": float64(egressBytes),
"written_bytes": float64(bytesWritten),
"read_bytes": float64(bytesRead),
"wasm_input_bytes": float64(inputBytes),
"uncompressed_bytes_read": float64(uncompressedBytesRead),
"uncompressed_live_bytes_read": float64(uncompressedLiveBytesRead),
"message_count": 1,
},
Timestamp: time.Now(),
}
Expand Down
21 changes: 20 additions & 1 deletion service/tier1.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ func (s *Tier1Service) Blocks(
ctx = reqctx.WithTracer(ctx, s.tracer)
ctx = dmetering.WithBytesMeter(ctx)
ctx = dmetering.WithCounter(ctx, "wasm_input_bytes")
ctx = dmetering.WithCounter(ctx, "live_bytes_uncompressed")
ctx = dmetering.WithCounter(ctx, "stored_bytes_uncompressed")
ctx = reqctx.WithTier2RequestParameters(ctx, s.tier2RequestParameters)

ctx, span := reqctx.WithSpan(ctx, "substreams/tier1/request")
Expand Down Expand Up @@ -568,9 +570,26 @@ func (s *Tier1Service) blocks(ctx context.Context, request *pbsubstreamsrpc.Requ
streamHandler = pipe
}

// We need to meter the bytes read from the live stream, as they are not metered by the dstore meters
blockMeteredHandlerFunc := bstream.HandlerFunc(func(blk *pbbstream.Block, obj interface{}) error {
step := obj.(bstream.Stepable).Step()
switch step {
case bstream.StepNewIrreversible:
// already metered by the store in compressed bytes.
// we will meter them here for potential future use
dmetering.GetBytesMeter(ctx).CountInc("uncompressed_bytes_read", len(blk.Payload.GetValue()))
default:
// all other cases are live blocks to be metered
dmetering.GetBytesMeter(ctx).AddBytesRead(len(blk.Payload.GetValue()))
dmetering.GetBytesMeter(ctx).CountInc("uncompressed_live_bytes_read", len(blk.Payload.GetValue()))
}

return streamHandler.ProcessBlock(blk, obj)
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, donc le tier2 va lire des blocks, et ici c'est la source elle-même qui va être metered, avec des métriques différentes, fack on fera l'aggrégation à la sortie, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tier2 doesn't play into this. tier2 does not have live blocks and so the blockstream doesn't need to be instrumented. all of the tier2's data sources are dstores which are metered.

blockStream, err := s.streamFactoryFunc(
ctx,
streamHandler,
blockMeteredHandlerFunc,
int64(requestDetails.LinearHandoffBlockNum),
request.StopBlockNum,
cursor,
Expand Down
Loading