-
Notifications
You must be signed in to change notification settings - Fork 308
feat(metrics): record per-snapshot dirty/empty/total bytes at creation #2649
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d333d2e
feat(metrics): record per-snapshot dirty/empty/total bytes
ValentaTomas b678429
inline diffStatsFromMetadata at the two call sites
ValentaTomas 6ae602a
rename diff kind=dirty -> kind=full in metric attribute
ValentaTomas 51a1b15
ratio histogram: percent (0-100) instead of basis points
ValentaTomas 237b7a2
metrics: emit at the DiffMetadata site, drop Snapshot stats fields
ValentaTomas 2fedc0d
metrics: nil-check Dirty/Empty bitmaps in recordSnapshotDiff
ValentaTomas 4258ca6
metrics: revert kind=full -> kind=dirty (matches DiffMetadata.Dirty),…
ValentaTomas 1ab4253
metrics: revert ratio to basis points (10000=100%) to keep sub-percen…
ValentaTomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package sandbox | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/metric" | ||
|
|
||
| "github.com/e2b-dev/infra/packages/shared/pkg/storage/header" | ||
| "github.com/e2b-dev/infra/packages/shared/pkg/telemetry" | ||
| "github.com/e2b-dev/infra/packages/shared/pkg/utils" | ||
| ) | ||
|
|
||
| var ( | ||
| snapshotDiffBytes = utils.Must(telemetry.GetHistogram(meter, telemetry.SnapshotDiffBytes)) | ||
| snapshotDiffRatioBp = utils.Must(telemetry.GetHistogram(meter, telemetry.SnapshotDiffRatioBp)) | ||
| snapshotTotalBytes = utils.Must(telemetry.GetHistogram(meter, telemetry.SnapshotTotalBytes)) | ||
| ) | ||
|
|
||
| type SnapshotUseCase string | ||
|
|
||
| const ( | ||
| SnapshotUseCasePause SnapshotUseCase = "pause" | ||
| SnapshotUseCaseBuild SnapshotUseCase = "build" | ||
| ) | ||
|
|
||
| func recordSnapshotDiff( | ||
| ctx context.Context, | ||
| fileType string, | ||
| dm *header.DiffMetadata, | ||
| original *header.Header, | ||
| useCase SnapshotUseCase, | ||
| ) { | ||
| if dm == nil || original == nil || original.Metadata == nil { | ||
| return | ||
| } | ||
| bs := int64(original.Metadata.BlockSize) | ||
| total := int64(original.Metadata.Size) | ||
|
|
||
| ft := attribute.String("file_type", fileType) | ||
| uc := attribute.String("use_case", string(useCase)) | ||
|
|
||
| snapshotTotalBytes.Record(ctx, total, metric.WithAttributes(ft, uc)) | ||
|
|
||
| var dirtyBytes, emptyBytes int64 | ||
| if dm.Dirty != nil { | ||
| dirtyBytes = int64(dm.Dirty.GetCardinality()) * bs | ||
| } | ||
| if dm.Empty != nil { | ||
| emptyBytes = int64(dm.Empty.GetCardinality()) * bs | ||
| } | ||
| for kind, b := range map[string]int64{ | ||
| "dirty": dirtyBytes, | ||
| "empty": emptyBytes, | ||
| } { | ||
| attrs := metric.WithAttributes(ft, attribute.String("kind", kind), uc) | ||
| snapshotDiffBytes.Record(ctx, b, attrs) | ||
| snapshotDiffRatioBp.Record(ctx, ratioBp(b, total), attrs) | ||
| } | ||
| } | ||
|
|
||
| // ratioBp returns num/denom in basis points (10000 = 100.00%) so we keep | ||
| // sub-percent resolution. Grafana panels divide by 100 to display percent. | ||
| func ratioBp(num, denom int64) int64 { | ||
| if denom <= 0 { | ||
| return 0 | ||
| } | ||
| bp := num * 10000 / denom | ||
| if bp < 0 { | ||
| return 0 | ||
| } | ||
| if bp > 10000 { | ||
| return 10000 | ||
| } | ||
|
|
||
| return bp | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.