Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: docker/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v26.1.2
Choose a base ref
...
head repository: docker/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v26.1.3
Choose a head ref
  • 9 commits
  • 9 files changed
  • 5 contributors

Commits on May 13, 2024

  1. docs: clarify that --data-path-addr doesn't restrict access

    Signed-off-by: David Karlsson <[email protected]>
    (cherry picked from commit faf096b)
    Signed-off-by: David Karlsson <[email protected]>
    dvdksn committed May 13, 2024
    Copy the full SHA
    81b482e View commit details
  2. Merge pull request #5068 from dvdksn/26.1_backport_doc-vxlan-listen-addr

    [26.1 Backport] docs: clarify that --data-path-addr doesn't restrict access
    thaJeztah authored May 13, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    60f2d38 View commit details

Commits on May 14, 2024

  1. Use funcs on DockerCli to return Meter/TracerProviders, not initializ…

    …e them. Initialize them during DockerCli struct init
    
    Signed-off-by: Christopher Petito <[email protected]>
    (cherry picked from commit 02537ea)
    krissetto authored and laurazard committed May 14, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    laurazard Laura Brehm
    Copy the full SHA
    6691085 View commit details
  2. Merge pull request #5070 from laurazard/backport/5067-26.1

    [26.1 backport] Centralize init of Meter/TracerProviders
    laurazard authored May 14, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    004e292 View commit details

Commits on May 15, 2024

  1. OTel: add command.time metric to plugin commands

    Signed-off-by: Laura Brehm <[email protected]>
    (cherry picked from commit f07834d)
    laurazard committed May 15, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    laurazard Laura Brehm
    Copy the full SHA
    ee359a3 View commit details
  2. OTel: implement missing MeterProvider ForceFlush

    Signed-off-by: Laura Brehm <[email protected]>
    (cherry picked from commit 5f4f4f6)
    laurazard committed May 15, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    laurazard Laura Brehm
    Copy the full SHA
    326c713 View commit details
  3. Merge pull request #5071 from laurazard/backport/5051-26.1

    [26.1 backport] Add OTel instrumentation to CLI plugins
    vvoland authored May 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4021ee9 View commit details
  4. vendor: github.com/docker/docker v26.1.3-dev (8e96db1c328d)

    - full diff: moby/moby@ef1912d...8e96db1
    
    Signed-off-by: Paweł Gronowski <[email protected]>
    vvoland committed May 15, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    vvoland Paweł Gronowski
    Copy the full SHA
    26e9ff4 View commit details

Commits on May 16, 2024

  1. Merge pull request #5073 from vvoland/vendor-docker

    [26.1] vendor: github.com/docker/docker v26.1.3-dev (8e96db1c328d)
    vvoland authored May 16, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b72abbb View commit details
Showing with 104 additions and 40 deletions.
  1. +18 −0 cli-plugins/plugin/plugin.go
  2. +5 −0 cli/command/cli.go
  3. +41 −25 cli/command/telemetry.go
  4. +22 −7 cli/command/telemetry_utils.go
  5. +8 −4 cmd/docker/docker.go
  6. +6 −0 docs/reference/commandline/swarm_init.md
  7. +1 −1 vendor.mod
  8. +2 −2 vendor.sum
  9. +1 −1 vendor/modules.txt
18 changes: 18 additions & 0 deletions cli-plugins/plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -52,6 +52,24 @@ func RunPlugin(dockerCli *command.DockerCli, plugin *cobra.Command, meta manager
opts = append(opts, withPluginClientConn(plugin.Name()))
}
err = tcmd.Initialize(opts...)
ogRunE := cmd.RunE
if ogRunE == nil {
ogRun := cmd.Run
// necessary because error will always be nil here
// see: https://github.com/golangci/golangci-lint/issues/1379
//nolint:unparam
ogRunE = func(cmd *cobra.Command, args []string) error {
ogRun(cmd, args)
return nil
}
cmd.Run = nil
}
cmd.RunE = func(cmd *cobra.Command, args []string) error {
stopInstrumentation := dockerCli.StartInstrumentation(cmd)
err := ogRunE(cmd, args)
stopInstrumentation(err)
return err
}
})
return err
}
5 changes: 5 additions & 0 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
@@ -273,6 +273,11 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption)
return ResolveDefaultContext(cli.options, cli.contextStoreConfig)
},
}

// TODO(krissetto): pass ctx to the funcs instead of using this
cli.createGlobalMeterProvider(cli.baseCtx)
cli.createGlobalTracerProvider(cli.baseCtx)

return nil
}

66 changes: 41 additions & 25 deletions cli/command/telemetry.go
Original file line number Diff line number Diff line change
@@ -41,35 +41,25 @@ type TelemetryClient interface {
// each time this function is invoked.
Resource() *resource.Resource

// TracerProvider returns a TracerProvider. This TracerProvider will be configured
// with the default tracing components for a CLI program along with any options given
// for the SDK.
TracerProvider(ctx context.Context, opts ...sdktrace.TracerProviderOption) TracerProvider
// TracerProvider returns the currently initialized TracerProvider. This TracerProvider will be configured
// with the default tracing components for a CLI program
TracerProvider() trace.TracerProvider

// MeterProvider returns a MeterProvider. This MeterProvider will be configured
// with the default metric components for a CLI program along with any options given
// for the SDK.
MeterProvider(ctx context.Context, opts ...sdkmetric.Option) MeterProvider
// MeterProvider returns the currently initialized MeterProvider. This MeterProvider will be configured
// with the default metric components for a CLI program
MeterProvider() metric.MeterProvider
}

func (cli *DockerCli) Resource() *resource.Resource {
return cli.res.Get()
}

func (cli *DockerCli) TracerProvider(ctx context.Context, opts ...sdktrace.TracerProviderOption) TracerProvider {
allOpts := make([]sdktrace.TracerProviderOption, 0, len(opts)+2)
allOpts = append(allOpts, sdktrace.WithResource(cli.Resource()))
allOpts = append(allOpts, dockerSpanExporter(ctx, cli)...)
allOpts = append(allOpts, opts...)
return sdktrace.NewTracerProvider(allOpts...)
func (cli *DockerCli) TracerProvider() trace.TracerProvider {
return otel.GetTracerProvider()
}

func (cli *DockerCli) MeterProvider(ctx context.Context, opts ...sdkmetric.Option) MeterProvider {
allOpts := make([]sdkmetric.Option, 0, len(opts)+2)
allOpts = append(allOpts, sdkmetric.WithResource(cli.Resource()))
allOpts = append(allOpts, dockerMetricExporter(ctx, cli)...)
allOpts = append(allOpts, opts...)
return sdkmetric.NewMeterProvider(allOpts...)
func (cli *DockerCli) MeterProvider() metric.MeterProvider {
return otel.GetMeterProvider()
}

// WithResourceOptions configures additional options for the default resource. The default
@@ -122,6 +112,28 @@ func (r *telemetryResource) init() {
r.opts = nil
}

// createGlobalMeterProvider creates a new MeterProvider from the initialized DockerCli struct
// with the given options and sets it as the global meter provider
func (cli *DockerCli) createGlobalMeterProvider(ctx context.Context, opts ...sdkmetric.Option) {
allOpts := make([]sdkmetric.Option, 0, len(opts)+2)
allOpts = append(allOpts, sdkmetric.WithResource(cli.Resource()))
allOpts = append(allOpts, dockerMetricExporter(ctx, cli)...)
allOpts = append(allOpts, opts...)
mp := sdkmetric.NewMeterProvider(allOpts...)
otel.SetMeterProvider(mp)
}

// createGlobalTracerProvider creates a new TracerProvider from the initialized DockerCli struct
// with the given options and sets it as the global tracer provider
func (cli *DockerCli) createGlobalTracerProvider(ctx context.Context, opts ...sdktrace.TracerProviderOption) {
allOpts := make([]sdktrace.TracerProviderOption, 0, len(opts)+2)
allOpts = append(allOpts, sdktrace.WithResource(cli.Resource()))
allOpts = append(allOpts, dockerSpanExporter(ctx, cli)...)
allOpts = append(allOpts, opts...)
tp := sdktrace.NewTracerProvider(allOpts...)
otel.SetTracerProvider(tp)
}

func defaultResourceOptions() []resource.Option {
return []resource.Option{
resource.WithDetectors(serviceNameDetector{}),
@@ -174,18 +186,22 @@ func newCLIReader(exp sdkmetric.Exporter) sdkmetric.Reader {
}

func (r *cliReader) Shutdown(ctx context.Context) error {
var rm metricdata.ResourceMetrics
if err := r.Reader.Collect(ctx, &rm); err != nil {
return err
}

// Place a pretty tight constraint on the actual reporting.
// We don't want CLI metrics to prevent the CLI from exiting
// so if there's some kind of issue we need to abort pretty
// quickly.
ctx, cancel := context.WithTimeout(ctx, exportTimeout)
defer cancel()

return r.ForceFlush(ctx)
}

func (r *cliReader) ForceFlush(ctx context.Context) error {
var rm metricdata.ResourceMetrics
if err := r.Reader.Collect(ctx, &rm); err != nil {
return err
}

return r.exporter.Export(ctx, &rm)
}

29 changes: 22 additions & 7 deletions cli/command/telemetry_utils.go
Original file line number Diff line number Diff line change
@@ -26,8 +26,7 @@ func BaseCommandAttributes(cmd *cobra.Command, streams Streams) []attribute.KeyV
// Note: this should be the last func to wrap/modify the PersistentRunE/RunE funcs before command execution.
//
// can also be used for spans!
func (cli *DockerCli) InstrumentCobraCommands(cmd *cobra.Command, mp metric.MeterProvider) {
meter := getDefaultMeter(mp)
func (cli *DockerCli) InstrumentCobraCommands(ctx context.Context, cmd *cobra.Command) {
// If PersistentPreRunE is nil, make it execute PersistentPreRun and return nil by default
ogPersistentPreRunE := cmd.PersistentPreRunE
if ogPersistentPreRunE == nil {
@@ -55,19 +54,27 @@ func (cli *DockerCli) InstrumentCobraCommands(cmd *cobra.Command, mp metric.Mete
}
cmd.RunE = func(cmd *cobra.Command, args []string) error {
// start the timer as the first step of every cobra command
baseAttrs := BaseCommandAttributes(cmd, cli)
stopCobraCmdTimer := startCobraCommandTimer(cmd, meter, baseAttrs)
stopInstrumentation := cli.StartInstrumentation(cmd)
cmdErr := ogRunE(cmd, args)
stopCobraCmdTimer(cmdErr)
stopInstrumentation(cmdErr)
return cmdErr
}

return ogPersistentPreRunE(cmd, args)
}
}

func startCobraCommandTimer(cmd *cobra.Command, meter metric.Meter, attrs []attribute.KeyValue) func(err error) {
ctx := cmd.Context()
// StartInstrumentation instruments CLI commands with the individual metrics and spans configured.
// It's the main command OTel utility, and new command-related metrics should be added to it.
// It should be called immediately before command execution, and returns a stopInstrumentation function
// that must be called with the error resulting from the command execution.
func (cli *DockerCli) StartInstrumentation(cmd *cobra.Command) (stopInstrumentation func(error)) {
baseAttrs := BaseCommandAttributes(cmd, cli)
return startCobraCommandTimer(cli.MeterProvider(), baseAttrs)
}

func startCobraCommandTimer(mp metric.MeterProvider, attrs []attribute.KeyValue) func(err error) {
meter := getDefaultMeter(mp)
durationCounter, _ := meter.Float64Counter(
"command.time",
metric.WithDescription("Measures the duration of the cobra command"),
@@ -76,12 +83,20 @@ func startCobraCommandTimer(cmd *cobra.Command, meter metric.Meter, attrs []attr
start := time.Now()

return func(err error) {
// Use a new context for the export so that the command being cancelled
// doesn't affect the metrics, and we get metrics for cancelled commands.
ctx, cancel := context.WithTimeout(context.Background(), exportTimeout)
defer cancel()

duration := float64(time.Since(start)) / float64(time.Millisecond)
cmdStatusAttrs := attributesFromError(err)
durationCounter.Add(ctx, duration,
metric.WithAttributes(attrs...),
metric.WithAttributes(cmdStatusAttrs...),
)
if mp, ok := mp.(MeterProvider); ok {
mp.ForceFlush(ctx)
}
}
}

12 changes: 8 additions & 4 deletions cmd/docker/docker.go
Original file line number Diff line number Diff line change
@@ -307,10 +307,14 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
return err
}

mp := dockerCli.MeterProvider(ctx)
defer mp.Shutdown(ctx)
otel.SetMeterProvider(mp)
dockerCli.InstrumentCobraCommands(cmd, mp)
mp := dockerCli.MeterProvider()
if mp, ok := mp.(command.MeterProvider); ok {
defer mp.Shutdown(ctx)
} else {
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
}

dockerCli.InstrumentCobraCommands(ctx, cmd)

var envs []string
args, os.Args, envs, err = processAliases(dockerCli, cmd, args, os.Args)
6 changes: 6 additions & 0 deletions docs/reference/commandline/swarm_init.md
Original file line number Diff line number Diff line change
@@ -117,6 +117,12 @@ data traffic from the management traffic of the cluster.

If unspecified, the IP address or interface of the advertise address is used.

Setting `--data-path-addr` does not restrict which interfaces or source IP
addresses the VXLAN socket is bound to. Similar to `--advertise-addr`, the
purpose of this flag is to inform other members of the swarm about which
address to use for control plane traffic. To restrict access to the VXLAN port
of the node, use firewall rules.

### <a name="data-path-port"></a> Configure port number for data traffic (--data-path-port)

The `--data-path-port` flag allows you to configure the UDP port number to use
2 changes: 1 addition & 1 deletion vendor.mod
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ require (
github.com/creack/pty v1.1.21
github.com/distribution/reference v0.5.0
github.com/docker/distribution v2.8.3+incompatible
github.com/docker/docker v26.1.2-0.20240508085902-ef1912d8b6ae+incompatible
github.com/docker/docker v26.1.3-0.20240515073302-8e96db1c328d+incompatible
github.com/docker/docker-credential-helpers v0.8.1
github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0
4 changes: 2 additions & 2 deletions vendor.sum
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@ github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v26.1.2-0.20240508085902-ef1912d8b6ae+incompatible h1:PcRQNw8eAMTjdnD7+y3IeJcsCKqxHmlT0MmqfNs9Jc4=
github.com/docker/docker v26.1.2-0.20240508085902-ef1912d8b6ae+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v26.1.3-0.20240515073302-8e96db1c328d+incompatible h1:J+p52tFajMpC0is/1M2mIArncOp4qa+E8hj5Vwt11vs=
github.com/docker/docker v26.1.3-0.20240515073302-8e96db1c328d+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.8.1 h1:j/eKUktUltBtMzKqmfLB0PAgqYyMHOp5vfsD1807oKo=
github.com/docker/docker-credential-helpers v0.8.1/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ github.com/docker/distribution/registry/client/transport
github.com/docker/distribution/registry/storage/cache
github.com/docker/distribution/registry/storage/cache/memory
github.com/docker/distribution/uuid
# github.com/docker/docker v26.1.2-0.20240508085902-ef1912d8b6ae+incompatible
# github.com/docker/docker v26.1.3-0.20240515073302-8e96db1c328d+incompatible
## explicit
github.com/docker/docker/api
github.com/docker/docker/api/types