-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add continuous profiling and metrics query related commands (#182)
- Loading branch information
Showing
13 changed files
with
282 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Licensed to Apache Software Foundation (ASF) under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Apache Software Foundation (ASF) licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
query ($expression: String!, $entity: Entity!, $duration: Duration!) { | ||
result: execExpression(expression: $expression, entity: $entity, duration: $duration) { | ||
type | ||
results { | ||
metric { | ||
labels { | ||
key value | ||
} | ||
} | ||
values { | ||
id | ||
value | ||
traceID | ||
} | ||
} | ||
error | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
assets/graphqls/profiling/continuous/QueryContinuousProfilingMonitoringInstances.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Licensed to Apache Software Foundation (ASF) under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Apache Software Foundation (ASF) licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
query ($serviceId: ID!, $target: ContinuousProfilingTargetType!){ | ||
result: queryContinuousProfilingMonitoringInstances(serviceId: $serviceId, target: $target) { | ||
id | ||
name | ||
attributes { | ||
name | ||
value | ||
} | ||
triggeredCount | ||
lastTriggerTimestamp | ||
|
||
processes { | ||
id | ||
name | ||
detectType | ||
labels | ||
triggeredCount | ||
lastTriggerTimestamp | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,7 @@ query ($serviceId: ID!){ | |
uriList | ||
uriRegex | ||
} | ||
triggeredCount | ||
lastTriggerTimestamp | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Licensed to Apache Software Foundation (ASF) under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Apache Software Foundation (ASF) licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package expression | ||
|
||
import ( | ||
"github.com/apache/skywalking-cli/internal/commands/interceptor" | ||
"github.com/apache/skywalking-cli/internal/flags" | ||
"github.com/apache/skywalking-cli/internal/model" | ||
"github.com/apache/skywalking-cli/pkg/display" | ||
"github.com/apache/skywalking-cli/pkg/display/displayable" | ||
"github.com/apache/skywalking-cli/pkg/graphql/metrics" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
api "skywalking.apache.org/repo/goapi/query" | ||
) | ||
|
||
const expressionParameterName = "expression" | ||
|
||
var ExecCommand = &cli.Command{ | ||
Name: "execute", | ||
Aliases: []string{"exec"}, | ||
Usage: `Execute a metrics expression.`, | ||
UsageText: `Execute a metrics expression. | ||
Examples: | ||
1. Execute the given expression of service "business-zone::projectB" | ||
$ swctl metrics execute --expression="service_resp_time" --service-name business-zone::projectB`, | ||
Flags: flags.Flags( | ||
flags.DurationFlags, | ||
flags.InstanceRelationFlags, | ||
flags.EndpointRelationFlags, | ||
flags.ProcessRelationFlags, | ||
[]cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: expressionParameterName, | ||
Usage: "metrics expression", | ||
Required: true, | ||
}, | ||
}, | ||
), | ||
Before: interceptor.BeforeChain( | ||
interceptor.DurationInterceptor, | ||
interceptor.ParseEndpointRelation(false), | ||
interceptor.ParseInstanceRelation(false), | ||
interceptor.ParseProcessRelation(false), | ||
), | ||
Action: func(ctx *cli.Context) error { | ||
end := ctx.String("end") | ||
start := ctx.String("start") | ||
step := ctx.Generic("step") | ||
|
||
expression := ctx.String(expressionParameterName) | ||
entity, err := interceptor.ParseEntity(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
duration := api.Duration{ | ||
Start: start, | ||
End: end, | ||
Step: step.(*model.StepEnumValue).Selected, | ||
} | ||
|
||
result, err := metrics.Execute(ctx, expression, entity, duration) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return display.Display(ctx, &displayable.Displayable{Data: result}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,6 @@ var Command = &cli.Command{ | |
Subcommands: []*cli.Command{ | ||
SetPolicyCommand, | ||
ListCommand, | ||
Monitoring, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to Apache Software Foundation (ASF) under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Apache Software Foundation (ASF) licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package continuous | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/apache/skywalking-cli/internal/commands/interceptor" | ||
"github.com/apache/skywalking-cli/internal/flags" | ||
"github.com/apache/skywalking-cli/pkg/display" | ||
"github.com/apache/skywalking-cli/pkg/display/displayable" | ||
"github.com/apache/skywalking-cli/pkg/graphql/profiling" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
api "skywalking.apache.org/repo/goapi/query" | ||
) | ||
|
||
var Monitoring = &cli.Command{ | ||
Name: "monitoring", | ||
Aliases: []string{"monitor"}, | ||
Usage: `query all continuous profiling monitoring instances through service and policy target`, | ||
UsageText: `Query all continuous profiling monitoring instances through service and policy target. | ||
Example: | ||
1. Query all continuous profiling monitoring instances through service "business-zone::projectC" and policy target "ON_CPU" | ||
$ swctl profiling continuous monitoring --service-name=business-zone::projectC --target=ON_CPU | ||
`, | ||
Flags: flags.Flags( | ||
flags.ServiceFlags, | ||
[]cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "target", | ||
Usage: "policy target type", | ||
Required: true, | ||
}, | ||
}, | ||
), | ||
Before: interceptor.BeforeChain( | ||
interceptor.ParseService(true), | ||
), | ||
Action: func(ctx *cli.Context) error { | ||
serviceID := ctx.String("service-id") | ||
targetString := ctx.String("target") | ||
targetHasSet := false | ||
var target api.ContinuousProfilingTargetType | ||
for _, enum := range api.AllContinuousProfilingTargetType { | ||
if strings.EqualFold(enum.String(), targetString) { | ||
target = enum | ||
targetHasSet = true | ||
break | ||
} | ||
} | ||
if !targetHasSet { | ||
return fmt.Errorf("unknown target type: %s", targetString) | ||
} | ||
|
||
instances, err := profiling.QueryContinuousProfilingMonitoringInstances(ctx, serviceID, target) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return display.Display(ctx, &displayable.Displayable{Data: instances}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters