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

Add trafficsplit metrics to CLI #3176

Merged
merged 21 commits into from
Aug 14, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Creating buildTrafficSplitRequestLabels()
  • Loading branch information
Carol Scott committed Aug 14, 2019
commit 6a1076f48cb1297b68e3163c0435ac87246b71fe
45 changes: 34 additions & 11 deletions controller/api/public/stat_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,20 +451,43 @@ func buildRequestLabels(req *pb.StatSummaryRequest) (labels model.LabelSet, labe

default:
labelNames = promGroupByLabelNames(req.Selector.Resource)
labels = labels.Merge(promQueryLabels(req.Selector.Resource))

if req.Selector.Resource.Type == k8s.TrafficSplit {
labels = labels.Merge(promQueryLabels(req.Selector.Resource))
labels = labels.Merge(promDirectionLabels("outbound"))
} else {
labels = labels.Merge(promDirectionLabels("inbound"))
}
labels = labels.Merge(promQueryLabels(req.Selector.Resource))
labels = labels.Merge(promDirectionLabels("inbound"))
}

if req.Selector.Resource.Type == k8s.TrafficSplit {
labelNames[1] = model.LabelName("dst_service") // replacing "trafficsplit" with "dst_service"
return
}

func buildTrafficSplitRequestLabels(req *pb.StatSummaryRequest) (labels model.LabelSet, labelNames model.LabelNames) {
scottcarol marked this conversation as resolved.
Show resolved Hide resolved
// labelNames: the group by in the prometheus query
// labels: the labels for the resource we want to query for

switch out := req.Outbound.(type) {
case *pb.StatSummaryRequest_ToResource:
labelNames = promGroupByLabelNames(req.Selector.Resource)
scottcarol marked this conversation as resolved.
Show resolved Hide resolved

labels = labels.Merge(promDstQueryLabels(out.ToResource))
labels = labels.Merge(promQueryLabels(req.Selector.Resource))
labels = labels.Merge(promDirectionLabels("outbound"))

case *pb.StatSummaryRequest_FromResource:
labelNames = promDstGroupByLabelNames(req.Selector.Resource)

labels = labels.Merge(promQueryLabels(out.FromResource))
labels = labels.Merge(promDstQueryLabels(req.Selector.Resource))
labels = labels.Merge(promDirectionLabels("outbound"))

default:
labelNames = promGroupByLabelNames(req.Selector.Resource)

labels = labels.Merge(promQueryLabels(req.Selector.Resource))
labels = labels.Merge(promDirectionLabels("outbound"))
}
return labels, labelNames

labelNames[1] = model.LabelName("dst_service") // replacing "trafficsplit" with "dst_service"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused on what this is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored this, let me know if it's more clear. buildTrafficSplitRequestLabels handles four different query scenarios, and needs to output different labels for each:

stat ts -A (namespace is not specified)
stat ts -n foo
stat ts --from resource/name
stat ts --to resource/name


return
}

func (s *grpcServer) getStatMetrics(ctx context.Context, req *pb.StatSummaryRequest, timeWindow string) (map[rKey]*pb.BasicStats, map[rKey]*pb.TcpStats, error) {
Expand Down Expand Up @@ -497,7 +520,7 @@ func (s *grpcServer) getTrafficSplitMetrics(ctx context.Context, req *pb.StatSum

scottcarol marked this conversation as resolved.
Show resolved Hide resolved
tsBasicStats := make(map[tsKey]*pb.BasicStats)

reqLabels, groupBy := buildRequestLabels(req)
reqLabels, groupBy := buildTrafficSplitRequestLabels(req)

apex := tsStats.apex
stringifiedReqLabels := generateLabelStringWithRegex(reqLabels, "authority", apex)
Expand Down