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 support to show metrics #4033

Merged
merged 13 commits into from
Nov 7, 2019
24 changes: 24 additions & 0 deletions query/outputnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ import (
// ToJson converts the list of subgraph into a JSON response by calling toFastJSON.
func ToJson(l *Latency, sgl []*SubGraph) ([]byte, error) {
sgr := &SubGraph{}
metricsMap := map[string]int{}
for _, sg := range sgl {
if sg.Params.Alias == "var" || sg.Params.Alias == "shortest" {
continue
}
if sg.Params.GetUid {
sgr.Params.GetUid = true
}
// calculate metrics for this query.
calculateMetrics(sg, metricsMap)
sgr.Children = append(sgr.Children, sg)
}
fmt.Println(metricsMap)
Copy link

Choose a reason for hiding this comment

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

Is this for logging purposes or to console to validate?

return sgr.toFastJSON(l)
}

Expand Down Expand Up @@ -810,3 +814,23 @@ func (sg *SubGraph) preTraverse(uid uint64, dst outputNode) error {

return nil
}

// calculateMetrics populates the given map with the number of uids are gathered for each
Copy link

Choose a reason for hiding this comment

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

calculateMetrics populates the given map with the number of uids are gathered for each attributes

// attributes.
func calculateMetrics(sg *SubGraph, metrics map[string]int) {
mangalaman93 marked this conversation as resolved.
Show resolved Hide resolved
// we'll calculate srcUid of the each attribute. because, these are number of uids
// processed by this attribute.
prev := metrics[sg.Attr]
// QUESTION: @manish @pawan: should I add destuid or length of posting list?.
prev = prev + len(sg.SrcUIDs.GetUids())
metrics[sg.Attr] = prev
mangalaman93 marked this conversation as resolved.
Show resolved Hide resolved

// add all the uids gathered by filters
mangalaman93 marked this conversation as resolved.
Show resolved Hide resolved
for _, filter := range sg.Filters {
calculateMetrics(filter, metrics)
}
// calculate metrics for the childres as well.
Copy link

Choose a reason for hiding this comment

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

children

for _, child := range sg.Children {
calculateMetrics(child, metrics)
}
}