|
| 1 | +// Licensed to Apache Software Foundation (ASF) under one or more contributor |
| 2 | +// license agreements. See the NOTICE file distributed with |
| 3 | +// this work for additional information regarding copyright |
| 4 | +// ownership. Apache Software Foundation (ASF) licenses this file to you under |
| 5 | +// the Apache License, Version 2.0 (the "License"); you may |
| 6 | +// not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package dependency |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + |
| 23 | + "github.com/urfave/cli/v2" |
| 24 | + |
| 25 | + "github.com/apache/skywalking-cli/internal/commands/interceptor" |
| 26 | + "github.com/apache/skywalking-cli/internal/flags" |
| 27 | + "github.com/apache/skywalking-cli/internal/model" |
| 28 | + "github.com/apache/skywalking-cli/pkg/display" |
| 29 | + "github.com/apache/skywalking-cli/pkg/display/displayable" |
| 30 | + "github.com/apache/skywalking-cli/pkg/graphql/dependency" |
| 31 | + "github.com/apache/skywalking-cli/pkg/graphql/metadata" |
| 32 | + |
| 33 | + api "skywalking.apache.org/repo/goapi/query" |
| 34 | +) |
| 35 | + |
| 36 | +var GlobalCommand = &cli.Command{ |
| 37 | + Name: "global", |
| 38 | + Aliases: []string{"glb"}, |
| 39 | + Usage: "Query the global dependencies", |
| 40 | + Flags: flags.Flags( |
| 41 | + flags.DurationFlags, |
| 42 | + []cli.Flag{ |
| 43 | + &cli.StringFlag{ |
| 44 | + Name: "layer", |
| 45 | + Usage: "Name of the layer to query the dependency of this layer", |
| 46 | + Required: false, |
| 47 | + }, |
| 48 | + }, |
| 49 | + ), |
| 50 | + Before: interceptor.BeforeChain( |
| 51 | + interceptor.DurationInterceptor, |
| 52 | + ), |
| 53 | + Action: func(ctx *cli.Context) error { |
| 54 | + layer := ctx.String("layer") |
| 55 | + end := ctx.String("end") |
| 56 | + start := ctx.String("start") |
| 57 | + step := ctx.Generic("step") |
| 58 | + |
| 59 | + duration := api.Duration{ |
| 60 | + Start: start, |
| 61 | + End: end, |
| 62 | + Step: step.(*model.StepEnumValue).Selected, |
| 63 | + } |
| 64 | + |
| 65 | + major, _, err := metadata.BackendVersion(ctx) |
| 66 | + if err != nil { |
| 67 | + return err |
| 68 | + } |
| 69 | + |
| 70 | + var topology api.Topology |
| 71 | + if major >= 10 { |
| 72 | + topology, err = dependency.GlobalTopology(ctx, layer, duration) |
| 73 | + } else { |
| 74 | + if layer != "" { |
| 75 | + return fmt.Errorf("the layer parameter only available when OAP version >= 10.0.0") |
| 76 | + } |
| 77 | + topology, err = dependency.GlobalTopologyWithoutLayer(ctx, duration) |
| 78 | + } |
| 79 | + |
| 80 | + if err != nil { |
| 81 | + return err |
| 82 | + } |
| 83 | + |
| 84 | + return display.Display(ctx, &displayable.Displayable{Data: topology}) |
| 85 | + }, |
| 86 | +} |
0 commit comments