GitLabgitlab-org

cli

main
ply9 git calls312 ms99 KiB6 cachedprotocol v2
134 lines3.9 KiBRaw
1package create
3import (
4 "context"
5 "fmt"
7 "github.com/MakeNowJust/heredoc/v2"
8 "github.com/spf13/cobra"
10 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
12 "gitlab.com/gitlab-org/cli/internal/api"
13 "gitlab.com/gitlab-org/cli/internal/cmdutils"
14 "gitlab.com/gitlab-org/cli/internal/iostreams"
15 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
16 "gitlab.com/gitlab-org/cli/internal/text"
19type options struct {
20 io *iostreams.IOStreams
21 apiClient func(repoHost string) (*api.Client, error)
23 controllerID int64
24 runnerIDs []int64
25 instance bool
26 outputFormat string
29func NewCmd(f cmdutils.Factory) *cobra.Command {
30 opts := &options{
31 io: f.IO(),
32 apiClient: f.ApiClient,
33 }
35 cmd := &cobra.Command{
36 Use: "create <controller-id> [flags]",
37 Short: `Create a scope for a runner controller. (EXPERIMENTAL)`,
38 Long: heredoc.Docf(`
39 Creates a scope for a runner controller. This is an administrator-only feature.
41 Use one of the following flags to specify the scope type:
43 - --instance: Add an instance-level scope, allowing the runner controller
44 to evaluate jobs for all runners in the GitLab instance.
45 - --runner <id>: Add a runner-level scope, allowing the runner controller
46 to evaluate jobs for a specific instance-level runner. Multiple IDs can
47 be comma-separated or specified by repeating the flag.
48 %s`, text.ExperimentalString),
49 Args: cobra.ExactArgs(1),
50 Example: heredoc.Doc(`
51 # Add an instance-level scope to runner controller 42
52 glab runner-controller scope create 42 --instance
54 # Add a runner-level scope for runner 5 to runner controller 42
55 glab runner-controller scope create 42 --runner 5
57 # Add runner-level scopes for multiple runners
58 glab runner-controller scope create 42 --runner 5 --runner 10
59 glab runner-controller scope create 42 --runner 5,10
61 # Add a runner-level scope and output as JSON
62 glab runner-controller scope create 42 --runner 5 --output json`),
63 Annotations: map[string]string{
64 mcpannotations.Destructive: "true",
65 },
66 RunE: func(cmd *cobra.Command, args []string) error {
67 if err := opts.complete(args); err != nil {
68 return err
69 }
70 return opts.run(cmd.Context())
71 },
72 }
74 cmdutils.EnableJSONOutput(cmd, opts.io, &opts.outputFormat)
76 fl := cmd.Flags()
77 fl.BoolVar(&opts.instance, "instance", false, "Add an instance-level scope.")
78 fl.Int64SliceVar(&opts.runnerIDs, "runner", nil, "Add a runner-level scope for the specified runner ID. Multiple IDs can be comma-separated or specified by repeating the flag.")
80 cmd.MarkFlagsMutuallyExclusive("instance", "runner")
81 cmd.MarkFlagsOneRequired("instance", "runner")
83 return cmd
86func (o *options) complete(args []string) error {
87 id, err := cmdutils.ParseID(args[0], "runner controller ID")
88 if err != nil {
89 return err
90 }
91 o.controllerID = id
92 return nil
95func (o *options) run(ctx context.Context) error {
96 apiClient, err := o.apiClient("")
97 if err != nil {
98 return err
99 }
100 client := apiClient.Lab()
102 var results []any
104 switch {
105 case o.instance:
106 scoping, _, err := client.RunnerControllerScopes.AddRunnerControllerInstanceScope(o.controllerID, gitlab.WithContext(ctx))
107 if err != nil {
108 return cmdutils.WrapError(err, "failed to add instance-level scope")
109 }
110 results = append(results, scoping)
111 default:
112 for _, runnerID := range o.runnerIDs {
113 scoping, _, err := client.RunnerControllerScopes.AddRunnerControllerRunnerScope(o.controllerID, runnerID, gitlab.WithContext(ctx))
114 if err != nil {
115 return cmdutils.WrapError(err, fmt.Sprintf("failed to add runner-level scope for runner %d", runnerID))
116 }
117 results = append(results, scoping)
118 }
119 }
121 if o.outputFormat == "json" {
122 return o.io.PrintJSON(results)
123 }
125 switch {
126 case o.instance:
127 o.io.LogInfof("Added instance-level scope to runner controller %d\n", o.controllerID)
128 default:
129 for _, runnerID := range o.runnerIDs {
130 o.io.LogInfof("Added runner-level scope for runner %d to runner controller %d\n", runnerID, o.controllerID)
131 }
132 }
133 return nil
Diagnostics9 git calls · 312 ms
CallStatusSizeTime0312 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchtree:02001.8 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200323 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=323
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=8185a1b139a07a59fba10180a7318233adb22fc3
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=323
git.pkt.payload.max=296
git.sideband.band1.bytes=296
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=296
git.pack.trailer=ac106711ec2e15414437a5964de4b85c86703290
Open pack map
fetchtree:0200196 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=196
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=2457618d95f2bcb98ae5f01c872bb42789a59b56
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=196
git.pkt.payload.max=169
git.sideband.band1.bytes=169
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=169
git.pack.trailer=02c3a461145a7ea4fb72afbfd8909e6ed3eedc5a
Open pack map
fetchtree:0200138 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=138
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=de1c4238be0bb0dd2a2fe8a34c32720cfc8e232f
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=138
git.pkt.payload.max=111
git.sideband.band1.bytes=111
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=111
git.pack.trailer=a71b46066d197c28e9cdffbb5427f00ffaf994df
Open pack map
fetch2001.4 KiB295 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=295
git.response.bytes=1471
git.response.cache=MISS
git.response.duration_ms=295
git.fetch.wants=e37af597b282847c4c624e24de844636159b5551
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1471
git.pkt.payload.max=1444
git.sideband.band1.bytes=1444
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e1f3d3ef39efe9
Request
816baba9…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format