Skip to content

Commit

Permalink
Merge pull request #170 from grafana/feat/flagging-custom-metrics
Browse files Browse the repository at this point in the history
Flagging custom metrics
  • Loading branch information
szkiba authored Feb 6, 2024
2 parents e130803 + 709fdf1 commit adac967
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions dashboard/assets/packages/model/src/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type Metric = {
contains?: ValueType
type?: MetricType
thresholds?: Array<string>
custom?: boolean
}

export class Query {
Expand Down
125 changes: 125 additions & 0 deletions dashboard/builtin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package dashboard

import (
"sort"

"go.k6.io/k6/metrics"
)

const (
// xk6-dashboard's time
keyTime = "time"

// from k6 metrics/builtin.go
keyVUsName = metrics.VUsName
keyVUsMaxName = metrics.VUsMaxName
keyIterationsName = metrics.IterationsName
keyIterationDurationName = metrics.IterationDurationName
keyDroppedIterationsName = metrics.DroppedIterationsName

keyChecksName = metrics.ChecksName
keyGroupDurationName = metrics.GroupDurationName

keyHTTPReqsName = metrics.HTTPReqsName
keyHTTPReqFailedName = metrics.HTTPReqFailedName
keyHTTPReqDurationName = metrics.HTTPReqDurationName
keyHTTPReqBlockedName = metrics.HTTPReqBlockedName
keyHTTPReqConnectingName = metrics.HTTPReqConnectingName
keyHTTPReqTLSHandshakingName = metrics.HTTPReqTLSHandshakingName
keyHTTPReqSendingName = metrics.HTTPReqSendingName
keyHTTPReqWaitingName = metrics.HTTPReqWaitingName
keyHTTPReqReceivingName = metrics.HTTPReqReceivingName

keyWSSessionsName = metrics.WSSessionsName
keyWSMessagesSentName = metrics.WSMessagesSentName
keyWSMessagesReceivedName = metrics.WSMessagesReceivedName
keyWSPingName = metrics.WSPingName
keyWSSessionDurationName = metrics.WSSessionDurationName
keyWSConnectingName = metrics.WSConnectingName

keyGRPCReqDurationName = metrics.GRPCReqDurationName

keyDataSentName = metrics.DataSentName
keyDataReceivedName = metrics.DataReceivedName

// from xk6-browser

keyfidName = "browser_web_vital_fid"
keyttfbName = "browser_web_vital_ttfb"
keylcpName = "browser_web_vital_lcp"
keyclsName = "browser_web_vital_cls"
keyinpName = "browser_web_vital_inp"
keyfcpName = "browser_web_vital_fcp"

keybrowserDataSentName = "browser_data_sent"
keybrowserDataReceivedName = "browser_data_received"
keybrowserHTTPReqDurationName = "browser_http_req_duration"
keybrowserHTTPReqFailedName = "browser_http_req_failed"

// from k6/grpc

keyGRPCStreamsName = "grpc_streams"
keyGRPCStreamsMsgsReceivedName = "grpc_streams_msgs_received"
keyGRPCStreamsMsgsSentName = "grpc_streams_msgs_sent"
)

var builtinNames = []string{ //nolint:gochecknoglobals
keyTime,

keyVUsName,
keyVUsMaxName,
keyIterationsName,
keyIterationDurationName,
keyDroppedIterationsName,

keyChecksName,
keyGroupDurationName,

keyHTTPReqsName,
keyHTTPReqFailedName,
keyHTTPReqDurationName,
keyHTTPReqBlockedName,
keyHTTPReqConnectingName,
keyHTTPReqTLSHandshakingName,
keyHTTPReqSendingName,
keyHTTPReqWaitingName,
keyHTTPReqReceivingName,

keyWSSessionsName,
keyWSMessagesSentName,
keyWSMessagesReceivedName,
keyWSPingName,
keyWSSessionDurationName,
keyWSConnectingName,

keyGRPCReqDurationName,

keyDataSentName,
keyDataReceivedName,

keyfidName,
keyttfbName,
keylcpName,
keyclsName,
keyinpName,
keyfcpName,

keybrowserDataSentName,
keybrowserDataReceivedName,
keybrowserHTTPReqDurationName,
keybrowserHTTPReqFailedName,

keyGRPCStreamsName,
keyGRPCStreamsMsgsReceivedName,
keyGRPCStreamsMsgsSentName,
}

func init() {
sort.Strings(builtinNames)
}

func isBuiltin(name string) bool {
idx := sort.SearchStrings(builtinNames, name)

return idx < len(builtinNames) && builtinNames[idx] == name
}
2 changes: 2 additions & 0 deletions dashboard/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ type metricData struct {
Contains metrics.ValueType `json:"contains,omitempty"`
Tainted bool `json:"tainted,omitempty"`
Thresholds []string `json:"thresholds,omitempty"`
Custom bool `json:"custom,omitempty"`
}

func newMetricData(origin *metrics.Metric) *metricData {
Expand All @@ -228,6 +229,7 @@ func newMetricData(origin *metrics.Metric) *metricData {
Contains: origin.Contains,
Tainted: origin.Tainted.Bool,
Thresholds: thresholdsSources(origin.Thresholds),
Custom: !isBuiltin(origin.Name),
}
}

Expand Down

0 comments on commit adac967

Please sign in to comment.