Clean up repeated package import
Signed-off-by: Zechun Chen <zechun.chen@daocloud.io>
This commit is contained in:
parent
a6f3cbe0ad
commit
b944b108df
@ -37,13 +37,11 @@ import (
|
|||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/containerd/containerd/pkg/cri/annotations"
|
"github.com/containerd/containerd/pkg/cri/annotations"
|
||||||
"github.com/containerd/containerd/pkg/cri/config"
|
|
||||||
criconfig "github.com/containerd/containerd/pkg/cri/config"
|
criconfig "github.com/containerd/containerd/pkg/cri/config"
|
||||||
cio "github.com/containerd/containerd/pkg/cri/io"
|
cio "github.com/containerd/containerd/pkg/cri/io"
|
||||||
customopts "github.com/containerd/containerd/pkg/cri/opts"
|
customopts "github.com/containerd/containerd/pkg/cri/opts"
|
||||||
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
||||||
"github.com/containerd/containerd/pkg/cri/util"
|
"github.com/containerd/containerd/pkg/cri/util"
|
||||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -285,7 +283,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
if err := cntr.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
if err := cntr.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
||||||
log.G(ctx).WithError(err).Errorf("Failed to delete containerd container %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete containerd container %q", id)
|
||||||
@ -355,7 +353,7 @@ func (c *criService) volumeMounts(containerRootDir string, criMounts []*runtime.
|
|||||||
// runtimeSpec returns a default runtime spec used in cri-containerd.
|
// runtimeSpec returns a default runtime spec used in cri-containerd.
|
||||||
func (c *criService) runtimeSpec(id string, platform platforms.Platform, baseSpecFile string, opts ...oci.SpecOpts) (*runtimespec.Spec, error) {
|
func (c *criService) runtimeSpec(id string, platform platforms.Platform, baseSpecFile string, opts ...oci.SpecOpts) (*runtimespec.Spec, error) {
|
||||||
// GenerateSpec needs namespace.
|
// GenerateSpec needs namespace.
|
||||||
ctx := ctrdutil.NamespacedContext()
|
ctx := util.NamespacedContext()
|
||||||
container := &containers.Container{ID: id}
|
container := &containers.Container{ID: id}
|
||||||
|
|
||||||
if baseSpecFile != "" {
|
if baseSpecFile != "" {
|
||||||
@ -418,7 +416,7 @@ func (c *criService) buildContainerSpec(
|
|||||||
sandboxConfig *runtime.PodSandboxConfig,
|
sandboxConfig *runtime.PodSandboxConfig,
|
||||||
imageConfig *imagespec.ImageConfig,
|
imageConfig *imagespec.ImageConfig,
|
||||||
extraMounts []*runtime.Mount,
|
extraMounts []*runtime.Mount,
|
||||||
ociRuntime config.Runtime,
|
ociRuntime criconfig.Runtime,
|
||||||
) (_ *runtimespec.Spec, retErr error) {
|
) (_ *runtimespec.Spec, retErr error) {
|
||||||
var (
|
var (
|
||||||
specOpts []oci.SpecOpts
|
specOpts []oci.SpecOpts
|
||||||
@ -493,7 +491,7 @@ func (c *criService) buildLinuxSpec(
|
|||||||
sandboxConfig *runtime.PodSandboxConfig,
|
sandboxConfig *runtime.PodSandboxConfig,
|
||||||
imageConfig *imagespec.ImageConfig,
|
imageConfig *imagespec.ImageConfig,
|
||||||
extraMounts []*runtime.Mount,
|
extraMounts []*runtime.Mount,
|
||||||
ociRuntime config.Runtime,
|
ociRuntime criconfig.Runtime,
|
||||||
) (_ []oci.SpecOpts, retErr error) {
|
) (_ []oci.SpecOpts, retErr error) {
|
||||||
specOpts := []oci.SpecOpts{
|
specOpts := []oci.SpecOpts{
|
||||||
oci.WithoutRunMount,
|
oci.WithoutRunMount,
|
||||||
@ -728,7 +726,7 @@ func (c *criService) buildWindowsSpec(
|
|||||||
sandboxConfig *runtime.PodSandboxConfig,
|
sandboxConfig *runtime.PodSandboxConfig,
|
||||||
imageConfig *imagespec.ImageConfig,
|
imageConfig *imagespec.ImageConfig,
|
||||||
extraMounts []*runtime.Mount,
|
extraMounts []*runtime.Mount,
|
||||||
ociRuntime config.Runtime,
|
ociRuntime criconfig.Runtime,
|
||||||
) (_ []oci.SpecOpts, retErr error) {
|
) (_ []oci.SpecOpts, retErr error) {
|
||||||
specOpts := []oci.SpecOpts{
|
specOpts := []oci.SpecOpts{
|
||||||
customopts.WithProcessArgs(config, imageConfig),
|
customopts.WithProcessArgs(config, imageConfig),
|
||||||
@ -829,7 +827,7 @@ func (c *criService) buildDarwinSpec(
|
|||||||
sandboxConfig *runtime.PodSandboxConfig,
|
sandboxConfig *runtime.PodSandboxConfig,
|
||||||
imageConfig *imagespec.ImageConfig,
|
imageConfig *imagespec.ImageConfig,
|
||||||
extraMounts []*runtime.Mount,
|
extraMounts []*runtime.Mount,
|
||||||
ociRuntime config.Runtime,
|
ociRuntime criconfig.Runtime,
|
||||||
) (_ []oci.SpecOpts, retErr error) {
|
) (_ []oci.SpecOpts, retErr error) {
|
||||||
specOpts := []oci.SpecOpts{
|
specOpts := []oci.SpecOpts{
|
||||||
customopts.WithProcessArgs(config, imageConfig),
|
customopts.WithProcessArgs(config, imageConfig),
|
||||||
|
@ -34,7 +34,6 @@ import (
|
|||||||
|
|
||||||
cio "github.com/containerd/containerd/pkg/cri/io"
|
cio "github.com/containerd/containerd/pkg/cri/io"
|
||||||
"github.com/containerd/containerd/pkg/cri/util"
|
"github.com/containerd/containerd/pkg/cri/util"
|
||||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
|
||||||
cioutil "github.com/containerd/containerd/pkg/ioutil"
|
cioutil "github.com/containerd/containerd/pkg/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -158,7 +157,7 @@ func (c *criService) execInternal(ctx context.Context, container containerd.Cont
|
|||||||
return nil, fmt.Errorf("failed to create exec %q: %w", execID, err)
|
return nil, fmt.Errorf("failed to create exec %q: %w", execID, err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
if _, err := process.Delete(deferCtx, containerd.WithProcessKill); err != nil {
|
if _, err := process.Delete(deferCtx, containerd.WithProcessKill); err != nil {
|
||||||
log.G(ctx).WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
|
||||||
|
@ -39,7 +39,6 @@ import (
|
|||||||
"github.com/containerd/containerd/pkg/cri/server/bandwidth"
|
"github.com/containerd/containerd/pkg/cri/server/bandwidth"
|
||||||
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
|
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
|
||||||
"github.com/containerd/containerd/pkg/cri/util"
|
"github.com/containerd/containerd/pkg/cri/util"
|
||||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
|
||||||
"github.com/containerd/containerd/pkg/netns"
|
"github.com/containerd/containerd/pkg/netns"
|
||||||
"github.com/containerd/containerd/protobuf"
|
"github.com/containerd/containerd/protobuf"
|
||||||
sb "github.com/containerd/containerd/sandbox"
|
sb "github.com/containerd/containerd/sandbox"
|
||||||
@ -186,7 +185,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
defer func() {
|
defer func() {
|
||||||
// Remove the network namespace only if all the resource cleanup is done.
|
// Remove the network namespace only if all the resource cleanup is done.
|
||||||
if retErr != nil && cleanupErr == nil {
|
if retErr != nil && cleanupErr == nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
// Teardown network if an error is returned.
|
// Teardown network if an error is returned.
|
||||||
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
||||||
@ -276,7 +275,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
go func() {
|
go func() {
|
||||||
defer close(exitCh)
|
defer close(exitCh)
|
||||||
|
|
||||||
ctx := ctrdutil.NamespacedContext()
|
ctx := util.NamespacedContext()
|
||||||
resp, err := controller.Wait(ctx, id)
|
resp, err := controller.Wait(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.G(ctx).WithError(err).Error("failed to wait for sandbox exit")
|
log.G(ctx).WithError(err).Error("failed to wait for sandbox exit")
|
||||||
|
@ -39,7 +39,6 @@ import (
|
|||||||
customopts "github.com/containerd/containerd/pkg/cri/opts"
|
customopts "github.com/containerd/containerd/pkg/cri/opts"
|
||||||
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
||||||
"github.com/containerd/containerd/pkg/cri/util"
|
"github.com/containerd/containerd/pkg/cri/util"
|
||||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -255,7 +254,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
c.nri.undoCreateContainer(deferCtx, &sandbox, id, spec)
|
c.nri.undoCreateContainer(deferCtx, &sandbox, id, spec)
|
||||||
}
|
}
|
||||||
@ -268,7 +267,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
if err := cntr.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
if err := cntr.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
||||||
log.G(ctx).WithError(err).Errorf("Failed to delete containerd container %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete containerd container %q", id)
|
||||||
@ -344,7 +343,7 @@ func (c *criService) volumeMounts(containerRootDir string, criMounts []*runtime.
|
|||||||
// runtimeSpec returns a default runtime spec used in cri-containerd.
|
// runtimeSpec returns a default runtime spec used in cri-containerd.
|
||||||
func (c *criService) runtimeSpec(id string, baseSpecFile string, opts ...oci.SpecOpts) (*runtimespec.Spec, error) {
|
func (c *criService) runtimeSpec(id string, baseSpecFile string, opts ...oci.SpecOpts) (*runtimespec.Spec, error) {
|
||||||
// GenerateSpec needs namespace.
|
// GenerateSpec needs namespace.
|
||||||
ctx := ctrdutil.NamespacedContext()
|
ctx := util.NamespacedContext()
|
||||||
container := &containers.Container{ID: id}
|
container := &containers.Container{ID: id}
|
||||||
|
|
||||||
if baseSpecFile != "" {
|
if baseSpecFile != "" {
|
||||||
|
@ -34,7 +34,6 @@ import (
|
|||||||
|
|
||||||
cio "github.com/containerd/containerd/pkg/cri/io"
|
cio "github.com/containerd/containerd/pkg/cri/io"
|
||||||
"github.com/containerd/containerd/pkg/cri/util"
|
"github.com/containerd/containerd/pkg/cri/util"
|
||||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
|
||||||
cioutil "github.com/containerd/containerd/pkg/ioutil"
|
cioutil "github.com/containerd/containerd/pkg/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -158,7 +157,7 @@ func (c *criService) execInternal(ctx context.Context, container containerd.Cont
|
|||||||
return nil, fmt.Errorf("failed to create exec %q: %w", execID, err)
|
return nil, fmt.Errorf("failed to create exec %q: %w", execID, err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
if _, err := process.Delete(deferCtx, containerd.WithProcessKill); err != nil {
|
if _, err := process.Delete(deferCtx, containerd.WithProcessKill); err != nil {
|
||||||
log.G(ctx).WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
|
||||||
|
@ -44,7 +44,6 @@ import (
|
|||||||
"github.com/containerd/containerd/pkg/cri/server/bandwidth"
|
"github.com/containerd/containerd/pkg/cri/server/bandwidth"
|
||||||
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
|
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
|
||||||
"github.com/containerd/containerd/pkg/cri/util"
|
"github.com/containerd/containerd/pkg/cri/util"
|
||||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
|
||||||
"github.com/containerd/containerd/pkg/netns"
|
"github.com/containerd/containerd/pkg/netns"
|
||||||
"github.com/containerd/containerd/snapshots"
|
"github.com/containerd/containerd/snapshots"
|
||||||
)
|
)
|
||||||
@ -195,7 +194,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
defer func() {
|
defer func() {
|
||||||
// Delete container only if all the resource cleanup is done.
|
// Delete container only if all the resource cleanup is done.
|
||||||
if retErr != nil && cleanupErr == nil {
|
if retErr != nil && cleanupErr == nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
if cleanupErr = container.Delete(deferCtx, containerd.WithSnapshotCleanup); cleanupErr != nil {
|
if cleanupErr = container.Delete(deferCtx, containerd.WithSnapshotCleanup); cleanupErr != nil {
|
||||||
log.G(ctx).WithError(cleanupErr).Errorf("Failed to delete containerd container %q", id)
|
log.G(ctx).WithError(cleanupErr).Errorf("Failed to delete containerd container %q", id)
|
||||||
@ -317,7 +316,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
defer func() {
|
defer func() {
|
||||||
// Teardown the network only if all the resource cleanup is done.
|
// Teardown the network only if all the resource cleanup is done.
|
||||||
if retErr != nil && cleanupErr == nil {
|
if retErr != nil && cleanupErr == nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
// Teardown network if an error is returned.
|
// Teardown network if an error is returned.
|
||||||
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
||||||
@ -364,7 +363,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
// Cleanup the sandbox container if an error is returned.
|
// Cleanup the sandbox container if an error is returned.
|
||||||
if _, err := task.Delete(deferCtx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
if _, err := task.Delete(deferCtx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
||||||
@ -375,7 +374,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// wait is a long running background request, no timeout needed.
|
// wait is a long running background request, no timeout needed.
|
||||||
exitCh, err := task.Wait(ctrdutil.NamespacedContext())
|
exitCh, err := task.Wait(util.NamespacedContext())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to wait for sandbox container task: %w", err)
|
return nil, fmt.Errorf("failed to wait for sandbox container task: %w", err)
|
||||||
}
|
}
|
||||||
@ -438,7 +437,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
defer func() {
|
defer func() {
|
||||||
// Teardown the network only if all the resource cleanup is done.
|
// Teardown the network only if all the resource cleanup is done.
|
||||||
if retErr != nil && cleanupErr == nil {
|
if retErr != nil && cleanupErr == nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
// Teardown network if an error is returned.
|
// Teardown network if an error is returned.
|
||||||
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
||||||
@ -470,7 +469,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := util.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
c.nri.removePodSandbox(deferCtx, &sandbox)
|
c.nri.removePodSandbox(deferCtx, &sandbox)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@ import (
|
|||||||
"github.com/containerd/containerd/namespaces"
|
"github.com/containerd/containerd/namespaces"
|
||||||
"github.com/containerd/containerd/protobuf/proto"
|
"github.com/containerd/containerd/protobuf/proto"
|
||||||
"github.com/containerd/containerd/protobuf/types"
|
"github.com/containerd/containerd/protobuf/types"
|
||||||
ptypes "github.com/containerd/containerd/protobuf/types"
|
|
||||||
"github.com/containerd/ttrpc"
|
"github.com/containerd/ttrpc"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
exec "golang.org/x/sys/execabs"
|
exec "golang.org/x/sys/execabs"
|
||||||
@ -190,7 +189,7 @@ func ReadRuntimeOptions[T any](reader io.Reader) (T, error) {
|
|||||||
return config, errdefs.ErrNotFound
|
return config, errdefs.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
var any ptypes.Any
|
var any types.Any
|
||||||
if err := proto.Unmarshal(data, &any); err != nil {
|
if err := proto.Unmarshal(data, &any); err != nil {
|
||||||
return config, err
|
return config, err
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ import (
|
|||||||
"go.opentelemetry.io/otel/propagation"
|
"go.opentelemetry.io/otel/propagation"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
"go.opentelemetry.io/otel/sdk/trace"
|
"go.opentelemetry.io/otel/sdk/trace"
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
|
||||||
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get tracing processors: %w", err)
|
return nil, fmt.Errorf("failed to get tracing processors: %w", err)
|
||||||
}
|
}
|
||||||
procs := make([]sdktrace.SpanProcessor, 0, len(plugins))
|
procs := make([]trace.SpanProcessor, 0, len(plugins))
|
||||||
for id, pctx := range plugins {
|
for id, pctx := range plugins {
|
||||||
p, err := pctx.Instance()
|
p, err := pctx.Instance()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -80,7 +79,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
proc := p.(sdktrace.SpanProcessor)
|
proc := p.(trace.SpanProcessor)
|
||||||
procs = append(procs, proc)
|
procs = append(procs, proc)
|
||||||
}
|
}
|
||||||
return newTracer(ic.Context, ic.Config.(*TraceConfig), procs)
|
return newTracer(ic.Context, ic.Config.(*TraceConfig), procs)
|
||||||
@ -152,7 +151,7 @@ func newExporter(ctx context.Context, cfg *OTLPConfig) (*otlptrace.Exporter, err
|
|||||||
// its sampling ratio and returns io.Closer.
|
// its sampling ratio and returns io.Closer.
|
||||||
//
|
//
|
||||||
// Note that this function sets process-wide tracing configuration.
|
// Note that this function sets process-wide tracing configuration.
|
||||||
func newTracer(ctx context.Context, config *TraceConfig, procs []sdktrace.SpanProcessor) (io.Closer, error) {
|
func newTracer(ctx context.Context, config *TraceConfig, procs []trace.SpanProcessor) (io.Closer, error) {
|
||||||
|
|
||||||
res, err := resource.New(ctx,
|
res, err := resource.New(ctx,
|
||||||
resource.WithHost(),
|
resource.WithHost(),
|
||||||
@ -165,18 +164,18 @@ func newTracer(ctx context.Context, config *TraceConfig, procs []sdktrace.SpanPr
|
|||||||
return nil, fmt.Errorf("failed to create resource: %w", err)
|
return nil, fmt.Errorf("failed to create resource: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sampler := sdktrace.ParentBased(sdktrace.TraceIDRatioBased(config.TraceSamplingRatio))
|
sampler := trace.ParentBased(trace.TraceIDRatioBased(config.TraceSamplingRatio))
|
||||||
|
|
||||||
opts := []sdktrace.TracerProviderOption{
|
opts := []trace.TracerProviderOption{
|
||||||
sdktrace.WithSampler(sampler),
|
trace.WithSampler(sampler),
|
||||||
sdktrace.WithResource(res),
|
trace.WithResource(res),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, proc := range procs {
|
for _, proc := range procs {
|
||||||
opts = append(opts, sdktrace.WithSpanProcessor(proc))
|
opts = append(opts, trace.WithSpanProcessor(proc))
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := sdktrace.NewTracerProvider(opts...)
|
provider := trace.NewTracerProvider(opts...)
|
||||||
|
|
||||||
otel.SetTracerProvider(provider)
|
otel.SetTracerProvider(provider)
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"go.opentelemetry.io/otel/sdk/trace"
|
"go.opentelemetry.io/otel/sdk/trace"
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
|
||||||
"go.opentelemetry.io/otel/sdk/trace/tracetest"
|
"go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -100,7 +99,7 @@ func TestNewTracer(t *testing.T) {
|
|||||||
config := &TraceConfig{ServiceName: "containerd", TraceSamplingRatio: 1.0}
|
config := &TraceConfig{ServiceName: "containerd", TraceSamplingRatio: 1.0}
|
||||||
t.Logf("config: %v", config)
|
t.Logf("config: %v", config)
|
||||||
|
|
||||||
procs := make([]sdktrace.SpanProcessor, 0, 1)
|
procs := make([]trace.SpanProcessor, 0, 1)
|
||||||
|
|
||||||
//Create a dummy in memory exporter for test
|
//Create a dummy in memory exporter for test
|
||||||
exp := tracetest.NewInMemoryExporter()
|
exp := tracetest.NewInMemoryExporter()
|
||||||
|
Loading…
Reference in New Issue
Block a user