-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feature/custom metrics #14
Merged
lwlee2608
merged 8 commits into
MATRIXXSoftware:main
from
luissimas:feature/custom-metrics
Dec 13, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5a9dd1
fix address on log messages
luissimas 1a346fe
fix genproto dependency
luissimas 85970fd
add custom metrics
luissimas 4e5b9c2
add cmd_code tag to metrics
luissimas 1bd17ab
use current time on metrics register
luissimas bf16483
add diameter_req_failed metric
luissimas f6f7c5c
update console logs on docs
luissimas b8f22e4
diameter_req_failed as rate
luissimas 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package diameter | ||
|
||
import ( | ||
"time" | ||
|
||
"go.k6.io/k6/js/modules" | ||
"go.k6.io/k6/metrics" | ||
) | ||
|
||
type DiameterMetrics struct { | ||
RequestDuration *metrics.Metric | ||
RequestCount *metrics.Metric | ||
FailedRequestCount *metrics.Metric | ||
} | ||
|
||
func registerMetrics(vu modules.VU) DiameterMetrics { | ||
registry := vu.InitEnv().Registry | ||
metrics := DiameterMetrics{ | ||
RequestDuration: registry.MustNewMetric("diameter_req_duration", metrics.Trend, metrics.Time), | ||
RequestCount: registry.MustNewMetric("diameter_req_count", metrics.Counter, metrics.Default), | ||
FailedRequestCount: registry.MustNewMetric("diameter_req_failed", metrics.Rate, metrics.Default), | ||
} | ||
return metrics | ||
} | ||
|
||
func (c *DiameterClient) reportMetric(metric *metrics.Metric, now time.Time, value float64, tags map[string]string) { | ||
state := c.vu.State() | ||
ctx := c.vu.Context() | ||
if state == nil || ctx == nil { | ||
return | ||
} | ||
|
||
metrics.PushIfNotDone(ctx, state.Samples, metrics.Sample{ | ||
Time: now, | ||
TimeSeries: metrics.TimeSeries{ | ||
Metric: metric, | ||
Tags: metrics.NewRegistry().RootTagSet().WithTagsFromMap(tags), | ||
}, | ||
Value: value, | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,23 +1,34 @@ | ||
package diameter | ||
|
||
import ( | ||
"github.com/dop251/goja" | ||
"go.k6.io/k6/js/modules" | ||
) | ||
|
||
type ( | ||
Diameter struct { | ||
vu modules.VU | ||
exports *goja.Object | ||
metrics DiameterMetrics | ||
} | ||
RootModule struct{} | ||
Module struct { | ||
*Diameter | ||
} | ||
) | ||
|
||
func init() { | ||
modules.Register("k6/x/diameter", &Diameter{}) | ||
modules.Register("k6/x/diameter", New()) | ||
modules.Register("k6/x/diameter/avp", &AVP{}) | ||
modules.Register("k6/x/diameter/dict", &Dict{}) | ||
} | ||
|
||
func New() *RootModule { | ||
return &RootModule{} | ||
} | ||
|
||
func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance { | ||
return &Diameter{ | ||
vu: vu, | ||
metrics: registerMetrics(vu), | ||
} | ||
} | ||
|
||
func (d *Diameter) Exports() modules.Exports { | ||
return modules.Exports{Default: d} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be made slightly more efficient: