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

Misc fixes for summary callback changes #1788

Merged
merged 6 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 6 additions & 6 deletions samples/custom_metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Counter, Gauge, Rate, Trend } from "k6/metrics";
import { check } from "k6";

/*
* Custom metrics are useful when you want to track something that is not
* Custom metrics are useful when you want to track something that is not
* provided out of the box.
*
*
* There are four types of custom metrics: Counter, Gauge, Rate and Trend.
*
*
* - Counter: a sum of all values added to the metric
* - Gauge: a value that change to whatever you set it to
* - Rate: rate of "truthiness", how many values out of total are !=0
Expand All @@ -22,7 +22,7 @@ let myTrend = new Trend("my_trend");

let maxResponseTime = 0.0;

export default function() {
export default function () {
let res = http.get("http://httpbin.org/");
let passed = check(res, { "status is 200": (r) => r.status === 200 });

Expand All @@ -36,6 +36,6 @@ export default function() {
// Add check success or failure to keep track of rate
myRate.add(passed);

// Keep track of DNS+TCP-connecting part of the response time
myTrend.add(res.timings.looking_up + res.timings.connecting);
// Keep track of TCP-connecting and TLS handshaking part of the response time
myTrend.add(res.timings.connecting + res.timings.tls_handshaking);
}
2 changes: 1 addition & 1 deletion samples/grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import grpc from 'k6/net/grpc';
import { check } from "k6";

let client = new grpc.Client();
client.load([], "samples/grpc_server/route_guide.proto")
client.load([], "./grpc_server/route_guide.proto")


export default () => {
Expand Down
8 changes: 4 additions & 4 deletions stats/cloud/cloud_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 31 additions & 13 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ import (
)

const (
counterString = `"counter"`
gaugeString = `"gauge"`
trendString = `"trend"`
rateString = `"rate"`

defaultString = `"default"`
timeString = `"time"`
dataString = `"data"`
counterString = "counter"
gaugeString = "gauge"
trendString = "trend"
rateString = "rate"

defaultString = "default"
timeString = "time"
dataString = "data"
)

// Possible values for MetricType.
Expand Down Expand Up @@ -71,6 +71,15 @@ type MetricType int

// MarshalJSON serializes a MetricType as a human readable string.
func (t MetricType) MarshalJSON() ([]byte, error) {
txt, err := t.MarshalText()
if err != nil {
return nil, err
}
return []byte(`"` + string(txt) + `"`), nil
na-- marked this conversation as resolved.
Show resolved Hide resolved
}

// MarshalText serializes a MetricType as a human readable string.
func (t MetricType) MarshalText() ([]byte, error) {
switch t {
case Counter:
return []byte(counterString), nil
Expand All @@ -85,8 +94,8 @@ func (t MetricType) MarshalJSON() ([]byte, error) {
}
}

// UnmarshalJSON deserializes a MetricType from a string representation.
func (t *MetricType) UnmarshalJSON(data []byte) error {
// UnmarshalText deserializes a MetricType from a string representation.
func (t *MetricType) UnmarshalText(data []byte) error {
switch string(data) {
case counterString:
*t = Counter
Expand Down Expand Up @@ -121,8 +130,17 @@ func (t MetricType) String() string {
// The type of values a metric contains.
type ValueType int

// MarshalJSON serializes a ValueType as a human readable string.
// MarshalJSON serializes a ValueType to a JSON string.
func (t ValueType) MarshalJSON() ([]byte, error) {
txt, err := t.MarshalText()
if err != nil {
return nil, err
}
return []byte(`"` + string(txt) + `"`), nil
}

// MarshalText serializes a ValueType as a human readable string.
func (t ValueType) MarshalText() ([]byte, error) {
switch t {
case Default:
return []byte(defaultString), nil
Expand All @@ -135,8 +153,8 @@ func (t ValueType) MarshalJSON() ([]byte, error) {
}
}

// UnmarshalJSON deserializes a ValueType from a string representation.
func (t *ValueType) UnmarshalJSON(data []byte) error {
// UnmarshalText deserializes a ValueType from a string representation.
func (t *ValueType) UnmarshalText(data []byte) error {
switch string(data) {
case defaultString:
*t = Default
Expand Down