arugal commented on a change in pull request #10: [Feature] Support instance  
list command
URL: https://github.com/apache/skywalking-cli/pull/10#discussion_r344493153
 
 

 ##########
 File path: graphql/client/client.go
 ##########
 @@ -42,11 +54,57 @@ func Services(cliCtx *cli.Context, duration 
schema.Duration) []schema.Service {
        `)
        request.Var("duration", duration)
 
-       ctx := context.Background()
-       if err := client.Run(ctx, request, &response); err != nil {
-               logger.Log.Fatalln(err)
-               panic(err)
+       executeQuery(cliCtx, request, &response)
+       return response["services"]
+}
+
+func Instances(cliCtx *cli.Context, nameOrID string, duration schema.Duration) 
[]schema.ServiceInstance {
+       var serviceId string
+       service, err := searchServices(cliCtx, nameOrID, duration)
+       if err != nil {
+               serviceId = nameOrID
+       } else {
+               serviceId = service.ID
        }
 
-       return response["services"]
+       var response map[string][]schema.ServiceInstance
+       request := graphql.NewRequest(`
+               query ($serviceId: ID!, $duration: Duration!) {
+               instances: getServiceInstances(duration: $duration, serviceId: 
$serviceId) {
+                       id
+                       name
+                       language
+                               instanceUUID
+                       attributes {
+                               name
+                               value
+                       }
+                       }
+               }
+       `)
+       request.Var("serviceId", serviceId)
+       request.Var("duration", duration)
+
+       executeQuery(cliCtx, request, &response)
+       return response["instances"]
+}
+
+func searchServices(cliCtx *cli.Context, serviceName string, duration 
schema.Duration) (service schema.Service, err error) {
+       var response map[string][]schema.Service
+       request := graphql.NewRequest(`
+               query searchServices($keyword: String!, $duration: Duration!) {
+               service: searchServices(duration: $duration, keyword: $keyword) 
{
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to