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

Avereha/group by node #292

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions expr/expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,10 @@ func TestExtractMetric(t *testing.T) {
"{something}",
"{something}",
},
{
"a.b#c.d",
"a.b#c.d",
},
}

for _, tt := range tests {
Expand Down
5 changes: 3 additions & 2 deletions expr/functions/groupByNode/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ func (f *groupByNode) Do(e parser.Expr, from, until int32, values map[parser.Met

groups := make(map[string][]*types.MetricData)
nodeList := []string{}

for _, a := range args {

metric := helper.ExtractMetric(a.Name)
nodes := strings.Split(metric, ".")
nodeKey := make([]string, 0, len(fields))
for _, f := range fields {
if f < 0 || f >= len(nodes) {
return nil, fmt.Errorf("%s: %w: %d", e.Target(), parser.ErrInvalidArgumentValue, f)
}
nodeKey = append(nodeKey, nodes[f])
}
node := strings.Join(nodeKey, ".")
Expand Down
2 changes: 2 additions & 0 deletions pkg/parser/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ var (
ErrUnknownTimeUnits = ParseError("unknown time units")
// ErrDifferentCountMetrics is an eval error returned when a function that works on pairs of metrics receives arguments having different number of metrics.
ErrDifferentCountMetrics = ParseError("both arguments must have the same number of metrics")
// ErrInvalidArgumentValue is an eval error returned when a function received an argument that has the right type but invalid value
ErrInvalidArgumentValue = ParseError("invalid function argument value")
)

// ParseError is a type of errors returned from the parser
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func IsNameChar(r byte) bool {
r == '[' || r == ']' ||
r == '^' || r == '$' ||
r == '<' || r == '>' ||
r == '&'
r == '&' || r == '#'
}

func isDigit(r byte) bool {
Expand Down