-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add decompression tracing instrumentation. (#1445)
* Add decompression tracing instrumentation. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fix time conversion. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Use span logger so we also get a log line. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Improve reusability and add fetched chunks. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
- Loading branch information
1 parent
768bf91
commit fb76416
Showing
14 changed files
with
131 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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,42 @@ | ||
package decompression | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
type ctxKeyType string | ||
|
||
const ctxKey ctxKeyType = "decompression" | ||
|
||
// Stats is decompression statistic | ||
type Stats struct { | ||
TimeDecompress time.Duration // Time spent decompressing chunks | ||
TimeFiltering time.Duration // Time spent filtering lines | ||
BytesDecompressed int64 // Total bytes decompressed data size | ||
BytesCompressed int64 // Total bytes compressed read | ||
FetchedChunks int64 // Total number of chunks fetched. | ||
} | ||
|
||
// NewContext creates a new decompression context | ||
func NewContext(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, ctxKey, &Stats{}) | ||
} | ||
|
||
// GetStats returns decompression statistics from a context. | ||
func GetStats(ctx context.Context) Stats { | ||
d, ok := ctx.Value(ctxKey).(*Stats) | ||
if !ok { | ||
return Stats{} | ||
} | ||
return *d | ||
} | ||
|
||
// Mutate mutates the current context statistic using a mutator function | ||
func Mutate(ctx context.Context, mutator func(m *Stats)) { | ||
d, ok := ctx.Value(ctxKey).(*Stats) | ||
if !ok { | ||
return | ||
} | ||
mutator(d) | ||
} |
This file contains 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 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 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 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 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 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 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 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 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.