From 8ba72c46ac6b0766055a10526e9d2912db45d129 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Fri, 3 May 2024 18:37:08 +0200 Subject: [PATCH 1/2] Replace OpenCensus with OpenTelemetry The OpenCensus repo has been archived on July 31, 2023 (see [1]), and thus will receive no further updates. OTel offers a bridge to help transition however this means every project using hcsshim need to set up that bridge. At this point, it seems better to transition to OTel instead. This commit fully replaces OpenCensus with OpenTelemetry v1.21. - Package `internal/oc` has been replaced by `internal/otelutil`. - `octtrpc` has been replaced by `otelttrpc`. - `go.opencensus.io/plugin/ocgrpc` has been replaced by `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. - Whenever possible, span attributes are passed directly when the span is created. [1]: https://opentelemetry.io/blog/2023/sunsetting-opencensus/ Signed-off-by: Albin Kerouanton --- cmd/containerd-shim-runhcs-v1/delete.go | 6 +- cmd/containerd-shim-runhcs-v1/events.go | 14 +- cmd/containerd-shim-runhcs-v1/exec_hcs.go | 21 +- cmd/containerd-shim-runhcs-v1/main.go | 13 +- cmd/containerd-shim-runhcs-v1/serve.go | 4 +- cmd/containerd-shim-runhcs-v1/service.go | 317 +++++----- cmd/containerd-shim-runhcs-v1/task_hcs.go | 13 +- .../task_wcow_podsandbox.go | 13 +- cmd/gcs/main.go | 13 +- cmd/ncproxy/ncproxy.go | 151 ++--- cmd/ncproxy/run.go | 17 +- cmd/ncproxy/server.go | 8 +- cmd/runhcs/create-scratch.go | 6 +- cmd/runhcs/prepare-disk.go | 6 +- computestorage/attach.go | 21 +- computestorage/destroy.go | 11 +- computestorage/detach.go | 17 +- computestorage/export.go | 15 +- computestorage/format.go | 6 +- computestorage/import.go | 15 +- computestorage/initialize.go | 13 +- computestorage/mount.go | 6 +- computestorage/setup.go | 23 +- go.mod | 9 +- go.sum | 43 +- internal/copyfile/copyfile.go | 16 +- internal/gcs/bridge.go | 22 +- internal/gcs/container.go | 63 +- internal/gcs/guestconnection.go | 51 +- internal/gcs/guestconnection_test.go | 75 +-- internal/gcs/process.go | 75 +-- internal/gcs/protocol.go | 5 +- internal/guest/bridge/bridge.go | 68 +- internal/guest/bridge/bridge_v2.go | 108 ++-- internal/guest/network/network.go | 31 +- internal/guest/prot/protocol.go | 27 +- internal/guest/runtime/hcsv2/container.go | 13 +- internal/guest/runtime/hcsv2/network.go | 59 +- internal/guest/runtime/hcsv2/process.go | 30 +- .../guest/runtime/hcsv2/sandbox_container.go | 11 +- .../runtime/hcsv2/standalone_container.go | 11 +- .../guest/runtime/hcsv2/workload_container.go | 14 +- .../guest/storage/devicemapper/targets.go | 33 +- internal/guest/storage/mount.go | 15 +- internal/guest/storage/overlay/overlay.go | 28 +- internal/guest/storage/plan9/plan9.go | 19 +- internal/guest/storage/pmem/pmem.go | 25 +- internal/guest/storage/scsi/scsi.go | 55 +- internal/hcs/process.go | 59 +- internal/hcs/system.go | 47 +- internal/log/format.go | 2 +- internal/log/hook.go | 8 +- internal/oc/exporter.go | 86 --- internal/oc/span.go | 58 -- internal/{oc => otelutil}/errors.go | 2 +- internal/otelutil/exporter.go | 102 +++ internal/otelutil/span.go | 53 ++ internal/uvm/computeagent.go | 4 +- internal/uvm/create.go | 11 +- internal/uvm/create_lcow.go | 10 +- internal/uvm/create_wcow.go | 10 +- internal/vhdx/info.go | 12 +- internal/vmcompute/vmcompute.go | 184 +++--- internal/wclayer/activatelayer.go | 11 +- internal/wclayer/baselayerreader.go | 10 +- internal/wclayer/baselayerwriter.go | 8 +- internal/wclayer/cim/LayerWriter.go | 20 +- internal/wclayer/converttobaselayer.go | 11 +- internal/wclayer/createlayer.go | 14 +- internal/wclayer/createscratchlayer.go | 14 +- internal/wclayer/deactivatelayer.go | 11 +- internal/wclayer/destroylayer.go | 11 +- internal/wclayer/expandscratchsize.go | 14 +- internal/wclayer/exportlayer.go | 29 +- internal/wclayer/getlayermountpath.go | 13 +- internal/wclayer/getsharedbaseimages.go | 10 +- internal/wclayer/grantvmaccess.go | 14 +- internal/wclayer/importlayer.go | 29 +- internal/wclayer/layerexists.go | 13 +- internal/wclayer/layerid.go | 11 +- internal/wclayer/nametoguid.go | 13 +- internal/wclayer/preparelayer.go | 14 +- internal/wclayer/processimage.go | 17 +- internal/wclayer/unpreparelayer.go | 11 +- pkg/octtrpc/interceptor.go | 117 ---- pkg/otelttrpc/interceptor.go | 95 +++ test/functional/main_test.go | 11 +- test/gcs/main_test.go | 11 +- test/go.mod | 6 +- test/go.sum | 64 +- vendor/github.com/golang/groupcache/LICENSE | 191 ------ .../github.com/golang/groupcache/lru/lru.go | 133 ---- vendor/go.opencensus.io/.gitignore | 9 - vendor/go.opencensus.io/AUTHORS | 1 - vendor/go.opencensus.io/CONTRIBUTING.md | 63 -- vendor/go.opencensus.io/Makefile | 97 --- vendor/go.opencensus.io/README.md | 267 -------- vendor/go.opencensus.io/appveyor.yml | 24 - vendor/go.opencensus.io/internal/internal.go | 37 -- vendor/go.opencensus.io/internal/sanitize.go | 50 -- .../internal/tagencoding/tagencoding.go | 75 --- .../internal/traceinternals.go | 53 -- .../go.opencensus.io/metric/metricdata/doc.go | 19 - .../metric/metricdata/exemplar.go | 38 -- .../metric/metricdata/label.go | 35 -- .../metric/metricdata/metric.go | 46 -- .../metric/metricdata/point.go | 193 ------ .../metric/metricdata/type_string.go | 16 - .../metric/metricdata/unit.go | 27 - .../metric/metricproducer/manager.go | 78 --- .../metric/metricproducer/producer.go | 28 - .../go.opencensus.io/plugin/ocgrpc/client.go | 56 -- .../plugin/ocgrpc/client_metrics.go | 118 ---- .../plugin/ocgrpc/client_stats_handler.go | 49 -- vendor/go.opencensus.io/plugin/ocgrpc/doc.go | 19 - .../go.opencensus.io/plugin/ocgrpc/server.go | 81 --- .../plugin/ocgrpc/server_metrics.go | 108 ---- .../plugin/ocgrpc/server_stats_handler.go | 63 -- .../plugin/ocgrpc/stats_common.go | 248 -------- .../plugin/ocgrpc/trace_common.go | 107 ---- vendor/go.opencensus.io/resource/resource.go | 164 ----- vendor/go.opencensus.io/stats/doc.go | 68 -- .../go.opencensus.io/stats/internal/record.go | 31 - vendor/go.opencensus.io/stats/measure.go | 109 ---- .../go.opencensus.io/stats/measure_float64.go | 55 -- .../go.opencensus.io/stats/measure_int64.go | 55 -- vendor/go.opencensus.io/stats/record.go | 156 ----- vendor/go.opencensus.io/stats/units.go | 26 - .../stats/view/aggregation.go | 123 ---- .../stats/view/aggregation_data.go | 336 ---------- .../go.opencensus.io/stats/view/collector.go | 93 --- vendor/go.opencensus.io/stats/view/doc.go | 47 -- vendor/go.opencensus.io/stats/view/export.go | 45 -- vendor/go.opencensus.io/stats/view/view.go | 221 ------- .../stats/view/view_to_metric.go | 147 ----- vendor/go.opencensus.io/stats/view/worker.go | 424 ------------- .../stats/view/worker_commands.go | 186 ------ vendor/go.opencensus.io/tag/context.go | 43 -- vendor/go.opencensus.io/tag/doc.go | 26 - vendor/go.opencensus.io/tag/key.go | 44 -- vendor/go.opencensus.io/tag/map.go | 229 ------- vendor/go.opencensus.io/tag/map_codec.go | 239 ------- vendor/go.opencensus.io/tag/metadata.go | 52 -- vendor/go.opencensus.io/tag/profile_19.go | 32 - vendor/go.opencensus.io/tag/profile_not19.go | 24 - vendor/go.opencensus.io/tag/validate.go | 56 -- vendor/go.opencensus.io/trace/basetypes.go | 129 ---- vendor/go.opencensus.io/trace/config.go | 86 --- vendor/go.opencensus.io/trace/doc.go | 52 -- vendor/go.opencensus.io/trace/evictedqueue.go | 38 -- vendor/go.opencensus.io/trace/export.go | 97 --- .../trace/internal/internal.go | 22 - vendor/go.opencensus.io/trace/lrumap.go | 61 -- .../trace/propagation/propagation.go | 108 ---- vendor/go.opencensus.io/trace/sampling.go | 75 --- vendor/go.opencensus.io/trace/spanbucket.go | 130 ---- vendor/go.opencensus.io/trace/spanstore.go | 308 --------- vendor/go.opencensus.io/trace/status_codes.go | 37 -- vendor/go.opencensus.io/trace/trace.go | 595 ------------------ vendor/go.opencensus.io/trace/trace_api.go | 265 -------- vendor/go.opencensus.io/trace/trace_go11.go | 33 - .../go.opencensus.io/trace/trace_nongo11.go | 26 - .../trace/tracestate/tracestate.go | 147 ----- .../google.golang.org/grpc/otelgrpc}/LICENSE | 3 +- .../google.golang.org/grpc/otelgrpc/config.go | 187 ++++++ .../google.golang.org/grpc/otelgrpc/doc.go | 45 ++ .../grpc/otelgrpc/interceptor.go | 580 +++++++++++++++++ .../grpc/otelgrpc/interceptorinfo.go | 50 ++ .../grpc/otelgrpc/internal/parse.go | 51 ++ .../grpc/otelgrpc/metadata_supplier.go | 98 +++ .../grpc/otelgrpc/semconv.go | 52 ++ .../grpc/otelgrpc/stats_handler.go | 187 ++++++ .../grpc/otelgrpc/version.go} | 17 +- vendor/modules.txt | 24 +- 174 files changed, 2595 insertions(+), 9153 deletions(-) delete mode 100644 internal/oc/exporter.go delete mode 100644 internal/oc/span.go rename internal/{oc => otelutil}/errors.go (99%) create mode 100644 internal/otelutil/exporter.go create mode 100644 internal/otelutil/span.go delete mode 100644 pkg/octtrpc/interceptor.go create mode 100644 pkg/otelttrpc/interceptor.go delete mode 100644 vendor/github.com/golang/groupcache/LICENSE delete mode 100644 vendor/github.com/golang/groupcache/lru/lru.go delete mode 100644 vendor/go.opencensus.io/.gitignore delete mode 100644 vendor/go.opencensus.io/AUTHORS delete mode 100644 vendor/go.opencensus.io/CONTRIBUTING.md delete mode 100644 vendor/go.opencensus.io/Makefile delete mode 100644 vendor/go.opencensus.io/README.md delete mode 100644 vendor/go.opencensus.io/appveyor.yml delete mode 100644 vendor/go.opencensus.io/internal/internal.go delete mode 100644 vendor/go.opencensus.io/internal/sanitize.go delete mode 100644 vendor/go.opencensus.io/internal/tagencoding/tagencoding.go delete mode 100644 vendor/go.opencensus.io/internal/traceinternals.go delete mode 100644 vendor/go.opencensus.io/metric/metricdata/doc.go delete mode 100644 vendor/go.opencensus.io/metric/metricdata/exemplar.go delete mode 100644 vendor/go.opencensus.io/metric/metricdata/label.go delete mode 100644 vendor/go.opencensus.io/metric/metricdata/metric.go delete mode 100644 vendor/go.opencensus.io/metric/metricdata/point.go delete mode 100644 vendor/go.opencensus.io/metric/metricdata/type_string.go delete mode 100644 vendor/go.opencensus.io/metric/metricdata/unit.go delete mode 100644 vendor/go.opencensus.io/metric/metricproducer/manager.go delete mode 100644 vendor/go.opencensus.io/metric/metricproducer/producer.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/client.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/client_metrics.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/client_stats_handler.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/doc.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/server.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/server_metrics.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/server_stats_handler.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/stats_common.go delete mode 100644 vendor/go.opencensus.io/plugin/ocgrpc/trace_common.go delete mode 100644 vendor/go.opencensus.io/resource/resource.go delete mode 100644 vendor/go.opencensus.io/stats/doc.go delete mode 100644 vendor/go.opencensus.io/stats/internal/record.go delete mode 100644 vendor/go.opencensus.io/stats/measure.go delete mode 100644 vendor/go.opencensus.io/stats/measure_float64.go delete mode 100644 vendor/go.opencensus.io/stats/measure_int64.go delete mode 100644 vendor/go.opencensus.io/stats/record.go delete mode 100644 vendor/go.opencensus.io/stats/units.go delete mode 100644 vendor/go.opencensus.io/stats/view/aggregation.go delete mode 100644 vendor/go.opencensus.io/stats/view/aggregation_data.go delete mode 100644 vendor/go.opencensus.io/stats/view/collector.go delete mode 100644 vendor/go.opencensus.io/stats/view/doc.go delete mode 100644 vendor/go.opencensus.io/stats/view/export.go delete mode 100644 vendor/go.opencensus.io/stats/view/view.go delete mode 100644 vendor/go.opencensus.io/stats/view/view_to_metric.go delete mode 100644 vendor/go.opencensus.io/stats/view/worker.go delete mode 100644 vendor/go.opencensus.io/stats/view/worker_commands.go delete mode 100644 vendor/go.opencensus.io/tag/context.go delete mode 100644 vendor/go.opencensus.io/tag/doc.go delete mode 100644 vendor/go.opencensus.io/tag/key.go delete mode 100644 vendor/go.opencensus.io/tag/map.go delete mode 100644 vendor/go.opencensus.io/tag/map_codec.go delete mode 100644 vendor/go.opencensus.io/tag/metadata.go delete mode 100644 vendor/go.opencensus.io/tag/profile_19.go delete mode 100644 vendor/go.opencensus.io/tag/profile_not19.go delete mode 100644 vendor/go.opencensus.io/tag/validate.go delete mode 100644 vendor/go.opencensus.io/trace/basetypes.go delete mode 100644 vendor/go.opencensus.io/trace/config.go delete mode 100644 vendor/go.opencensus.io/trace/doc.go delete mode 100644 vendor/go.opencensus.io/trace/evictedqueue.go delete mode 100644 vendor/go.opencensus.io/trace/export.go delete mode 100644 vendor/go.opencensus.io/trace/internal/internal.go delete mode 100644 vendor/go.opencensus.io/trace/lrumap.go delete mode 100644 vendor/go.opencensus.io/trace/propagation/propagation.go delete mode 100644 vendor/go.opencensus.io/trace/sampling.go delete mode 100644 vendor/go.opencensus.io/trace/spanbucket.go delete mode 100644 vendor/go.opencensus.io/trace/spanstore.go delete mode 100644 vendor/go.opencensus.io/trace/status_codes.go delete mode 100644 vendor/go.opencensus.io/trace/trace.go delete mode 100644 vendor/go.opencensus.io/trace/trace_api.go delete mode 100644 vendor/go.opencensus.io/trace/trace_go11.go delete mode 100644 vendor/go.opencensus.io/trace/trace_nongo11.go delete mode 100644 vendor/go.opencensus.io/trace/tracestate/tracestate.go rename vendor/{go.opencensus.io => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc}/LICENSE (99%) create mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/config.go create mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/doc.go create mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go create mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go create mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal/parse.go create mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/metadata_supplier.go create mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/semconv.go create mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go rename vendor/{go.opencensus.io/opencensus.go => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go} (55%) diff --git a/cmd/containerd-shim-runhcs-v1/delete.go b/cmd/containerd-shim-runhcs-v1/delete.go index 5c8f8313e4..389a4c7b7b 100644 --- a/cmd/containerd-shim-runhcs-v1/delete.go +++ b/cmd/containerd-shim-runhcs-v1/delete.go @@ -18,7 +18,7 @@ import ( "github.com/Microsoft/hcsshim/internal/hcs" "github.com/Microsoft/hcsshim/internal/memory" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/winapi" ) @@ -57,9 +57,9 @@ The delete command will be executed in the container's bundle as its cwd. // task.DeleteResponse by protocol. We can write to stderr which will be // logged as a warning in containerd. - ctx, span := oc.StartSpan(context.Background(), "delete") + ctx, span := otelutil.StartSpan(context.Background(), "delete") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() bundleFlag := cCtx.GlobalString("bundle") if bundleFlag == "" { diff --git a/cmd/containerd-shim-runhcs-v1/events.go b/cmd/containerd-shim-runhcs-v1/events.go index fd791e7adf..8c9519d652 100644 --- a/cmd/containerd-shim-runhcs-v1/events.go +++ b/cmd/containerd-shim-runhcs-v1/events.go @@ -6,10 +6,11 @@ import ( "context" "fmt" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/containerd/containerd/namespaces" shim "github.com/containerd/containerd/runtime/v2/shim" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) type publisher interface { @@ -39,12 +40,11 @@ func (e *eventPublisher) close() error { } func (e *eventPublisher) publishEvent(ctx context.Context, topic string, event interface{}) (err error) { - ctx, span := oc.StartSpan(ctx, "publishEvent") + ctx, span := otelutil.StartSpan(ctx, "publishEvent", trace.WithAttributes( + attribute.String("topic", topic), + attribute.String("event", fmt.Sprintf("%+v", event)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("topic", topic), - trace.StringAttribute("event", fmt.Sprintf("%+v", event))) + defer func() { otelutil.SetSpanStatus(span, err) }() if e == nil { return nil diff --git a/cmd/containerd-shim-runhcs-v1/exec_hcs.go b/cmd/containerd-shim-runhcs-v1/exec_hcs.go index 84cdb38d24..fd770cd45a 100644 --- a/cmd/containerd-shim-runhcs-v1/exec_hcs.go +++ b/cmd/containerd-shim-runhcs-v1/exec_hcs.go @@ -15,14 +15,15 @@ import ( "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "google.golang.org/protobuf/types/known/timestamppb" "github.com/Microsoft/hcsshim/internal/cmd" "github.com/Microsoft/hcsshim/internal/cow" "github.com/Microsoft/hcsshim/internal/hcs" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" "github.com/Microsoft/hcsshim/internal/signals" "github.com/Microsoft/hcsshim/internal/uvm" @@ -448,12 +449,11 @@ func (he *hcsExec) exitFromCreatedL(ctx context.Context, status int) { // `Create`/`Wait`/`Start` which is a valid pattern. func (he *hcsExec) waitForExit() { var err error // this will only save the last error, since we dont return early on error - ctx, span := oc.StartSpan(context.Background(), "hcsExec::waitForExit") + ctx, span := otelutil.StartSpan(context.Background(), "hcsExec::waitForExit", trace.WithAttributes( + attribute.String("tid", he.tid), + attribute.String("eid", he.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("tid", he.tid), - trace.StringAttribute("eid", he.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = he.p.Process.Wait() if err != nil { @@ -511,11 +511,10 @@ func (he *hcsExec) waitForExit() { // // This MUST be called via a goroutine at exec create. func (he *hcsExec) waitForContainerExit() { - ctx, span := oc.StartSpan(context.Background(), "hcsExec::waitForContainerExit") + ctx, span := otelutil.StartSpan(context.Background(), "hcsExec::waitForContainerExit", trace.WithAttributes( + attribute.String("tid", he.tid), + attribute.String("eid", he.id))) defer span.End() - span.AddAttributes( - trace.StringAttribute("tid", he.tid), - trace.StringAttribute("eid", he.id)) // wait for container or process to exit and ckean up resrources select { diff --git a/cmd/containerd-shim-runhcs-v1/main.go b/cmd/containerd-shim-runhcs-v1/main.go index be5e950f16..0d3e24ca76 100644 --- a/cmd/containerd-shim-runhcs-v1/main.go +++ b/cmd/containerd-shim-runhcs-v1/main.go @@ -16,10 +16,11 @@ import ( specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" "github.com/urfave/cli" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel" + sdktrace "go.opentelemetry.io/otel/sdk/trace" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/shimdiag" hcsversion "github.com/Microsoft/hcsshim/internal/version" @@ -102,9 +103,11 @@ func main() { ), ) - // Register our OpenCensus logrus exporter - trace.ApplyConfig(trace.Config{DefaultSampler: oc.DefaultSampler}) - trace.RegisterExporter(&oc.LogrusExporter{}) + // Register our OTel logrus exporter + otel.SetTracerProvider(sdktrace.NewTracerProvider( + sdktrace.WithSampler(otelutil.DefaultSampler), + sdktrace.WithBatcher(&otelutil.LogrusExporter{}), + )) app := cli.NewApp() app.Name = "containerd-shim-runhcs-v1" diff --git a/cmd/containerd-shim-runhcs-v1/serve.go b/cmd/containerd-shim-runhcs-v1/serve.go index 290f986c42..61aeb32695 100644 --- a/cmd/containerd-shim-runhcs-v1/serve.go +++ b/cmd/containerd-shim-runhcs-v1/serve.go @@ -27,7 +27,7 @@ import ( "github.com/Microsoft/hcsshim/internal/extendedtask" hcslog "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/shimdiag" - "github.com/Microsoft/hcsshim/pkg/octtrpc" + "github.com/Microsoft/hcsshim/pkg/otelttrpc" ) var svc *service @@ -193,7 +193,7 @@ var serveCommand = cli.Command{ return fmt.Errorf("failed to create new service: %w", err) } - s, err := ttrpc.NewServer(ttrpc.WithUnaryServerInterceptor(octtrpc.ServerInterceptor())) + s, err := ttrpc.NewServer(ttrpc.WithUnaryServerInterceptor(otelttrpc.ServerInterceptor())) if err != nil { return err } diff --git a/cmd/containerd-shim-runhcs-v1/service.go b/cmd/containerd-shim-runhcs-v1/service.go index 04647c7677..dd1b23b250 100644 --- a/cmd/containerd-shim-runhcs-v1/service.go +++ b/cmd/containerd-shim-runhcs-v1/service.go @@ -13,11 +13,12 @@ import ( task "github.com/containerd/containerd/api/runtime/task/v2" "github.com/containerd/errdefs" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "google.golang.org/protobuf/types/known/emptypb" "github.com/Microsoft/hcsshim/internal/extendedtask" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/shimdiag" ) @@ -99,24 +100,22 @@ func NewService(o ...ServiceOption) (svc *service, err error) { } func (s *service) State(ctx context.Context, req *task.StateRequest) (resp *task.StateResponse, err error) { - ctx, span := oc.StartSpan(ctx, "State") + ctx, span := otelutil.StartSpan(ctx, "State", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("eid", req.ExecID))) defer span.End() defer func() { if resp != nil { - span.AddAttributes( - trace.StringAttribute("status", resp.Status.String()), - trace.Int64Attribute("exitStatus", int64(resp.ExitStatus)), - trace.StringAttribute("exitedAt", resp.ExitedAt.String())) + span.SetAttributes( + attribute.String("status", resp.Status.String()), + attribute.Int64("exitStatus", int64(resp.ExitStatus)), + attribute.String("exitedAt", resp.ExitedAt.String())) } - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("eid", req.ExecID)) - if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.stateInternal(ctx, req) @@ -124,29 +123,27 @@ func (s *service) State(ctx context.Context, req *task.StateRequest) (resp *task } func (s *service) Create(ctx context.Context, req *task.CreateTaskRequest) (resp *task.CreateTaskResponse, err error) { - ctx, span := oc.StartSpan(ctx, "Create") + ctx, span := otelutil.StartSpan(ctx, "Create", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("bundle", req.Bundle), + // attribute.String("rootfs", req.Rootfs), TODO: JTERRY75 - + // OpenCensus doesnt support slice like our logrus hook + attribute.Bool("terminal", req.Terminal), + attribute.String("stdin", req.Stdin), + attribute.String("stdout", req.Stdout), + attribute.String("stderr", req.Stderr), + attribute.String("checkpoint", req.Checkpoint), + attribute.String("parentcheckpoint", req.ParentCheckpoint))) defer span.End() defer func() { if resp != nil { - span.AddAttributes(trace.Int64Attribute("pid", int64(resp.Pid))) + span.SetAttributes(attribute.Int64("pid", int64(resp.Pid))) } - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("bundle", req.Bundle), - // trace.StringAttribute("rootfs", req.Rootfs), TODO: JTERRY75 - - // OpenCensus doesnt support slice like our logrus hook - trace.BoolAttribute("terminal", req.Terminal), - trace.StringAttribute("stdin", req.Stdin), - trace.StringAttribute("stdout", req.Stdout), - trace.StringAttribute("stderr", req.Stderr), - trace.StringAttribute("checkpoint", req.Checkpoint), - trace.StringAttribute("parentcheckpoint", req.ParentCheckpoint)) - if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.createInternal(ctx, req) @@ -154,21 +151,19 @@ func (s *service) Create(ctx context.Context, req *task.CreateTaskRequest) (resp } func (s *service) Start(ctx context.Context, req *task.StartRequest) (resp *task.StartResponse, err error) { - ctx, span := oc.StartSpan(ctx, "Start") + ctx, span := otelutil.StartSpan(ctx, "Start", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("eid", req.ExecID))) defer span.End() defer func() { if resp != nil { - span.AddAttributes(trace.Int64Attribute("pid", int64(resp.Pid))) + span.SetAttributes(attribute.Int64("pid", int64(resp.Pid))) } - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("eid", req.ExecID)) - if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.startInternal(ctx, req) @@ -176,24 +171,22 @@ func (s *service) Start(ctx context.Context, req *task.StartRequest) (resp *task } func (s *service) Delete(ctx context.Context, req *task.DeleteRequest) (resp *task.DeleteResponse, err error) { - ctx, span := oc.StartSpan(ctx, "Delete") + ctx, span := otelutil.StartSpan(ctx, "Delete", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("eid", req.ExecID))) defer span.End() defer func() { if resp != nil { - span.AddAttributes( - trace.Int64Attribute("pid", int64(resp.Pid)), - trace.Int64Attribute("exitStatus", int64(resp.ExitStatus)), - trace.StringAttribute("exitedAt", resp.ExitedAt.String())) + span.SetAttributes( + attribute.Int64("pid", int64(resp.Pid)), + attribute.Int64("exitStatus", int64(resp.ExitStatus)), + attribute.String("exitedAt", resp.ExitedAt.String())) } - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("eid", req.ExecID)) - if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.deleteInternal(ctx, req) @@ -201,14 +194,13 @@ func (s *service) Delete(ctx context.Context, req *task.DeleteRequest) (resp *ta } func (s *service) Pids(ctx context.Context, req *task.PidsRequest) (_ *task.PidsResponse, err error) { - ctx, span := oc.StartSpan(ctx, "Pids") + ctx, span := otelutil.StartSpan(ctx, "Pids", trace.WithAttributes( + attribute.String("tid", req.ID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes(trace.StringAttribute("tid", req.ID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.pidsInternal(ctx, req) @@ -216,14 +208,13 @@ func (s *service) Pids(ctx context.Context, req *task.PidsRequest) (_ *task.Pids } func (s *service) Pause(ctx context.Context, req *task.PauseRequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "Pause") + ctx, span := otelutil.StartSpan(ctx, "Pause", trace.WithAttributes( + attribute.String("tid", req.ID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes(trace.StringAttribute("tid", req.ID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.pauseInternal(ctx, req) @@ -231,14 +222,13 @@ func (s *service) Pause(ctx context.Context, req *task.PauseRequest) (_ *emptypb } func (s *service) Resume(ctx context.Context, req *task.ResumeRequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "Resume") + ctx, span := otelutil.StartSpan(ctx, "Resume", trace.WithAttributes( + attribute.String("tid", req.ID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes(trace.StringAttribute("tid", req.ID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.resumeInternal(ctx, req) @@ -246,16 +236,14 @@ func (s *service) Resume(ctx context.Context, req *task.ResumeRequest) (_ *empty } func (s *service) Checkpoint(ctx context.Context, req *task.CheckpointTaskRequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "Checkpoint") + ctx, span := otelutil.StartSpan(ctx, "Checkpoint", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("path", req.Path))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("path", req.Path)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.checkpointInternal(ctx, req) @@ -263,18 +251,16 @@ func (s *service) Checkpoint(ctx context.Context, req *task.CheckpointTaskReques } func (s *service) Kill(ctx context.Context, req *task.KillRequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "Kill") + ctx, span := otelutil.StartSpan(ctx, "Kill", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("eid", req.ExecID), + attribute.Int64("signal", int64(req.Signal)), + attribute.Bool("all", req.All))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("eid", req.ExecID), - trace.Int64Attribute("signal", int64(req.Signal)), - trace.BoolAttribute("all", req.All)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.killInternal(ctx, req) @@ -282,20 +268,18 @@ func (s *service) Kill(ctx context.Context, req *task.KillRequest) (_ *emptypb.E } func (s *service) Exec(ctx context.Context, req *task.ExecProcessRequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "Exec") + ctx, span := otelutil.StartSpan(ctx, "Exec", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("eid", req.ExecID), + attribute.Bool("terminal", req.Terminal), + attribute.String("stdin", req.Stdin), + attribute.String("stdout", req.Stdout), + attribute.String("stderr", req.Stderr))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("eid", req.ExecID), - trace.BoolAttribute("terminal", req.Terminal), - trace.StringAttribute("stdin", req.Stdin), - trace.StringAttribute("stdout", req.Stdout), - trace.StringAttribute("stderr", req.Stderr)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.execInternal(ctx, req) @@ -303,20 +287,18 @@ func (s *service) Exec(ctx context.Context, req *task.ExecProcessRequest) (_ *em } func (s *service) DiagExecInHost(ctx context.Context, req *shimdiag.ExecProcessRequest) (_ *shimdiag.ExecProcessResponse, err error) { - ctx, span := oc.StartSpan(ctx, "DiagExecInHost") + ctx, span := otelutil.StartSpan(ctx, "DiagExecInHost", trace.WithAttributes( + attribute.String("args", strings.Join(req.Args, " ")), + attribute.String("workdir", req.Workdir), + attribute.Bool("terminal", req.Terminal), + attribute.String("stdin", req.Stdin), + attribute.String("stdout", req.Stdout), + attribute.String("stderr", req.Stderr))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("args", strings.Join(req.Args, " ")), - trace.StringAttribute("workdir", req.Workdir), - trace.BoolAttribute("terminal", req.Terminal), - trace.StringAttribute("stdin", req.Stdin), - trace.StringAttribute("stdout", req.Stdout), - trace.StringAttribute("stderr", req.Stderr)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.diagExecInHostInternal(ctx, req) @@ -324,17 +306,15 @@ func (s *service) DiagExecInHost(ctx context.Context, req *shimdiag.ExecProcessR } func (s *service) DiagShare(ctx context.Context, req *shimdiag.ShareRequest) (_ *shimdiag.ShareResponse, err error) { - ctx, span := oc.StartSpan(ctx, "DiagShare") + ctx, span := otelutil.StartSpan(ctx, "DiagShare", trace.WithAttributes( + attribute.String("hostpath", req.HostPath), + attribute.String("uvmpath", req.UvmPath), + attribute.Bool("readonly", req.ReadOnly))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("hostpath", req.HostPath), - trace.StringAttribute("uvmpath", req.UvmPath), - trace.BoolAttribute("readonly", req.ReadOnly)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.diagShareInternal(ctx, req) @@ -342,15 +322,13 @@ func (s *service) DiagShare(ctx context.Context, req *shimdiag.ShareRequest) (_ } func (s *service) DiagTasks(ctx context.Context, req *shimdiag.TasksRequest) (_ *shimdiag.TasksResponse, err error) { - ctx, span := oc.StartSpan(ctx, "DiagTasks") + ctx, span := otelutil.StartSpan(ctx, "DiagTasks", trace.WithAttributes( + attribute.Bool("execs", req.Execs))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.BoolAttribute("execs", req.Execs)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.diagTasksInternal(ctx, req) @@ -358,18 +336,16 @@ func (s *service) DiagTasks(ctx context.Context, req *shimdiag.TasksRequest) (_ } func (s *service) ResizePty(ctx context.Context, req *task.ResizePtyRequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "ResizePty") + ctx, span := otelutil.StartSpan(ctx, "ResizePty", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("eid", req.ExecID), + attribute.Int64("width", int64(req.Width)), + attribute.Int64("height", int64(req.Height)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("eid", req.ExecID), - trace.Int64Attribute("width", int64(req.Width)), - trace.Int64Attribute("height", int64(req.Height))) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.resizePtyInternal(ctx, req) @@ -377,17 +353,15 @@ func (s *service) ResizePty(ctx context.Context, req *task.ResizePtyRequest) (_ } func (s *service) CloseIO(ctx context.Context, req *task.CloseIORequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "CloseIO") + ctx, span := otelutil.StartSpan(ctx, "CloseIO", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("eid", req.ExecID), + attribute.Bool("stdin", req.Stdin))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("eid", req.ExecID), - trace.BoolAttribute("stdin", req.Stdin)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.closeIOInternal(ctx, req) @@ -395,14 +369,13 @@ func (s *service) CloseIO(ctx context.Context, req *task.CloseIORequest) (_ *emp } func (s *service) Update(ctx context.Context, req *task.UpdateTaskRequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "Update") + ctx, span := otelutil.StartSpan(ctx, "Update", trace.WithAttributes( + attribute.String("tid", req.ID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes(trace.StringAttribute("tid", req.ID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.updateInternal(ctx, req) @@ -410,23 +383,21 @@ func (s *service) Update(ctx context.Context, req *task.UpdateTaskRequest) (_ *e } func (s *service) Wait(ctx context.Context, req *task.WaitRequest) (resp *task.WaitResponse, err error) { - ctx, span := oc.StartSpan(ctx, "Wait") + ctx, span := otelutil.StartSpan(ctx, "Wait", trace.WithAttributes( + attribute.String("tid", req.ID), + attribute.String("eid", req.ExecID))) defer span.End() defer func() { if resp != nil { - span.AddAttributes( - trace.Int64Attribute("exitStatus", int64(resp.ExitStatus)), - trace.StringAttribute("exitedAt", resp.ExitedAt.String())) + span.SetAttributes( + attribute.Int64("exitStatus", int64(resp.ExitStatus)), + attribute.String("exitedAt", resp.ExitedAt.String())) } - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("tid", req.ID), - trace.StringAttribute("eid", req.ExecID)) - if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.waitInternal(ctx, req) @@ -434,14 +405,13 @@ func (s *service) Wait(ctx context.Context, req *task.WaitRequest) (resp *task.W } func (s *service) Stats(ctx context.Context, req *task.StatsRequest) (_ *task.StatsResponse, err error) { - ctx, span := oc.StartSpan(ctx, "Stats") + ctx, span := otelutil.StartSpan(ctx, "Stats", trace.WithAttributes( + attribute.String("tid", req.ID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes(trace.StringAttribute("tid", req.ID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.statsInternal(ctx, req) @@ -449,22 +419,21 @@ func (s *service) Stats(ctx context.Context, req *task.StatsRequest) (_ *task.St } func (s *service) Connect(ctx context.Context, req *task.ConnectRequest) (resp *task.ConnectResponse, err error) { - ctx, span := oc.StartSpan(ctx, "Connect") + ctx, span := otelutil.StartSpan(ctx, "Connect", trace.WithAttributes( + attribute.String("tid", req.ID))) defer span.End() defer func() { if resp != nil { - span.AddAttributes( - trace.Int64Attribute("shimPid", int64(resp.ShimPid)), - trace.Int64Attribute("taskPid", int64(resp.TaskPid)), - trace.StringAttribute("version", resp.Version)) + span.SetAttributes( + attribute.Int64("shimPid", int64(resp.ShimPid)), + attribute.Int64("taskPid", int64(resp.TaskPid)), + attribute.String("version", resp.Version)) } - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("tid", req.ID)) - if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.connectInternal(ctx, req) @@ -472,14 +441,13 @@ func (s *service) Connect(ctx context.Context, req *task.ConnectRequest) (resp * } func (s *service) Shutdown(ctx context.Context, req *task.ShutdownRequest) (_ *emptypb.Empty, err error) { - ctx, span := oc.StartSpan(ctx, "Shutdown") + ctx, span := otelutil.StartSpan(ctx, "Shutdown", trace.WithAttributes( + attribute.String("tid", req.ID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes(trace.StringAttribute("tid", req.ID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } r, e := s.shutdownInternal(ctx, req) @@ -490,13 +458,12 @@ func (s *service) DiagStacks(ctx context.Context, req *shimdiag.StacksRequest) ( if s == nil { return nil, nil } - ctx, span := oc.StartSpan(ctx, "DiagStacks") + ctx, span := otelutil.StartSpan(ctx, "DiagStacks", trace.WithAttributes( + attribute.String("tid", s.tid))) defer span.End() - span.AddAttributes(trace.StringAttribute("tid", s.tid)) - if s.isSandbox { - span.AddAttributes(trace.StringAttribute("pod-id", s.tid)) + span.SetAttributes(attribute.String("pod-id", s.tid)) } buf := make([]byte, 4096) @@ -522,22 +489,20 @@ func (s *service) DiagPid(ctx context.Context, req *shimdiag.PidRequest) (*shimd if s == nil { return nil, nil } - ctx, span := oc.StartSpan(ctx, "DiagPid") //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, "DiagPid", trace.WithAttributes( + attribute.String("tid", s.tid))) //nolint:ineffassign,staticcheck defer span.End() - span.AddAttributes(trace.StringAttribute("tid", s.tid)) - return &shimdiag.PidResponse{ Pid: int32(os.Getpid()), }, nil } func (s *service) ComputeProcessorInfo(ctx context.Context, req *extendedtask.ComputeProcessorInfoRequest) (*extendedtask.ComputeProcessorInfoResponse, error) { - ctx, span := oc.StartSpan(ctx, "ComputeProcessorInfo") + ctx, span := otelutil.StartSpan(ctx, "ComputeProcessorInfo", trace.WithAttributes( + attribute.String("tid", s.tid))) defer span.End() - span.AddAttributes(trace.StringAttribute("tid", s.tid)) - r, e := s.computeProcessorInfoInternal(ctx, req) return r, errdefs.ToGRPC(e) } diff --git a/cmd/containerd-shim-runhcs-v1/task_hcs.go b/cmd/containerd-shim-runhcs-v1/task_hcs.go index d544cb0934..70f87def41 100644 --- a/cmd/containerd-shim-runhcs-v1/task_hcs.go +++ b/cmd/containerd-shim-runhcs-v1/task_hcs.go @@ -20,7 +20,8 @@ import ( "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "google.golang.org/protobuf/types/known/timestamppb" "github.com/Microsoft/go-winio/pkg/fs" @@ -38,8 +39,8 @@ import ( "github.com/Microsoft/hcsshim/internal/layers" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/memory" - "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/internal/oci" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/processorinfo" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" @@ -605,9 +606,9 @@ func (ht *hcsTask) Wait() *task.StateResponse { } func (ht *hcsTask) waitInitExit() { - ctx, span := oc.StartSpan(context.Background(), "hcsTask::waitInitExit") + ctx, span := otelutil.StartSpan(context.Background(), "hcsTask::waitInitExit", trace.WithAttributes( + attribute.String("tid", ht.id))) defer span.End() - span.AddAttributes(trace.StringAttribute("tid", ht.id)) // Wait for it to exit on its own ht.init.Wait() @@ -624,9 +625,9 @@ func (ht *hcsTask) waitInitExit() { // Note: For Windows process isolated containers there is no host virtual // machine so this should not be called. func (ht *hcsTask) waitForHostExit() { - ctx, span := oc.StartSpan(context.Background(), "hcsTask::waitForHostExit") + ctx, span := otelutil.StartSpan(context.Background(), "hcsTask::waitForHostExit", trace.WithAttributes( + attribute.String("tid", ht.id))) defer span.End() - span.AddAttributes(trace.StringAttribute("tid", ht.id)) err := ht.host.WaitCtx(ctx) if err != nil { diff --git a/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go b/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go index 423c5c23de..04f709c7a9 100644 --- a/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go +++ b/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go @@ -11,7 +11,7 @@ import ( "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats" "github.com/Microsoft/hcsshim/internal/cmd" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/shimdiag" "github.com/Microsoft/hcsshim/internal/uvm" eventstypes "github.com/containerd/containerd/api/events" @@ -21,7 +21,8 @@ import ( typeurl "github.com/containerd/typeurl/v2" "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // newWcowPodSandboxTask creates a fake WCOW task with a fake WCOW `init` @@ -212,9 +213,9 @@ func (wpst *wcowPodSandboxTask) close(ctx context.Context) { } func (wpst *wcowPodSandboxTask) waitInitExit() { - ctx, span := oc.StartSpan(context.Background(), "wcowPodSandboxTask::waitInitExit") + ctx, span := otelutil.StartSpan(context.Background(), "wcowPodSandboxTask::waitInitExit", trace.WithAttributes( + attribute.String("tid", wpst.id))) defer span.End() - span.AddAttributes(trace.StringAttribute("tid", wpst.id)) // Wait for it to exit on its own wpst.init.Wait() @@ -224,9 +225,9 @@ func (wpst *wcowPodSandboxTask) waitInitExit() { } func (wpst *wcowPodSandboxTask) waitParentExit() { - ctx, span := oc.StartSpan(context.Background(), "wcowPodSandboxTask::waitParentExit") + ctx, span := otelutil.StartSpan(context.Background(), "wcowPodSandboxTask::waitParentExit", trace.WithAttributes( + attribute.String("tid", wpst.id))) defer span.End() - span.AddAttributes(trace.StringAttribute("tid", wpst.id)) werr := wpst.host.WaitCtx(ctx) if werr != nil { diff --git a/cmd/gcs/main.go b/cmd/gcs/main.go index 25751763dd..3e451d8914 100644 --- a/cmd/gcs/main.go +++ b/cmd/gcs/main.go @@ -19,7 +19,8 @@ import ( oci "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel" + sdktrace "go.opentelemetry.io/otel/sdk/trace" "github.com/Microsoft/hcsshim/internal/guest/bridge" "github.com/Microsoft/hcsshim/internal/guest/kmsg" @@ -28,7 +29,7 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/transport" "github.com/Microsoft/hcsshim/internal/guestpath" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/version" "github.com/Microsoft/hcsshim/pkg/securitypolicy" ) @@ -210,10 +211,12 @@ func main() { flag.Parse() - // If v4 enable opencensus + // If v4 enable OTel if *v4 { - trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) - trace.RegisterExporter(&oc.LogrusExporter{}) + otel.SetTracerProvider(sdktrace.NewTracerProvider( + sdktrace.WithSampler(otelutil.DefaultSampler), + sdktrace.WithBatcher(&otelutil.LogrusExporter{}), + )) } logrus.AddHook(log.NewHook()) diff --git a/cmd/ncproxy/ncproxy.go b/cmd/ncproxy/ncproxy.go index af2f18a860..6f8f452d01 100644 --- a/cmd/ncproxy/ncproxy.go +++ b/cmd/ncproxy/ncproxy.go @@ -12,7 +12,8 @@ import ( "github.com/containerd/ttrpc" typeurl "github.com/containerd/typeurl/v2" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -22,11 +23,11 @@ import ( ncproxynetworking "github.com/Microsoft/hcsshim/internal/ncproxy/networking" ncproxystore "github.com/Microsoft/hcsshim/internal/ncproxy/store" "github.com/Microsoft/hcsshim/internal/ncproxyttrpc" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/uvm" ncproxygrpc "github.com/Microsoft/hcsshim/pkg/ncproxy/ncproxygrpc/v1" nodenetsvc "github.com/Microsoft/hcsshim/pkg/ncproxy/nodenetsvc/v1" - "github.com/Microsoft/hcsshim/pkg/octtrpc" + "github.com/Microsoft/hcsshim/pkg/otelttrpc" ) func init() { @@ -66,14 +67,12 @@ func newGRPCService(agentCache *computeAgentCache, ncproxyNetworking *ncproxysto var _ ncproxygrpc.NetworkConfigProxyServer = &grpcService{} func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest) (_ *ncproxygrpc.AddNICResponse, err error) { - ctx, span := oc.StartSpan(ctx, "AddNIC") + ctx, span := otelutil.StartSpan(ctx, "AddNIC", trace.WithAttributes( + attribute.String("containerID", req.ContainerID), + attribute.String("endpointName", req.EndpointName), + attribute.String("nicID", req.NicID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("containerID", req.ContainerID), - trace.StringAttribute("endpointName", req.EndpointName), - trace.StringAttribute("nicID", req.NicID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.ContainerID == "" || req.EndpointName == "" || req.NicID == "" { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -161,14 +160,12 @@ func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest } func (s *grpcService) ModifyNIC(ctx context.Context, req *ncproxygrpc.ModifyNICRequest) (_ *ncproxygrpc.ModifyNICResponse, err error) { - ctx, span := oc.StartSpan(ctx, "ModifyNIC") + ctx, span := otelutil.StartSpan(ctx, "ModifyNIC", trace.WithAttributes( + attribute.String("containerID", req.ContainerID), + attribute.String("endpointName", req.EndpointName), + attribute.String("nicID", req.NicID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("containerID", req.ContainerID), - trace.StringAttribute("endpointName", req.EndpointName), - trace.StringAttribute("nicID", req.NicID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.ContainerID == "" || req.EndpointName == "" || req.NicID == "" || req.EndpointSettings == nil { return nil, status.Error(codes.InvalidArgument, "received empty field in request") @@ -255,14 +252,12 @@ func (s *grpcService) ModifyNIC(ctx context.Context, req *ncproxygrpc.ModifyNICR } func (s *grpcService) DeleteNIC(ctx context.Context, req *ncproxygrpc.DeleteNICRequest) (_ *ncproxygrpc.DeleteNICResponse, err error) { - ctx, span := oc.StartSpan(ctx, "DeleteNIC") + ctx, span := otelutil.StartSpan(ctx, "DeleteNIC", trace.WithAttributes( + attribute.String("containerID", req.ContainerID), + attribute.String("endpointName", req.EndpointName), + attribute.String("nicID", req.NicID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("containerID", req.ContainerID), - trace.StringAttribute("endpointName", req.EndpointName), - trace.StringAttribute("nicID", req.NicID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.ContainerID == "" || req.EndpointName == "" || req.NicID == "" { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -310,9 +305,9 @@ func (s *grpcService) DeleteNIC(ctx context.Context, req *ncproxygrpc.DeleteNICR } func (s *grpcService) CreateNetwork(ctx context.Context, req *ncproxygrpc.CreateNetworkRequest) (_ *ncproxygrpc.CreateNetworkResponse, err error) { - ctx, span := oc.StartSpan(ctx, "CreateNetwork") + ctx, span := otelutil.StartSpan(ctx, "CreateNetwork") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() if req.Network == nil || req.Network.GetSettings() == nil { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -324,10 +319,10 @@ func (s *grpcService) CreateNetwork(ctx context.Context, req *ncproxygrpc.Create if networkReq.Name == "" { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) } - span.AddAttributes( - trace.StringAttribute("networkName", networkReq.Name), - trace.StringAttribute("type", networkReq.Mode.String()), - trace.StringAttribute("ipamType", networkReq.IpamType.String())) + span.SetAttributes( + attribute.String("networkName", networkReq.Name), + attribute.String("type", networkReq.Mode.String()), + attribute.String("ipamType", networkReq.IpamType.String())) network, err := createHCNNetwork(ctx, networkReq) if err != nil { @@ -360,9 +355,9 @@ func (s *grpcService) CreateNetwork(ctx context.Context, req *ncproxygrpc.Create } func (s *grpcService) CreateEndpoint(ctx context.Context, req *ncproxygrpc.CreateEndpointRequest) (_ *ncproxygrpc.CreateEndpointResponse, err error) { - ctx, span := oc.StartSpan(ctx, "CreateEndpoint") + ctx, span := otelutil.StartSpan(ctx, "CreateEndpoint") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() if req.EndpointSettings == nil { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -372,11 +367,11 @@ func (s *grpcService) CreateEndpoint(ctx context.Context, req *ncproxygrpc.Creat case *ncproxygrpc.EndpointSettings_HcnEndpoint: reqEndpoint := req.EndpointSettings.GetHcnEndpoint() - span.AddAttributes( - trace.StringAttribute("macAddr", reqEndpoint.Macaddress), - trace.StringAttribute("endpointName", reqEndpoint.Name), - trace.StringAttribute("ipAddr", reqEndpoint.Ipaddress), - trace.StringAttribute("networkName", reqEndpoint.NetworkName)) + span.SetAttributes( + attribute.String("macAddr", reqEndpoint.Macaddress), + attribute.String("endpointName", reqEndpoint.Name), + attribute.String("ipAddr", reqEndpoint.Ipaddress), + attribute.String("networkName", reqEndpoint.NetworkName)) if reqEndpoint.Name == "" || reqEndpoint.Ipaddress == "" || reqEndpoint.Macaddress == "" || reqEndpoint.NetworkName == "" { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -437,13 +432,11 @@ func (s *grpcService) CreateEndpoint(ctx context.Context, req *ncproxygrpc.Creat } func (s *grpcService) AddEndpoint(ctx context.Context, req *ncproxygrpc.AddEndpointRequest) (_ *ncproxygrpc.AddEndpointResponse, err error) { - ctx, span := oc.StartSpan(ctx, "AddEndpoint") + ctx, span := otelutil.StartSpan(ctx, "AddEndpoint", trace.WithAttributes( + attribute.String("endpointName", req.Name), + attribute.String("namespaceID", req.NamespaceID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("endpointName", req.Name), - trace.StringAttribute("namespaceID", req.NamespaceID)) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.Name == "" || (!req.AttachToHost && req.NamespaceID == "") { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -480,7 +473,7 @@ func (s *grpcService) AddEndpoint(ctx context.Context, req *ncproxygrpc.AddEndpo req.NamespaceID = nsID log.G(ctx).WithField("namespaceID", req.NamespaceID).Debug("Attaching endpoint to default host namespace") // replace current span namespaceID attribute - span.AddAttributes(trace.StringAttribute("namespaceID", req.NamespaceID)) + span.SetAttributes(attribute.String("namespaceID", req.NamespaceID)) } if err := hcn.AddNamespaceEndpoint(req.NamespaceID, ep.Id); err != nil { return nil, errors.Wrapf(err, "failed to add endpoint with name %q to namespace", req.Name) @@ -491,12 +484,10 @@ func (s *grpcService) AddEndpoint(ctx context.Context, req *ncproxygrpc.AddEndpo } func (s *grpcService) DeleteEndpoint(ctx context.Context, req *ncproxygrpc.DeleteEndpointRequest) (_ *ncproxygrpc.DeleteEndpointResponse, err error) { - ctx, span := oc.StartSpan(ctx, "DeleteEndpoint") + ctx, span := otelutil.StartSpan(ctx, "DeleteEndpoint", trace.WithAttributes( + attribute.String("endpointName", req.Name))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("endpointName", req.Name)) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.Name == "" { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -527,12 +518,10 @@ func (s *grpcService) DeleteEndpoint(ctx context.Context, req *ncproxygrpc.Delet } func (s *grpcService) DeleteNetwork(ctx context.Context, req *ncproxygrpc.DeleteNetworkRequest) (_ *ncproxygrpc.DeleteNetworkResponse, err error) { - ctx, span := oc.StartSpan(ctx, "DeleteNetwork") + ctx, span := otelutil.StartSpan(ctx, "DeleteNetwork", trace.WithAttributes( + attribute.String("networkName", req.Name))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("networkName", req.Name)) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.Name == "" { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -596,12 +585,10 @@ func ncpNetworkingEndpointToEndpointResponse(ep *ncproxynetworking.Endpoint) (_ } func (s *grpcService) GetEndpoint(ctx context.Context, req *ncproxygrpc.GetEndpointRequest) (_ *ncproxygrpc.GetEndpointResponse, err error) { - ctx, span := oc.StartSpan(ctx, "GetEndpoint") + ctx, span := otelutil.StartSpan(ctx, "GetEndpoint", trace.WithAttributes( + attribute.String("endpointName", req.Name))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("endpointName", req.Name)) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.Name == "" { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -624,9 +611,9 @@ func (s *grpcService) GetEndpoint(ctx context.Context, req *ncproxygrpc.GetEndpo } func (s *grpcService) GetEndpoints(ctx context.Context, req *ncproxygrpc.GetEndpointsRequest) (_ *ncproxygrpc.GetEndpointsResponse, err error) { - ctx, span := oc.StartSpan(ctx, "GetEndpoints") + ctx, span := otelutil.StartSpan(ctx, "GetEndpoints") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() endpoints := []*ncproxygrpc.GetEndpointResponse{} @@ -675,12 +662,10 @@ func ncpNetworkingNetworkToNetworkResponse(network *ncproxynetworking.Network) ( } func (s *grpcService) GetNetwork(ctx context.Context, req *ncproxygrpc.GetNetworkRequest) (_ *ncproxygrpc.GetNetworkResponse, err error) { - ctx, span := oc.StartSpan(ctx, "GetNetwork") + ctx, span := otelutil.StartSpan(ctx, "GetNetwork", trace.WithAttributes( + attribute.String("networkName", req.Name))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("networkName", req.Name)) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.Name == "" { return nil, status.Errorf(codes.InvalidArgument, "received empty field in request: %+v", req) @@ -704,9 +689,9 @@ func (s *grpcService) GetNetwork(ctx context.Context, req *ncproxygrpc.GetNetwor } func (s *grpcService) GetNetworks(ctx context.Context, req *ncproxygrpc.GetNetworksRequest) (_ *ncproxygrpc.GetNetworksResponse, err error) { - ctx, span := oc.StartSpan(ctx, "GetNetworks") + ctx, span := otelutil.StartSpan(ctx, "GetNetworks") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() networks := []*ncproxygrpc.GetNetworkResponse{} @@ -767,20 +752,18 @@ func getComputeAgentClient(agentAddr string) (*computeAgentClient, error) { } raw := ttrpcNewClient( conn, - ttrpc.WithUnaryClientInterceptor(octtrpc.ClientInterceptor()), + ttrpc.WithUnaryClientInterceptor(otelttrpc.ClientInterceptor()), ttrpc.WithOnClose(func() { conn.Close() }), ) return &computeAgentClient{raw, computeagent.NewComputeAgentClient(raw)}, nil } func (s *ttrpcService) RegisterComputeAgent(ctx context.Context, req *ncproxyttrpc.RegisterComputeAgentRequest) (_ *ncproxyttrpc.RegisterComputeAgentResponse, err error) { - ctx, span := oc.StartSpan(ctx, "RegisterComputeAgent") + ctx, span := otelutil.StartSpan(ctx, "RegisterComputeAgent", trace.WithAttributes( + attribute.String("containerID", req.ContainerID), + attribute.String("agentAddress", req.AgentAddress))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("containerID", req.ContainerID), - trace.StringAttribute("agentAddress", req.AgentAddress)) + defer func() { otelutil.SetSpanStatus(span, err) }() agent, err := getComputeAgentClient(req.AgentAddress) if err != nil { @@ -801,12 +784,10 @@ func (s *ttrpcService) RegisterComputeAgent(ctx context.Context, req *ncproxyttr } func (s *ttrpcService) UnregisterComputeAgent(ctx context.Context, req *ncproxyttrpc.UnregisterComputeAgentRequest) (_ *ncproxyttrpc.UnregisterComputeAgentResponse, err error) { - ctx, span := oc.StartSpan(ctx, "UnregisterComputeAgent") + ctx, span := otelutil.StartSpan(ctx, "UnregisterComputeAgent", trace.WithAttributes( + attribute.String("containerID", req.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("containerID", req.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = s.agentStore.DeleteComputeAgent(ctx, req.ContainerID) if err != nil { @@ -828,13 +809,11 @@ func (s *ttrpcService) UnregisterComputeAgent(ctx context.Context, req *ncproxyt } func (s *ttrpcService) ConfigureNetworking(ctx context.Context, req *ncproxyttrpc.ConfigureNetworkingInternalRequest) (_ *ncproxyttrpc.ConfigureNetworkingInternalResponse, err error) { - ctx, span := oc.StartSpan(ctx, "ConfigureNetworking") + ctx, span := otelutil.StartSpan(ctx, "ConfigureNetworking", trace.WithAttributes( + attribute.String("containerID", req.ContainerID), + attribute.String("agentAddress", req.RequestType.String()))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("containerID", req.ContainerID), - trace.StringAttribute("agentAddress", req.RequestType.String())) + defer func() { otelutil.SetSpanStatus(span, err) }() if req.ContainerID == "" { return nil, status.Error(codes.InvalidArgument, "ContainerID is empty") diff --git a/cmd/ncproxy/run.go b/cmd/ncproxy/run.go index 635260297e..c0bb10b5b6 100644 --- a/cmd/ncproxy/run.go +++ b/cmd/ncproxy/run.go @@ -19,8 +19,9 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" - "go.opencensus.io/plugin/ocgrpc" - "go.opencensus.io/trace" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + "go.opentelemetry.io/otel" + sdktrace "go.opentelemetry.io/otel/sdk/trace" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials/insecure" @@ -29,7 +30,7 @@ import ( "github.com/Microsoft/hcsshim/internal/computeagent" "github.com/Microsoft/hcsshim/internal/debug" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" nodenetsvcV0 "github.com/Microsoft/hcsshim/pkg/ncproxy/nodenetsvc/v0" nodenetsvc "github.com/Microsoft/hcsshim/pkg/ncproxy/nodenetsvc/v1" ) @@ -158,9 +159,11 @@ func run(clicontext *cli.Context) error { logrus.Error(err) } - // Register our OpenCensus logrus exporter - trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) - trace.RegisterExporter(&oc.LogrusExporter{}) + // Register our OTel logrus exporter + otel.SetTracerProvider(sdktrace.NewTracerProvider( + sdktrace.WithSampler(otelutil.DefaultSampler), + sdktrace.WithBatcher(&otelutil.LogrusExporter{}), + )) // If no logging directory passed in use where ncproxy is located. if logDir == "" { @@ -226,7 +229,7 @@ func run(clicontext *cli.Context) error { dialCtx := ctx opts := []grpc.DialOption{ grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithStatsHandler(&ocgrpc.ClientHandler{}), + grpc.WithStatsHandler(otelgrpc.NewClientHandler()), } if conf.Timeout > 0 { var cancel context.CancelFunc diff --git a/cmd/ncproxy/server.go b/cmd/ncproxy/server.go index ac808b5fcf..9758091ff8 100644 --- a/cmd/ncproxy/server.go +++ b/cmd/ncproxy/server.go @@ -14,12 +14,12 @@ import ( "github.com/Microsoft/hcsshim/internal/ncproxyttrpc" ncproxygrpcv0 "github.com/Microsoft/hcsshim/pkg/ncproxy/ncproxygrpc/v0" ncproxygrpc "github.com/Microsoft/hcsshim/pkg/ncproxy/ncproxygrpc/v1" - "github.com/Microsoft/hcsshim/pkg/octtrpc" + "github.com/Microsoft/hcsshim/pkg/otelttrpc" "github.com/containerd/ttrpc" "github.com/pkg/errors" "github.com/sirupsen/logrus" bolt "go.etcd.io/bbolt" - "go.opencensus.io/plugin/ocgrpc" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "google.golang.org/grpc" ) @@ -48,13 +48,13 @@ func newServer(ctx context.Context, conf *config, dbPath string) (*server, error agentCache := newComputeAgentCache() reconnectComputeAgents(ctx, agentStore, agentCache) - ttrpcServer, err := ttrpc.NewServer(ttrpc.WithUnaryServerInterceptor(octtrpc.ServerInterceptor())) + ttrpcServer, err := ttrpc.NewServer(ttrpc.WithUnaryServerInterceptor(otelttrpc.ServerInterceptor())) if err != nil { log.G(ctx).WithError(err).Error("failed to create ttrpc server") return nil, err } return &server{ - grpc: grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})), + grpc: grpc.NewServer(grpc.StatsHandler(otelgrpc.NewServerHandler())), ttrpc: ttrpcServer, conf: conf, agentStore: agentStore, diff --git a/cmd/runhcs/create-scratch.go b/cmd/runhcs/create-scratch.go index 1d3cba9539..67a8cfdf64 100644 --- a/cmd/runhcs/create-scratch.go +++ b/cmd/runhcs/create-scratch.go @@ -7,7 +7,7 @@ import ( "github.com/Microsoft/hcsshim/internal/appargs" "github.com/Microsoft/hcsshim/internal/lcow" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/uvm" "github.com/Microsoft/hcsshim/osversion" "github.com/pkg/errors" @@ -35,9 +35,9 @@ var createScratchCommand = cli.Command{ }, Before: appargs.Validate(), Action: func(context *cli.Context) (err error) { - ctx, span := oc.StartSpan(gcontext.Background(), "create-scratch") + ctx, span := otelutil.StartSpan(gcontext.Background(), "create-scratch") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() dest := context.String("destpath") if dest == "" { diff --git a/cmd/runhcs/prepare-disk.go b/cmd/runhcs/prepare-disk.go index ba9e0d370b..5d2c37fe1d 100644 --- a/cmd/runhcs/prepare-disk.go +++ b/cmd/runhcs/prepare-disk.go @@ -7,7 +7,7 @@ import ( "github.com/Microsoft/hcsshim/internal/appargs" "github.com/Microsoft/hcsshim/internal/lcow" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/uvm" "github.com/Microsoft/hcsshim/osversion" "github.com/pkg/errors" @@ -31,9 +31,9 @@ var prepareDiskCommand = cli.Command{ }, Before: appargs.Validate(), Action: func(context *cli.Context) (err error) { - ctx, span := oc.StartSpan(gcontext.Background(), prepareDiskStr) + ctx, span := otelutil.StartSpan(gcontext.Background(), prepareDiskStr) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() dest := context.String("destpath") if dest == "" { diff --git a/computestorage/attach.go b/computestorage/attach.go index 301a10888f..0086054484 100644 --- a/computestorage/attach.go +++ b/computestorage/attach.go @@ -6,9 +6,10 @@ import ( "context" "encoding/json" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // AttachLayerStorageFilter sets up the layer storage filter on a writable @@ -20,12 +21,10 @@ import ( // `layerData` is the parent read-only layer data. func AttachLayerStorageFilter(ctx context.Context, layerPath string, layerData LayerData) (err error) { title := "hcsshim::AttachLayerStorageFilter" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("layerPath", layerPath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("layerPath", layerPath), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() bytes, err := json.Marshal(layerData) if err != nil { @@ -48,12 +47,10 @@ func AttachLayerStorageFilter(ctx context.Context, layerPath string, layerData L // `layerData` is the parent read-only layer data. func AttachOverlayFilter(ctx context.Context, volumePath string, layerData LayerData) (err error) { title := "hcsshim::AttachOverlayFilter" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("volumePath", volumePath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("volumePath", volumePath), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() bytes, err := json.Marshal(layerData) if err != nil { diff --git a/computestorage/destroy.go b/computestorage/destroy.go index 5058d3b55e..91d8432d05 100644 --- a/computestorage/destroy.go +++ b/computestorage/destroy.go @@ -5,9 +5,10 @@ package computestorage import ( "context" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // DestroyLayer deletes a container layer. @@ -15,10 +16,10 @@ import ( // `layerPath` is a path to a directory containing the layer to export. func DestroyLayer(ctx context.Context, layerPath string) (err error) { title := "hcsshim::DestroyLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("layerPath", layerPath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("layerPath", layerPath)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = hcsDestroyLayer(layerPath) if err != nil { diff --git a/computestorage/detach.go b/computestorage/detach.go index 6e00e4a1f8..8e735cfc9a 100644 --- a/computestorage/detach.go +++ b/computestorage/detach.go @@ -7,9 +7,10 @@ import ( "encoding/json" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // DetachLayerStorageFilter detaches the layer storage filter on a writable container layer. @@ -17,10 +18,10 @@ import ( // `layerPath` is a path to a directory containing the layer to export. func DetachLayerStorageFilter(ctx context.Context, layerPath string) (err error) { title := "hcsshim::DetachLayerStorageFilter" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("layerPath", layerPath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("layerPath", layerPath)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = hcsDetachLayerStorageFilter(layerPath) if err != nil { @@ -34,10 +35,10 @@ func DetachLayerStorageFilter(ctx context.Context, layerPath string) (err error) // `volumePath` is a path to writable container volume. func DetachOverlayFilter(ctx context.Context, volumePath string, filterType hcsschema.FileSystemFilterType) (err error) { title := "hcsshim::DetachOverlayFilter" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("volumePath", volumePath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("volumePath", volumePath)) + defer func() { otelutil.SetSpanStatus(span, err) }() layerData := LayerData{} layerData.FilterType = filterType diff --git a/computestorage/export.go b/computestorage/export.go index c6370a5c9a..69d5be7e20 100644 --- a/computestorage/export.go +++ b/computestorage/export.go @@ -6,9 +6,10 @@ import ( "context" "encoding/json" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // ExportLayer exports a container layer. @@ -22,13 +23,11 @@ import ( // `options` are the export options applied to the exported layer. func ExportLayer(ctx context.Context, layerPath, exportFolderPath string, layerData LayerData, options ExportLayerOptions) (err error) { title := "hcsshim::ExportLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("layerPath", layerPath), + attribute.String("exportFolderPath", exportFolderPath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("layerPath", layerPath), - trace.StringAttribute("exportFolderPath", exportFolderPath), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() ldBytes, err := json.Marshal(layerData) if err != nil { diff --git a/computestorage/format.go b/computestorage/format.go index 2140e5c9fc..30f163a142 100644 --- a/computestorage/format.go +++ b/computestorage/format.go @@ -5,7 +5,7 @@ package computestorage import ( "context" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" "golang.org/x/sys/windows" ) @@ -20,9 +20,9 @@ import ( // that can be obtained from the virtdisk APIs. func FormatWritableLayerVhd(ctx context.Context, vhdHandle windows.Handle) (err error) { title := "hcsshim::FormatWritableLayerVhd" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() err = hcsFormatWritableLayerVhd(vhdHandle) if err != nil { diff --git a/computestorage/import.go b/computestorage/import.go index e1c87416a3..222f49385e 100644 --- a/computestorage/import.go +++ b/computestorage/import.go @@ -6,9 +6,10 @@ import ( "context" "encoding/json" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // ImportLayer imports a container layer. @@ -22,13 +23,11 @@ import ( // `layerData` is the parent layer data. func ImportLayer(ctx context.Context, layerPath, sourceFolderPath string, layerData LayerData) (err error) { title := "hcsshim::ImportLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("layerPath", layerPath), + attribute.String("sourceFolderPath", sourceFolderPath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("layerPath", layerPath), - trace.StringAttribute("sourceFolderPath", sourceFolderPath), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() bytes, err := json.Marshal(layerData) if err != nil { diff --git a/computestorage/initialize.go b/computestorage/initialize.go index d0c6216056..f81e3066a1 100644 --- a/computestorage/initialize.go +++ b/computestorage/initialize.go @@ -6,9 +6,10 @@ import ( "context" "encoding/json" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // InitializeWritableLayer initializes a writable layer for a container. @@ -19,12 +20,10 @@ import ( // `layerData` is the parent read-only layer data. func InitializeWritableLayer(ctx context.Context, layerPath string, layerData LayerData) (err error) { title := "hcsshim::InitializeWritableLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("layerPath", layerPath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("layerPath", layerPath), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() bytes, err := json.Marshal(layerData) if err != nil { diff --git a/computestorage/mount.go b/computestorage/mount.go index 4f4d8ebf2f..ff83389454 100644 --- a/computestorage/mount.go +++ b/computestorage/mount.go @@ -6,7 +6,7 @@ import ( "context" "github.com/Microsoft/hcsshim/internal/interop" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" "golang.org/x/sys/windows" ) @@ -14,9 +14,9 @@ import ( // GetLayerVhdMountPath returns the volume path for a virtual disk of a writable container layer. func GetLayerVhdMountPath(ctx context.Context, vhdHandle windows.Handle) (path string, err error) { title := "hcsshim::GetLayerVhdMountPath" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() var mountPath *uint16 err = hcsGetLayerVhdMountPath(vhdHandle, &mountPath) diff --git a/computestorage/setup.go b/computestorage/setup.go index 1c685aed0a..a95d1c4af8 100644 --- a/computestorage/setup.go +++ b/computestorage/setup.go @@ -6,10 +6,11 @@ import ( "context" "encoding/json" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/osversion" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/windows" ) @@ -24,12 +25,10 @@ import ( // `options` are the options applied while processing the layer. func SetupBaseOSLayer(ctx context.Context, layerPath string, vhdHandle windows.Handle, options OsLayerOptions) (err error) { title := "hcsshim::SetupBaseOSLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("layerPath", layerPath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("layerPath", layerPath), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() bytes, err := json.Marshal(options) if err != nil { @@ -59,13 +58,11 @@ func SetupBaseOSVolume(ctx context.Context, layerPath, volumePath string, option return errors.New("SetupBaseOSVolume is not present on builds older than 19645") } title := "hcsshim::SetupBaseOSVolume" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("layerPath", layerPath), + attribute.String("volumePath", volumePath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("layerPath", layerPath), - trace.StringAttribute("volumePath", volumePath), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() bytes, err := json.Marshal(options) if err != nil { diff --git a/go.mod b/go.mod index f68414f4ec..e0cc05d780 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,10 @@ require ( github.com/vishvananda/netlink v1.2.1-beta.2 github.com/vishvananda/netns v0.0.4 go.etcd.io/bbolt v1.3.9 - go.opencensus.io v0.24.0 + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 + go.opentelemetry.io/otel v1.21.0 + go.opentelemetry.io/otel/sdk v1.21.0 + go.opentelemetry.io/otel/trace v1.21.0 go.uber.org/mock v0.4.0 golang.org/x/sync v0.7.0 golang.org/x/sys v0.20.0 @@ -71,7 +74,6 @@ require ( github.com/goccy/go-json v0.10.2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/mux v1.8.1 // indirect @@ -102,10 +104,7 @@ require ( github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/yashtewari/glob-intersection v0.2.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect - go.opentelemetry.io/otel v1.21.0 // indirect go.opentelemetry.io/otel/metric v1.21.0 // indirect - go.opentelemetry.io/otel/sdk v1.21.0 // indirect - go.opentelemetry.io/otel/trace v1.21.0 // indirect golang.org/x/crypto v0.22.0 // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.24.0 // indirect diff --git a/go.sum b/go.sum index a459715ff4..005f15ad33 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,9 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.112.0 h1:tpFCD7hpHFlQ8yPwT3x+QeXqc2T6+n6T+hmABHfDUSM= +cloud.google.com/go/compute v1.24.0 h1:phWcR2eWzRJaL/kOiJwfFsPs4BaKq1j6vnpZrc1YlVg= +cloud.google.com/go/compute v1.24.0/go.mod h1:kw1/T+h/+tK2LJK0wiPPx1intgdAM3j/g3hFDlscY40= +cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -33,6 +38,8 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ= +github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM= github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0= github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0= github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw= @@ -95,9 +102,10 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A= +github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= @@ -125,20 +133,12 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= @@ -147,18 +147,12 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/google/flatbuffers v1.12.1 h1:MVlul7pQNoDzWRLTw5imwYsl+usrS1TXG2H4jg6ImGw= github.com/google/flatbuffers v1.12.1/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-containerregistry v0.19.1 h1:yMQ62Al6/V0Z7CqIrrS1iYoA5/oQCm88DeNujc7C1KY= github.com/google/go-containerregistry v0.19.1/go.mod h1:YCMFNQeeXeLF+dnhhWkqDItx/JSkH01j1Kis4PsjzFI= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= @@ -286,6 +280,8 @@ go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI= go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 h1:RsQi0qJ2imFfCvZabqzM9cNXBG8k6gXMv1A0cXRmH6A= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0/go.mod h1:vsh3ySueQCiKPxFLvjWC4Z135gIa34TQ/NSqkDTZYUM= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo= go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= @@ -333,7 +329,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= @@ -343,6 +338,8 @@ golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ= +golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -412,9 +409,10 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0= @@ -424,22 +422,11 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go. google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.28.1/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= diff --git a/internal/copyfile/copyfile.go b/internal/copyfile/copyfile.go index b845b372cf..1ddb77ae71 100644 --- a/internal/copyfile/copyfile.go +++ b/internal/copyfile/copyfile.go @@ -7,21 +7,21 @@ import ( "fmt" "syscall" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/winapi" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // CopyFile is a utility for copying a file using CopyFileW win32 API for // performance. func CopyFile(ctx context.Context, srcFile, destFile string, overwrite bool) (err error) { - ctx, span := oc.StartSpan(ctx, "copyfile::CopyFile") //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, "copyfile::CopyFile", trace.WithAttributes( + attribute.String("srcFile", srcFile), + attribute.String("destFile", destFile), + attribute.Bool("overwrite", overwrite))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("srcFile", srcFile), - trace.StringAttribute("destFile", destFile), - trace.BoolAttribute("overwrite", overwrite)) + defer func() { otelutil.SetSpanStatus(span, err) }() var bFailIfExists int32 = 1 if overwrite { diff --git a/internal/gcs/bridge.go b/internal/gcs/bridge.go index 0aa9d54536..b5b40c9fc4 100644 --- a/internal/gcs/bridge.go +++ b/internal/gcs/bridge.go @@ -16,11 +16,12 @@ import ( "time" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/windows" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" ) const ( @@ -260,7 +261,7 @@ func (brdg *bridge) recvLoopRoutine() { } func readMessage(r io.Reader) (int64, msgType, []byte, error) { - _, span := oc.StartSpan(context.Background(), "bridge receive read message", oc.WithClientSpanKind) + _, span := otelutil.StartSpan(context.Background(), "bridge receive read message", otelutil.WithClientSpanKind) defer span.End() var h [hdrSize]byte @@ -271,9 +272,9 @@ func readMessage(r io.Reader) (int64, msgType, []byte, error) { typ := msgType(binary.LittleEndian.Uint32(h[hdrOffType:])) n := binary.LittleEndian.Uint32(h[hdrOffSize:]) id := int64(binary.LittleEndian.Uint64(h[hdrOffID:])) - span.AddAttributes( - trace.StringAttribute("type", typ.String()), - trace.Int64Attribute("message-id", id)) + span.SetAttributes( + attribute.String("type", typ.String()), + attribute.Int64("message-id", id)) if n < hdrSize || n > maxMsgSize { return 0, 0, nil, fmt.Errorf("invalid message size %d", n) @@ -383,12 +384,11 @@ func (brdg *bridge) sendLoop() { func (brdg *bridge) writeMessage(buf *bytes.Buffer, enc *json.Encoder, typ msgType, id int64, req interface{}) error { var err error - _, span := oc.StartSpan(context.Background(), "bridge send", oc.WithClientSpanKind) + _, span := otelutil.StartSpan(context.Background(), "bridge send", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("type", typ.String()), + attribute.Int64("message-id", id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("type", typ.String()), - trace.Int64Attribute("message-id", id)) + defer func() { otelutil.SetSpanStatus(span, err) }() // Prepare the buffer with the message. var h [hdrSize]byte diff --git a/internal/gcs/container.go b/internal/gcs/container.go index a64408b834..d1dc0d801b 100644 --- a/internal/gcs/container.go +++ b/internal/gcs/container.go @@ -12,8 +12,9 @@ import ( "github.com/Microsoft/hcsshim/internal/hcs/schema1" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) const hrComputeSystemDoesNotExist = 0xc037010e @@ -37,10 +38,10 @@ var _ cow.Container = &Container{} // CreateContainer creates a container using ID `cid` and `cfg`. The request // will likely not be cancellable even if `ctx` becomes done. func (gc *GuestConnection) CreateContainer(ctx context.Context, cid string, config interface{}) (_ *Container, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::CreateContainer", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::GuestConnection::CreateContainer", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", cid))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", cid)) + defer func() { otelutil.SetSpanStatus(span, err) }() c := &Container{ gc: gc, @@ -98,9 +99,9 @@ func (c *Container) IsOCI() bool { // Close releases associated with the container. func (c *Container) Close() error { c.closeOnce.Do(func() { - _, span := oc.StartSpan(context.Background(), "gcs::Container::Close") + _, span := otelutil.StartSpan(context.Background(), "gcs::Container::Close", trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - span.AddAttributes(trace.StringAttribute("cid", c.id)) close(c.closeCh) }) @@ -109,10 +110,10 @@ func (c *Container) Close() error { // CreateProcess creates a process in the container. func (c *Container) CreateProcess(ctx context.Context, config interface{}) (_ cow.Process, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Container::CreateProcess", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Container::CreateProcess", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", c.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() return c.gc.exec(ctx, c.id, config) } @@ -124,10 +125,10 @@ func (c *Container) ID() string { // Modify sends a modify request to the container. func (c *Container) Modify(ctx context.Context, config interface{}) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Container::Modify", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Container::Modify", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", c.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() req := containerModifySettings{ requestBase: makeRequest(ctx, c.id), @@ -139,10 +140,10 @@ func (c *Container) Modify(ctx context.Context, config interface{}) (err error) // Properties returns the requested container properties targeting a V1 schema container. func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyType) (_ *schema1.ContainerProperties, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Container::Properties", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Container::Properties", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", c.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() req := containerGetProperties{ requestBase: makeRequest(ctx, c.id), @@ -158,10 +159,10 @@ func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyTyp // PropertiesV2 returns the requested container properties targeting a V2 schema container. func (c *Container) PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (_ *hcsschema.Properties, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Container::PropertiesV2", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Container::PropertiesV2", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", c.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() req := containerGetPropertiesV2{ requestBase: makeRequest(ctx, c.id), @@ -177,10 +178,10 @@ func (c *Container) PropertiesV2(ctx context.Context, types ...hcsschema.Propert // Start starts the container. func (c *Container) Start(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Container::Start", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Container::Start", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", c.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() req := makeRequest(ctx, c.id) var resp responseBase @@ -208,10 +209,10 @@ func (c *Container) shutdown(ctx context.Context, proc rpcProc) error { // might not be terminated by the time the request completes (and might never // terminate). func (c *Container) Shutdown(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Container::Shutdown", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Container::Shutdown", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", c.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() @@ -222,10 +223,10 @@ func (c *Container) Shutdown(ctx context.Context) (err error) { // might not be terminated by the time the request completes (and might never // terminate). func (c *Container) Terminate(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Container::Terminate", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Container::Terminate", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", c.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() @@ -248,9 +249,9 @@ func (c *Container) Wait() error { } func (c *Container) waitBackground() { - ctx, span := oc.StartSpan(context.Background(), "gcs::Container::waitBackground") + ctx, span := otelutil.StartSpan(context.Background(), "gcs::Container::waitBackground", trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - span.AddAttributes(trace.StringAttribute("cid", c.id)) select { case <-c.notifyCh: @@ -260,5 +261,5 @@ func (c *Container) waitBackground() { close(c.waitBlock) log.G(ctx).Debug("container exited") - oc.SetSpanStatus(span, c.waitError) + otelutil.SetSpanStatus(span, c.waitError) } diff --git a/internal/gcs/guestconnection.go b/internal/gcs/guestconnection.go index 73282e95d0..d88fb4a8bc 100644 --- a/internal/gcs/guestconnection.go +++ b/internal/gcs/guestconnection.go @@ -4,9 +4,6 @@ package gcs import ( "context" - "encoding/base64" - "encoding/hex" - "encoding/json" "fmt" "io" "net" @@ -18,12 +15,12 @@ import ( "github.com/Microsoft/hcsshim/internal/cow" "github.com/Microsoft/hcsshim/internal/hcs/schema1" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" - "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) const ( @@ -68,9 +65,9 @@ type GuestConnectionConfig struct { // Connect establishes a GCS connection. `gcc.Conn` will be closed by this function. func (gcc *GuestConnectionConfig) Connect(ctx context.Context, isColdStart bool) (_ *GuestConnection, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::GuestConnectionConfig::Connect", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::GuestConnectionConfig::Connect", otelutil.WithClientSpanKind) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() gc := &GuestConnection{ nextPort: firstIoChannelVsockPort, @@ -166,9 +163,9 @@ func (gc *GuestConnection) connect(ctx context.Context, isColdStart bool, initGu // Modify sends a modify settings request to the null container. This is // generally used to prepare virtual hardware that has been added to the guest. func (gc *GuestConnection) Modify(ctx context.Context, settings interface{}) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::Modify", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::GuestConnection::Modify", otelutil.WithClientSpanKind) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() req := containerModifySettings{ requestBase: makeRequest(ctx, nullContainerID), @@ -179,9 +176,9 @@ func (gc *GuestConnection) Modify(ctx context.Context, settings interface{}) (er } func (gc *GuestConnection) DumpStacks(ctx context.Context) (response string, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::DumpStacks", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::GuestConnection::DumpStacks", otelutil.WithClientSpanKind) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() req := dumpStacksRequest{ requestBase: makeRequest(ctx, nullContainerID), @@ -192,10 +189,10 @@ func (gc *GuestConnection) DumpStacks(ctx context.Context) (response string, err } func (gc *GuestConnection) DeleteContainerState(ctx context.Context, cid string) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::DeleteContainerState", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::GuestConnection::DeleteContainerState", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", cid))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", cid)) + defer func() { otelutil.SetSpanStatus(span, err) }() req := deleteContainerStateRequest{ requestBase: makeRequest(ctx, cid), @@ -215,9 +212,9 @@ func (gc *GuestConnection) Close() error { // CreateProcess creates a process in the container host. func (gc *GuestConnection) CreateProcess(ctx context.Context, settings interface{}) (_ cow.Process, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::GuestConnection::CreateProcess", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::GuestConnection::CreateProcess", otelutil.WithClientSpanKind) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() return gc.exec(ctx, nullContainerID, settings) } @@ -286,24 +283,8 @@ func makeRequest(ctx context.Context, cid string) requestBase { r := requestBase{ ContainerID: cid, } - span := trace.FromContext(ctx) - if span != nil { - sc := span.SpanContext() - r.OpenCensusSpanContext = &ocspancontext{ - TraceID: hex.EncodeToString(sc.TraceID[:]), - SpanID: hex.EncodeToString(sc.SpanID[:]), - TraceOptions: uint32(sc.TraceOptions), - } - if sc.Tracestate != nil { - entries := sc.Tracestate.Entries() - if len(entries) > 0 { - if bytes, err := json.Marshal(sc.Tracestate.Entries()); err == nil { - r.OpenCensusSpanContext.Tracestate = base64.StdEncoding.EncodeToString(bytes) - } else { - log.G(ctx).WithError(err).Warn("failed to encode OpenCensus Tracestate") - } - } - } + if span := trace.SpanFromContext(ctx); span != nil { + r.SpanContext = span.SpanContext() } return r } diff --git a/internal/gcs/guestconnection_test.go b/internal/gcs/guestconnection_test.go index facb0dd34b..25ae213465 100644 --- a/internal/gcs/guestconnection_test.go +++ b/internal/gcs/guestconnection_test.go @@ -5,7 +5,6 @@ package gcs import ( "context" "encoding/base64" - "encoding/hex" "encoding/json" "errors" "fmt" @@ -17,11 +16,9 @@ import ( "github.com/Microsoft/go-winio" "github.com/Microsoft/go-winio/pkg/guid" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" - "go.opencensus.io/trace/tracestate" - - "github.com/Microsoft/hcsshim/internal/oc" + "go.opentelemetry.io/otel/trace" ) const pipePortFmt = `\\.\pipe\gctest-port-%d` @@ -272,13 +269,13 @@ func Test_makeRequestNoSpan(t *testing.T) { if r.ActivityID != empty { t.Fatalf("expected ActivityID empty, got: %q", r.ActivityID.String()) } - if r.OpenCensusSpanContext != nil { - t.Fatal("expected nil span context") + if r.SpanContext.IsValid() { + t.Fatal("expected empty span context") } } func Test_makeRequestWithSpan(t *testing.T) { - ctx, span := oc.StartSpan(context.Background(), t.Name()) + ctx, span := otelutil.StartSpan(context.Background(), t.Name()) defer span.End() r := makeRequest(ctx, t.Name()) @@ -289,66 +286,56 @@ func Test_makeRequestWithSpan(t *testing.T) { if r.ActivityID != empty { t.Fatalf("expected ActivityID empty, got: %q", r.ActivityID.String()) } - if r.OpenCensusSpanContext == nil { - t.Fatal("expected non-nil span context") + if !r.SpanContext.IsValid() { + t.Fatal("expected valid span context") } sc := span.SpanContext() - encodedTraceID := hex.EncodeToString(sc.TraceID[:]) - if r.OpenCensusSpanContext.TraceID != encodedTraceID { - t.Fatalf("expected encoded TraceID: %q, got: %q", encodedTraceID, r.OpenCensusSpanContext.TraceID) + encodedTraceID := sc.TraceID().String() + if r.SpanContext.TraceID().String() != encodedTraceID { + t.Fatalf("expected encoded TraceID: %q, got: %q", encodedTraceID, r.SpanContext.TraceID()) } - encodedSpanID := hex.EncodeToString(sc.SpanID[:]) - if r.OpenCensusSpanContext.SpanID != encodedSpanID { - t.Fatalf("expected encoded SpanID: %q, got: %q", encodedSpanID, r.OpenCensusSpanContext.SpanID) + encodedSpanID := sc.SpanID().String() + if r.SpanContext.SpanID().String() != encodedSpanID { + t.Fatalf("expected encoded SpanID: %q, got: %q", encodedSpanID, r.SpanContext.SpanID()) } - encodedTraceOptions := uint32(sc.TraceOptions) - if r.OpenCensusSpanContext.TraceOptions != encodedTraceOptions { - t.Fatalf("expected encoded TraceOptions: %v, got: %v", encodedTraceOptions, r.OpenCensusSpanContext.TraceOptions) + encodedTraceOptions := uint32(sc.TraceFlags()) + if uint32(r.SpanContext.TraceFlags()) != encodedTraceOptions { + t.Fatalf("expected encoded TraceOptions: %v, got: %v", encodedTraceOptions, r.SpanContext.TraceFlags()) } - if r.OpenCensusSpanContext.Tracestate != "" { - t.Fatalf("expected encoded TraceState: '', got: %q", r.OpenCensusSpanContext.Tracestate) + if r.SpanContext.TraceState().String() != "" { + t.Fatalf("expected encoded TraceState: '', got: %q", r.SpanContext.TraceState()) } } func Test_makeRequestWithSpan_TraceStateEmptyEntries(t *testing.T) { // Start a remote context span so we can forward trace state. - ts, err := tracestate.New(nil) - if err != nil { - t.Fatalf("failed to make test Tracestate") - } - parent := trace.SpanContext{ - Tracestate: ts, - } - ctx, span := trace.StartSpanWithRemoteParent(context.Background(), t.Name(), parent) - defer span.End() + parent := trace.SpanContext{} + ctx := trace.ContextWithRemoteSpanContext(context.Background(), parent) r := makeRequest(ctx, t.Name()) - if r.OpenCensusSpanContext == nil { - t.Fatal("expected non-nil span context") + if !r.SpanContext.IsValid() { + t.Fatal("expected valid span context") } - if r.OpenCensusSpanContext.Tracestate != "" { - t.Fatalf("expected encoded TraceState: '', got: %q", r.OpenCensusSpanContext.Tracestate) + if r.SpanContext.TraceState().String() != "" { + t.Fatalf("expected encoded TraceState: '', got: %q", r.SpanContext.TraceState()) } } func Test_makeRequestWithSpan_TraceStateEntries(t *testing.T) { // Start a remote context span so we can forward trace state. - ts, err := tracestate.New(nil, tracestate.Entry{Key: "test", Value: "test"}) + ts, err := (trace.TraceState{}).Insert("test", "test") if err != nil { t.Fatalf("failed to make test Tracestate") } - parent := trace.SpanContext{ - Tracestate: ts, - } - ctx, span := trace.StartSpanWithRemoteParent(context.Background(), t.Name(), parent) - defer span.End() + parent := (trace.SpanContext{}).WithTraceState(ts) + ctx := trace.ContextWithRemoteSpanContext(context.Background(), parent) r := makeRequest(ctx, t.Name()) - if r.OpenCensusSpanContext == nil { - t.Fatal("expected non-nil span context") + if !r.SpanContext.IsValid() { + t.Fatal("expected valid span context") } encodedTraceState := base64.StdEncoding.EncodeToString([]byte(`[{"Key":"test","Value":"test"}]`)) - if r.OpenCensusSpanContext.Tracestate != encodedTraceState { - t.Fatalf("expected encoded TraceState: %q, got: %q", encodedTraceState, r.OpenCensusSpanContext.Tracestate) + if r.SpanContext.TraceState().String() != encodedTraceState { + t.Fatalf("expected encoded TraceState: %q, got: %q", encodedTraceState, r.SpanContext.TraceState()) } } diff --git a/internal/gcs/process.go b/internal/gcs/process.go index 87c5c29ae4..65ed1bd41b 100644 --- a/internal/gcs/process.go +++ b/internal/gcs/process.go @@ -14,9 +14,10 @@ import ( "github.com/Microsoft/hcsshim/internal/cow" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) const ( @@ -124,11 +125,10 @@ func (gc *GuestConnection) exec(ctx context.Context, cid string, params interfac // Close releases resources associated with the process and closes the // associated standard IO streams. func (p *Process) Close() error { - ctx, span := oc.StartSpan(context.Background(), "gcs::Process::Close") + ctx, span := otelutil.StartSpan(context.Background(), "gcs::Process::Close", trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.id)))) defer span.End() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.id))) if err := p.stdin.Close(); err != nil { log.G(ctx).WithError(err).Warn("close stdin failed") @@ -144,12 +144,11 @@ func (p *Process) Close() error { // CloseStdin causes the process to read EOF on its stdin stream. func (p *Process) CloseStdin(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStdin") //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, "gcs::Process::CloseStdin", trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.id)))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.id))) + defer func() { otelutil.SetSpanStatus(span, err) }() p.stdinCloseWriteOnce.Do(func() { p.stdinCloseWriteErr = p.stdin.CloseWrite() @@ -158,23 +157,21 @@ func (p *Process) CloseStdin(ctx context.Context) (err error) { } func (p *Process) CloseStdout(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStdout") //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, "gcs::Process::CloseStdout", trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.id)))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.id))) + defer func() { otelutil.SetSpanStatus(span, err) }() return p.stdout.Close() } func (p *Process) CloseStderr(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Process::CloseStderr") //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, "gcs::Process::CloseStderr", trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.id)))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.id))) + defer func() { otelutil.SetSpanStatus(span, err) }() return p.stderr.Close() } @@ -195,12 +192,11 @@ func (p *Process) ExitCode() (_ int, err error) { // signal was delivered. The process might not be terminated by the time this // returns. func (p *Process) Kill(ctx context.Context) (_ bool, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Process::Kill") + ctx, span := otelutil.StartSpan(ctx, "gcs::Process::Kill", trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.id)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.id))) + defer func() { otelutil.SetSpanStatus(span, err) }() return p.Signal(ctx, nil) } @@ -213,12 +209,11 @@ func (p *Process) Pid() int { // ResizeConsole requests that the pty associated with the process resize its // window. func (p *Process) ResizeConsole(ctx context.Context, width, height uint16) (err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Process::ResizeConsole", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Process::ResizeConsole", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.id)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.id))) + defer func() { otelutil.SetSpanStatus(span, err) }() req := containerResizeConsole{ requestBase: makeRequest(ctx, p.cid), @@ -232,12 +227,11 @@ func (p *Process) ResizeConsole(ctx context.Context, width, height uint16) (err // Signal sends a signal to the process, returning whether it was delivered. func (p *Process) Signal(ctx context.Context, options interface{}) (_ bool, err error) { - ctx, span := oc.StartSpan(ctx, "gcs::Process::Signal", oc.WithClientSpanKind) + ctx, span := otelutil.StartSpan(ctx, "gcs::Process::Signal", otelutil.WithClientSpanKind, trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.id)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.id))) + defer func() { otelutil.SetSpanStatus(span, err) }() req := containerSignalProcess{ requestBase: makeRequest(ctx, p.cid), @@ -277,11 +271,10 @@ func (p *Process) Wait() error { } func (p *Process) waitBackground() { - ctx, span := oc.StartSpan(context.Background(), "gcs::Process::waitBackground") + ctx, span := otelutil.StartSpan(context.Background(), "gcs::Process::waitBackground", trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.id)))) defer span.End() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.id))) p.waitCall.Wait() ec, err := p.ExitCode() @@ -289,5 +282,5 @@ func (p *Process) waitBackground() { log.G(ctx).WithError(err).Error("failed wait") } log.G(ctx).WithField("exitCode", ec).Debug("process exited") - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) } diff --git a/internal/gcs/protocol.go b/internal/gcs/protocol.go index 94e55e4c1e..fc8230c3fe 100644 --- a/internal/gcs/protocol.go +++ b/internal/gcs/protocol.go @@ -10,6 +10,7 @@ import ( "github.com/Microsoft/go-winio/pkg/guid" "github.com/Microsoft/hcsshim/internal/hcs/schema1" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" + "go.opentelemetry.io/otel/trace" ) // LinuxGcsVsockPort is the vsock port number that the Linux GCS will @@ -162,13 +163,13 @@ type requestBase struct { ContainerID string `json:"ContainerId"` ActivityID guid.GUID `json:"ActivityId"` - // OpenCensusSpanContext is the encoded OpenCensus `trace.SpanContext` if + // SpanContext is the encoded OTel `trace.SpanContext` if // set when making the request. // // NOTE: This is not a part of the protocol but because its a JSON protocol // adding fields is a non-breaking change. If the guest supports it this is // just additive context. - OpenCensusSpanContext *ocspancontext `json:"ocsc,omitempty"` + SpanContext trace.SpanContext `json:"otelsc,omitempty"` } func (req *requestBase) Base() *requestBase { diff --git a/internal/guest/bridge/bridge.go b/internal/guest/bridge/bridge.go index d56eb51760..fae292a7af 100644 --- a/internal/guest/bridge/bridge.go +++ b/internal/guest/bridge/bridge.go @@ -5,9 +5,7 @@ package bridge import ( "context" - "encoding/base64" "encoding/binary" - "encoding/hex" "encoding/json" "fmt" "io" @@ -20,14 +18,14 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" - "go.opencensus.io/trace/tracestate" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/Microsoft/hcsshim/internal/guest/gcserr" "github.com/Microsoft/hcsshim/internal/guest/prot" "github.com/Microsoft/hcsshim/internal/guest/runtime/hcsv2" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" ) // UnknownMessage represents the default handler logic for an unmatched request @@ -268,46 +266,16 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser // request. _ = json.Unmarshal(message, &base) - var ctx context.Context - var span *trace.Span - if base.OpenCensusSpanContext != nil { - sc := trace.SpanContext{} - if bytes, err := hex.DecodeString(base.OpenCensusSpanContext.TraceID); err == nil { - copy(sc.TraceID[:], bytes) - } - if bytes, err := hex.DecodeString(base.OpenCensusSpanContext.SpanID); err == nil { - copy(sc.SpanID[:], bytes) - } - sc.TraceOptions = trace.TraceOptions(base.OpenCensusSpanContext.TraceOptions) - if base.OpenCensusSpanContext.Tracestate != "" { - if bytes, err := base64.StdEncoding.DecodeString(base.OpenCensusSpanContext.Tracestate); err == nil { - var entries []tracestate.Entry - if err := json.Unmarshal(bytes, &entries); err == nil { - if ts, err := tracestate.New(nil, entries...); err == nil { - sc.Tracestate = ts - } - } - } - } - ctx, span = oc.StartSpanWithRemoteParent( - context.Background(), - "opengcs::bridge::request", - sc, - oc.WithServerSpanKind, - ) - } else { - ctx, span = oc.StartSpan( - context.Background(), - "opengcs::bridge::request", - oc.WithServerSpanKind, - ) + ctx := context.Background() + if base.SpanContext.IsValid() { + ctx = trace.ContextWithRemoteSpanContext(ctx, base.SpanContext) } - span.AddAttributes( - trace.Int64Attribute("message-id", int64(header.ID)), - trace.StringAttribute("message-type", header.Type.String()), - trace.StringAttribute("activityID", base.ActivityID), - trace.StringAttribute("cid", base.ContainerID)) + ctx, _ = otelutil.StartSpan(ctx, "opengcs::bridge::request", otelutil.WithServerSpanKind, trace.WithAttributes( + attribute.Int64("message-id", int64(header.ID)), + attribute.String("message-type", header.Type.String()), + attribute.String("activityID", base.ActivityID), + attribute.String("cid", base.ContainerID))) entry := log.G(ctx) if entry.Logger.GetLevel() > logrus.DebugLevel { @@ -351,9 +319,9 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser } resp.Base().ActivityID = r.ActivityID if err != nil { - span := trace.FromContext(r.Context) + span := trace.SpanFromContext(r.Context) if span != nil { - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) } setErrorForResponseBase(resp.Base(), err) } @@ -382,10 +350,10 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser break } - s := trace.FromContext(resp.ctx) + s := trace.SpanFromContext(resp.ctx) if s != nil { log.G(resp.ctx).WithField("message", string(responseBytes)).Trace("request write response") - s.AddAttributes(trace.StringAttribute("response-message-type", resp.header.Type.String())) + s.SetAttributes(attribute.String("response-message-type", resp.header.Type.String())) s.End() } } @@ -421,10 +389,10 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser // PublishNotification writes a specific notification to the bridge. func (b *Bridge) PublishNotification(n *prot.ContainerNotification) { - ctx, span := oc.StartSpan(context.Background(), + ctx, span := otelutil.StartSpan(context.Background(), "opengcs::bridge::PublishNotification", - oc.WithClientSpanKind) - span.AddAttributes(trace.StringAttribute("notification", fmt.Sprintf("%+v", n))) + otelutil.WithClientSpanKind, + trace.WithAttributes(attribute.String("notification", fmt.Sprintf("%+v", n)))) // DONT defer span.End() here. Publish is odd because bridgeResponse calls // `End` on the `ctx` after the response is sent. diff --git a/internal/guest/bridge/bridge_v2.go b/internal/guest/bridge/bridge_v2.go index f9712abc9d..f82e8534f5 100644 --- a/internal/guest/bridge/bridge_v2.go +++ b/internal/guest/bridge/bridge_v2.go @@ -10,7 +10,8 @@ import ( "time" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/unix" "github.com/Microsoft/hcsshim/internal/guest/commonutils" @@ -19,7 +20,7 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/runtime/hcsv2" "github.com/Microsoft/hcsshim/internal/guest/stdio" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" ) @@ -46,10 +47,10 @@ var capabilities = prot.GcsCapabilities{ // negotiateProtocolV2 was introduced in v4 so will not be called with a minimum // lower than that. func (b *Bridge) negotiateProtocolV2(r *Request) (_ RequestResponse, err error) { - _, span := oc.StartSpan(r.Context, "opengcs::bridge::negotiateProtocolV2") + _, span := otelutil.StartSpan(r.Context, "opengcs::bridge::negotiateProtocolV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() var request prot.NegotiateProtocol if err := commonutils.UnmarshalJSONWithHresult(r.Message, &request); err != nil { @@ -82,10 +83,10 @@ func (b *Bridge) negotiateProtocolV2(r *Request) (_ RequestResponse, err error) // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) createContainerV2(r *Request) (_ RequestResponse, err error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::createContainerV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::createContainerV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() var request prot.ContainerCreate if err := commonutils.UnmarshalJSONWithHresult(r.Message, &request); err != nil { @@ -135,10 +136,10 @@ func (b *Bridge) createContainerV2(r *Request) (_ RequestResponse, err error) { // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) startContainerV2(r *Request) (_ RequestResponse, err error) { - _, span := oc.StartSpan(r.Context, "opengcs::bridge::startContainerV2") + _, span := otelutil.StartSpan(r.Context, "opengcs::bridge::startContainerV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() // This is just a noop, but needs to be handled so that an error isn't // returned to the HCS. @@ -166,10 +167,10 @@ func (b *Bridge) startContainerV2(r *Request) (_ RequestResponse, err error) { // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) execProcessV2(r *Request) (_ RequestResponse, err error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::execProcessV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::execProcessV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() var request prot.ContainerExecuteProcess if err := commonutils.UnmarshalJSONWithHresult(r.Message, &request); err != nil { @@ -211,9 +212,9 @@ func (b *Bridge) execProcessV2(r *Request) (_ RequestResponse, err error) { // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) killContainerV2(r *Request) (RequestResponse, error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::killContainerV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::killContainerV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) return b.signalContainerShutdownV2(ctx, span, r, false) } @@ -224,9 +225,9 @@ func (b *Bridge) killContainerV2(r *Request) (RequestResponse, error) { // // This is allowed only for protocol version 4+, schema version 2.1+ func (b *Bridge) shutdownContainerV2(r *Request) (RequestResponse, error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::shutdownContainerV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::shutdownContainerV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) return b.signalContainerShutdownV2(ctx, span, r, true) } @@ -234,11 +235,11 @@ func (b *Bridge) shutdownContainerV2(r *Request) (RequestResponse, error) { // signalContainerV2 is not a handler func. It is called from either // `killContainerV2` or `shutdownContainerV2` to deliver a SIGTERM or SIGKILL // respectively -func (b *Bridge) signalContainerShutdownV2(ctx context.Context, span *trace.Span, r *Request, graceful bool) (_ RequestResponse, err error) { - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", r.ContainerID), - trace.BoolAttribute("graceful", graceful), +func (b *Bridge) signalContainerShutdownV2(ctx context.Context, span trace.Span, r *Request, graceful bool) (_ RequestResponse, err error) { + defer func() { otelutil.SetSpanStatus(span, err) }() + span.SetAttributes( + attribute.String("cid", r.ContainerID), + attribute.Bool("graceful", graceful), ) var request prot.MessageBase @@ -263,19 +264,19 @@ func (b *Bridge) signalContainerShutdownV2(ctx context.Context, span *trace.Span } func (b *Bridge) signalProcessV2(r *Request) (_ RequestResponse, err error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::signalProcessV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::signalProcessV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() var request prot.ContainerSignalProcess if err := commonutils.UnmarshalJSONWithHresult(r.Message, &request); err != nil { return nil, errors.Wrapf(err, "failed to unmarshal JSON in message \"%s\"", r.Message) } - span.AddAttributes( - trace.Int64Attribute("pid", int64(request.ProcessID)), - trace.Int64Attribute("signal", int64(request.Options.Signal))) + span.SetAttributes( + attribute.Int64("pid", int64(request.ProcessID)), + attribute.Int64("signal", int64(request.Options.Signal))) var signal syscall.Signal if request.Options.Signal == 0 { @@ -292,10 +293,10 @@ func (b *Bridge) signalProcessV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) getPropertiesV2(r *Request) (_ RequestResponse, err error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::getPropertiesV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::getPropertiesV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() var request prot.ContainerGetProperties if err := commonutils.UnmarshalJSONWithHresult(r.Message, &request); err != nil { @@ -334,19 +335,19 @@ func (b *Bridge) getPropertiesV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) waitOnProcessV2(r *Request) (_ RequestResponse, err error) { - _, span := oc.StartSpan(r.Context, "opengcs::bridge::waitOnProcessV2") + _, span := otelutil.StartSpan(r.Context, "opengcs::bridge::waitOnProcessV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() var request prot.ContainerWaitForProcess if err := commonutils.UnmarshalJSONWithHresult(r.Message, &request); err != nil { return nil, errors.Wrapf(err, "failed to unmarshal JSON in message \"%s\"", r.Message) } - span.AddAttributes( - trace.Int64Attribute("pid", int64(request.ProcessID)), - trace.Int64Attribute("timeout-ms", int64(request.TimeoutInMs))) + span.SetAttributes( + attribute.Int64("pid", int64(request.ProcessID)), + attribute.Int64("timeout-ms", int64(request.TimeoutInMs))) var exitCodeChan <-chan int var doneChan chan<- bool @@ -389,20 +390,20 @@ func (b *Bridge) waitOnProcessV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) resizeConsoleV2(r *Request) (_ RequestResponse, err error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::resizeConsoleV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::resizeConsoleV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() var request prot.ContainerResizeConsole if err := commonutils.UnmarshalJSONWithHresult(r.Message, &request); err != nil { return nil, errors.Wrapf(err, "failed to unmarshal JSON in message \"%s\"", r.Message) } - span.AddAttributes( - trace.Int64Attribute("pid", int64(request.ProcessID)), - trace.Int64Attribute("height", int64(request.Height)), - trace.Int64Attribute("width", int64(request.Width))) + span.SetAttributes( + attribute.Int64("pid", int64(request.ProcessID)), + attribute.Int64("height", int64(request.Height)), + attribute.Int64("width", int64(request.Width))) c, err := b.hostState.GetCreatedContainer(request.ContainerID) if err != nil { @@ -423,10 +424,10 @@ func (b *Bridge) resizeConsoleV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) modifySettingsV2(r *Request) (_ RequestResponse, err error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::modifySettingsV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::modifySettingsV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() request, err := prot.UnmarshalContainerModifySettings(r.Message) if err != nil { @@ -442,9 +443,9 @@ func (b *Bridge) modifySettingsV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) dumpStacksV2(r *Request) (_ RequestResponse, err error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::dumpStacksV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::dumpStacksV2") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() stacks, err := b.hostState.GetStacks(ctx) if err != nil { @@ -456,11 +457,10 @@ func (b *Bridge) dumpStacksV2(r *Request) (_ RequestResponse, err error) { } func (b *Bridge) deleteContainerStateV2(r *Request) (_ RequestResponse, err error) { - ctx, span := oc.StartSpan(r.Context, "opengcs::bridge::deleteContainerStateV2") + ctx, span := otelutil.StartSpan(r.Context, "opengcs::bridge::deleteContainerStateV2", trace.WithAttributes( + attribute.String("cid", r.ContainerID))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes(trace.StringAttribute("cid", r.ContainerID)) + defer func() { otelutil.SetSpanStatus(span, err) }() var request prot.MessageBase if err := commonutils.UnmarshalJSONWithHresult(r.Message, &request); err != nil { diff --git a/internal/guest/network/network.go b/internal/guest/network/network.go index 68f7c1bef1..abe35c2827 100644 --- a/internal/guest/network/network.go +++ b/internal/guest/network/network.go @@ -16,9 +16,10 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/storage/pci" "github.com/Microsoft/hcsshim/internal/guest/storage/vmbus" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // mock out calls for testing @@ -34,9 +35,9 @@ const maxDNSSearches = 6 // GenerateEtcHostsContent generates a /etc/hosts file based on `hostname`. func GenerateEtcHostsContent(ctx context.Context, hostname string) string { - _, span := oc.StartSpan(ctx, "network::GenerateEtcHostsContent") + _, span := otelutil.StartSpan(ctx, "network::GenerateEtcHostsContent", trace.WithAttributes( + attribute.String("hostname", hostname))) defer span.End() - span.AddAttributes(trace.StringAttribute("hostname", hostname)) nameParts := strings.Split(hostname, ".") buf := bytes.Buffer{} @@ -59,14 +60,12 @@ func GenerateEtcHostsContent(ctx context.Context, hostname string) string { // GenerateResolvConfContent generates the resolv.conf file content based on // `searches`, `servers`, and `options`. func GenerateResolvConfContent(ctx context.Context, searches, servers, options []string) (_ string, err error) { - _, span := oc.StartSpan(ctx, "network::GenerateResolvConfContent") + _, span := otelutil.StartSpan(ctx, "network::GenerateResolvConfContent", trace.WithAttributes( + attribute.String("searches", strings.Join(searches, ", ")), + attribute.String("servers", strings.Join(servers, ", ")), + attribute.String("options", strings.Join(options, ", ")))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("searches", strings.Join(searches, ", ")), - trace.StringAttribute("servers", strings.Join(servers, ", ")), - trace.StringAttribute("options", strings.Join(options, ", "))) + defer func() { otelutil.SetSpanStatus(span, err) }() if len(searches) > maxDNSSearches { return "", errors.Errorf("searches has more than %d domains", maxDNSSearches) @@ -115,12 +114,12 @@ func MergeValues(first, second []string) []string { // // Will retry the operation until `ctx` is exceeded or canceled. func InstanceIDToName(ctx context.Context, id string, vpciAssigned bool) (_ string, err error) { - ctx, span := oc.StartSpan(ctx, "network::InstanceIDToName") - defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - vmBusID := strings.ToLower(id) - span.AddAttributes(trace.StringAttribute("adapterInstanceID", vmBusID)) + + ctx, span := otelutil.StartSpan(ctx, "network::InstanceIDToName", trace.WithAttributes( + attribute.String("adapterInstanceID", vmBusID))) + defer span.End() + defer func() { otelutil.SetSpanStatus(span, err) }() var netDevicePath string if vpciAssigned { diff --git a/internal/guest/prot/protocol.go b/internal/guest/prot/protocol.go index 891891d510..b05796f40b 100644 --- a/internal/guest/prot/protocol.go +++ b/internal/guest/prot/protocol.go @@ -10,6 +10,7 @@ import ( v1 "github.com/containerd/cgroups/v3/cgroup1/stats" oci "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" + "go.opentelemetry.io/otel/trace" "github.com/Microsoft/hcsshim/internal/guest/commonutils" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" @@ -276,41 +277,19 @@ type GcsGuestCapabilities struct { DeleteContainerStateSupported bool `json:",omitempty"` } -// ocspancontext is the internal JSON representation of the OpenCensus -// `trace.SpanContext` for fowarding to a GCS that supports it. -type ocspancontext struct { - // TraceID is the `hex` encoded string of the OpenCensus - // `SpanContext.TraceID` to propagate to the guest. - TraceID string `json:",omitempty"` - // SpanID is the `hex` encoded string of the OpenCensus `SpanContext.SpanID` - // to propagate to the guest. - SpanID string `json:",omitempty"` - - // TraceOptions is the OpenCensus `SpanContext.TraceOptions` passed through - // to propagate to the guest. - TraceOptions uint32 `json:",omitempty"` - - // Tracestate is the `base64` encoded string of marshaling the OpenCensus - // `SpanContext.TraceState.Entries()` to JSON. - // - // If `SpanContext.Tracestate == nil || - // len(SpanContext.Tracestate.Entries()) == 0` this will be `""`. - Tracestate string `json:",omitempty"` -} - // MessageBase is the base type embedded in all messages sent from the HCS to // the GCS, as well as ContainerNotification which is sent from GCS to HCS. type MessageBase struct { ContainerID string `json:"ContainerId"` ActivityID string `json:"ActivityId"` - // OpenCensusSpanContext is the encoded OpenCensus `trace.SpanContext` if + // SpanContext is the encoded OTel `trace.SpanContext` if // set when making the request. // // NOTE: This is not a part of the protocol but because its a JSON protocol // adding fields is a non-breaking change. If the guest supports it this is // just additive context. - OpenCensusSpanContext *ocspancontext `json:"ocsc,omitempty"` + SpanContext trace.SpanContext `json:"otelsc,omitempty"` } // NegotiateProtocol is the message from the HCS used to determine the protocol diff --git a/internal/guest/runtime/hcsv2/container.go b/internal/guest/runtime/hcsv2/container.go index bc1ff9924c..52f298d0f4 100644 --- a/internal/guest/runtime/hcsv2/container.go +++ b/internal/guest/runtime/hcsv2/container.go @@ -16,7 +16,8 @@ import ( oci "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/Microsoft/hcsshim/internal/guest/gcserr" "github.com/Microsoft/hcsshim/internal/guest/prot" @@ -27,7 +28,7 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/transport" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" ) @@ -230,9 +231,9 @@ func (c *Container) Update(ctx context.Context, resources interface{}) error { // Wait waits for the container's init process to exit. func (c *Container) Wait() prot.NotificationType { - _, span := oc.StartSpan(context.Background(), "opengcs::Container::Wait") + _, span := otelutil.StartSpan(context.Background(), "opengcs::Container::Wait", trace.WithAttributes( + attribute.String(logfields.ContainerID, c.id))) defer span.End() - span.AddAttributes(trace.StringAttribute(logfields.ContainerID, c.id)) c.initProcess.writersWg.Wait() c.etL.Lock() @@ -255,9 +256,9 @@ func (c *Container) setExitType(signal syscall.Signal) { // GetStats returns the cgroup metrics for the container. func (c *Container) GetStats(ctx context.Context) (*v1.Metrics, error) { - _, span := oc.StartSpan(ctx, "opengcs::Container::GetStats") + _, span := otelutil.StartSpan(ctx, "opengcs::Container::GetStats", trace.WithAttributes( + attribute.String("cid", c.id))) defer span.End() - span.AddAttributes(trace.StringAttribute("cid", c.id)) cgroupPath := c.spec.Linux.CgroupsPath cg, err := cgroups.Load(cgroups.StaticPath(cgroupPath)) diff --git a/internal/guest/runtime/hcsv2/network.go b/internal/guest/runtime/hcsv2/network.go index e8b0ebec17..04c6e8492f 100644 --- a/internal/guest/runtime/hcsv2/network.go +++ b/internal/guest/runtime/hcsv2/network.go @@ -12,12 +12,13 @@ import ( "github.com/pkg/errors" "github.com/vishvananda/netns" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/Microsoft/hcsshim/internal/guest/gcserr" "github.com/Microsoft/hcsshim/internal/guest/network" "github.com/Microsoft/hcsshim/internal/guest/prot" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" ) @@ -71,12 +72,12 @@ func GetOrAddNetworkNamespace(id string) *namespace { // RemoveNetworkNamespace removes the in-memory `namespace` found by `id`. func RemoveNetworkNamespace(ctx context.Context, id string) (err error) { - _, span := oc.StartSpan(ctx, "hcsv2::RemoveNetworkNamespace") - defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - id = strings.ToLower(id) - span.AddAttributes(trace.StringAttribute("id", id)) + + _, span := otelutil.StartSpan(ctx, "hcsv2::RemoveNetworkNamespace", trace.WithAttributes( + attribute.String("id", id))) + defer span.End() + defer func() { otelutil.SetSpanStatus(span, err) }() namespaceSync.Lock() defer namespaceSync.Unlock() @@ -112,12 +113,11 @@ func (n *namespace) ID() string { // assigned adapters into this namespace. The caller MUST call `Sync()` to // complete this operation. func (n *namespace) AssignContainerPid(ctx context.Context, pid int) (err error) { - _, span := oc.StartSpan(ctx, "namespace::AssignContainerPid") + _, span := otelutil.StartSpan(ctx, "namespace::AssignContainerPid", trace.WithAttributes( + attribute.String("namespace", n.id), + attribute.Int64("pid", int64(pid)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("namespace", n.id), - trace.Int64Attribute("pid", int64(pid))) + defer func() { otelutil.SetSpanStatus(span, err) }() n.m.Lock() defer n.m.Unlock() @@ -147,12 +147,11 @@ func (n *namespace) Adapters() []*guestresource.LCOWNetworkAdapter { // namespace assigned to `n`. A user must call `Sync()` to complete this // operation. func (n *namespace) AddAdapter(ctx context.Context, adp *guestresource.LCOWNetworkAdapter) (err error) { - ctx, span := oc.StartSpan(ctx, "namespace::AddAdapter") + ctx, span := otelutil.StartSpan(ctx, "namespace::AddAdapter", trace.WithAttributes( + attribute.String("namespace", n.id), + attribute.String("adapter", fmt.Sprintf("%+v", adp)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("namespace", n.id), - trace.StringAttribute("adapter", fmt.Sprintf("%+v", adp))) + defer func() { otelutil.SetSpanStatus(span, err) }() n.m.Lock() defer n.m.Unlock() @@ -179,12 +178,11 @@ func (n *namespace) AddAdapter(ctx context.Context, adp *guestresource.LCOWNetwo // RemoveAdapter removes the adapter matching `id` from `n`. If `id` is not // found returns no error. func (n *namespace) RemoveAdapter(ctx context.Context, id string) (err error) { - _, span := oc.StartSpan(ctx, "namespace::RemoveAdapter") + _, span := otelutil.StartSpan(ctx, "namespace::RemoveAdapter", trace.WithAttributes( + attribute.String("namespace", n.id), + attribute.String("adapterID", id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("namespace", n.id), - trace.StringAttribute("adapterID", id)) + defer func() { otelutil.SetSpanStatus(span, err) }() n.m.Lock() defer n.m.Unlock() @@ -206,10 +204,10 @@ func (n *namespace) RemoveAdapter(ctx context.Context, id string) (err error) { // Sync moves all adapters to the network namespace of `n` if assigned. func (n *namespace) Sync(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "namespace::Sync") + ctx, span := otelutil.StartSpan(ctx, "namespace::Sync", trace.WithAttributes( + attribute.String("namespace", n.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("namespace", n.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() n.m.Lock() defer n.m.Unlock() @@ -244,13 +242,12 @@ type nicInNamespace struct { // assignToPid assigns `nin.adapter`, represented by `nin.ifname` to `pid`. func (nin *nicInNamespace) assignToPid(ctx context.Context, pid int) (err error) { - ctx, span := oc.StartSpan(ctx, "nicInNamespace::assignToPid") + ctx, span := otelutil.StartSpan(ctx, "nicInNamespace::assignToPid", trace.WithAttributes( + attribute.String("adapterID", nin.adapter.ID), + attribute.String("ifname", nin.ifname), + attribute.Int64("pid", int64(pid)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("adapterID", nin.adapter.ID), - trace.StringAttribute("ifname", nin.ifname), - trace.Int64Attribute("pid", int64(pid))) + defer func() { otelutil.SetSpanStatus(span, err) }() v1Adapter := &prot.NetworkAdapter{ NatEnabled: (nin.adapter.IPAddress != "") || (nin.adapter.IPv6Address != ""), diff --git a/internal/guest/runtime/hcsv2/process.go b/internal/guest/runtime/hcsv2/process.go index e29e6e62f7..de84cbc1bf 100644 --- a/internal/guest/runtime/hcsv2/process.go +++ b/internal/guest/runtime/hcsv2/process.go @@ -15,11 +15,12 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/stdio" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" oci "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) type Process interface { @@ -87,11 +88,10 @@ func newProcess(c *Container, spec *oci.Process, process runtime.Process, pid ui p.exitWg.Add(1) p.writersWg.Add(1) go func() { - ctx, span := oc.StartSpan(context.Background(), "newProcess::waitBackground") + ctx, span := otelutil.StartSpan(context.Background(), "newProcess::waitBackground", trace.WithAttributes( + attribute.String(logfields.ContainerID, p.cid), + attribute.Int64(logfields.ProcessID, int64(p.pid)))) defer span.End() - span.AddAttributes( - trace.StringAttribute(logfields.ContainerID, p.cid), - trace.Int64Attribute(logfields.ProcessID, int64(p.pid))) // Wait for the process to exit exitCode, err := p.process.Wait() @@ -117,11 +117,10 @@ func newProcess(c *Container, spec *oci.Process, process runtime.Process, pid ui } c.processesMutex.Lock() - _, span := oc.StartSpan(context.Background(), "newProcess::waitBackground::waitAllWaiters") + _, span := otelutil.StartSpan(context.Background(), "newProcess::waitBackground::waitAllWaiters", trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.pid)))) defer span.End() - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.pid))) delete(c.processes, p.pid) c.processesMutex.Unlock() @@ -165,10 +164,9 @@ func (p *containerProcess) ResizeConsole(_ context.Context, height, width uint16 // gather the exit code. The second channel must be signaled from the caller // when the caller has completed its use of this call to Wait. func (p *containerProcess) Wait() (<-chan int, chan<- bool) { - ctx, span := oc.StartSpan(context.Background(), "opengcs::containerProcess::Wait") - span.AddAttributes( - trace.StringAttribute("cid", p.cid), - trace.Int64Attribute("pid", int64(p.pid))) + ctx, span := otelutil.StartSpan(context.Background(), "opengcs::containerProcess::Wait", trace.WithAttributes( + attribute.String("cid", p.cid), + attribute.Int64("pid", int64(p.pid)))) exitCodeChan := make(chan int, 1) doneChan := make(chan bool) @@ -288,8 +286,8 @@ func (ep *externalProcess) ResizeConsole(_ context.Context, height, width uint16 } func (ep *externalProcess) Wait() (<-chan int, chan<- bool) { - _, span := oc.StartSpan(context.Background(), "opengcs::externalProcess::Wait") - span.AddAttributes(trace.Int64Attribute("pid", int64(ep.cmd.Process.Pid))) + otelutil.StartSpan(context.Background(), "opengcs::externalProcess::Wait", trace.WithAttributes( + attribute.Int64("pid", int64(ep.cmd.Process.Pid)))) exitCodeChan := make(chan int, 1) doneChan := make(chan bool) diff --git a/internal/guest/runtime/hcsv2/sandbox_container.go b/internal/guest/runtime/hcsv2/sandbox_container.go index 864d7221c5..71635998c0 100644 --- a/internal/guest/runtime/hcsv2/sandbox_container.go +++ b/internal/guest/runtime/hcsv2/sandbox_container.go @@ -11,11 +11,12 @@ import ( oci "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/Microsoft/hcsshim/internal/guest/network" specInternal "github.com/Microsoft/hcsshim/internal/guest/spec" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/pkg/annotations" ) @@ -32,10 +33,10 @@ func getSandboxResolvPath(id string) string { } func setupSandboxContainerSpec(ctx context.Context, id string, spec *oci.Spec) (err error) { - ctx, span := oc.StartSpan(ctx, "hcsv2::setupSandboxContainerSpec") + ctx, span := otelutil.StartSpan(ctx, "hcsv2::setupSandboxContainerSpec", trace.WithAttributes( + attribute.String("cid", id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", id)) + defer func() { otelutil.SetSpanStatus(span, err) }() // Generate the sandbox root dir rootDir := specInternal.SandboxRootDir(id) diff --git a/internal/guest/runtime/hcsv2/standalone_container.go b/internal/guest/runtime/hcsv2/standalone_container.go index f4f07b262e..256aaf9c39 100644 --- a/internal/guest/runtime/hcsv2/standalone_container.go +++ b/internal/guest/runtime/hcsv2/standalone_container.go @@ -11,12 +11,13 @@ import ( oci "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/Microsoft/hcsshim/internal/guest/network" specInternal "github.com/Microsoft/hcsshim/internal/guest/spec" "github.com/Microsoft/hcsshim/internal/guestpath" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" ) func getStandaloneRootDir(id string) string { @@ -36,10 +37,10 @@ func getStandaloneResolvPath(id string) string { } func setupStandaloneContainerSpec(ctx context.Context, id string, spec *oci.Spec) (err error) { - ctx, span := oc.StartSpan(ctx, "hcsv2::setupStandaloneContainerSpec") + ctx, span := otelutil.StartSpan(ctx, "hcsv2::setupStandaloneContainerSpec", trace.WithAttributes( + attribute.String("cid", id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", id)) + defer func() { otelutil.SetSpanStatus(span, err) }() // Generate the standalone root dir rootDir := getStandaloneRootDir(id) diff --git a/internal/guest/runtime/hcsv2/workload_container.go b/internal/guest/runtime/hcsv2/workload_container.go index 28349de5df..1c3db58d2a 100644 --- a/internal/guest/runtime/hcsv2/workload_container.go +++ b/internal/guest/runtime/hcsv2/workload_container.go @@ -11,12 +11,13 @@ import ( oci "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/unix" specInternal "github.com/Microsoft/hcsshim/internal/guest/spec" "github.com/Microsoft/hcsshim/internal/guestpath" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/pkg/annotations" ) @@ -94,12 +95,11 @@ func specHasGPUDevice(spec *oci.Spec) bool { } func setupWorkloadContainerSpec(ctx context.Context, sbid, id string, spec *oci.Spec, ociBundlePath string) (err error) { - ctx, span := oc.StartSpan(ctx, "hcsv2::setupWorkloadContainerSpec") + ctx, span := otelutil.StartSpan(ctx, "hcsv2::setupWorkloadContainerSpec", trace.WithAttributes( + attribute.String("sandboxID", sbid), + attribute.String("cid", id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("sandboxID", sbid), - trace.StringAttribute("cid", id)) + defer func() { otelutil.SetSpanStatus(span, err) }() // Verify no hostname if spec.Hostname != "" { diff --git a/internal/guest/storage/devicemapper/targets.go b/internal/guest/storage/devicemapper/targets.go index b16f35562f..dedfdc139e 100644 --- a/internal/guest/storage/devicemapper/targets.go +++ b/internal/guest/storage/devicemapper/targets.go @@ -7,11 +7,12 @@ import ( "context" "fmt" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/unix" "github.com/Microsoft/hcsshim/ext4/dmverity" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" ) @@ -29,19 +30,17 @@ var retryErrors = []error{ // CreateZeroSectorLinearTarget creates dm-linear target for a device at `devPath` and `mappingInfo`, returns // virtual block device path. func CreateZeroSectorLinearTarget(ctx context.Context, devPath, devName string, mappingInfo *guestresource.LCOWVPMemMappingInfo) (_ string, err error) { - _, span := oc.StartSpan(ctx, "devicemapper::CreateZeroSectorLinearTarget") - defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - size := int64(mappingInfo.DeviceSizeInBytes) offset := int64(mappingInfo.DeviceOffsetInBytes) linearTarget := zeroSectorLinearTarget(size, devPath, offset) - span.AddAttributes( - trace.StringAttribute("devicePath", devPath), - trace.Int64Attribute("deviceStart", offset), - trace.Int64Attribute("sectorSize", size), - trace.StringAttribute("linearTable", fmt.Sprintf("%s: '%d %d %s'", devName, linearTarget.SectorStart, linearTarget.LengthInBlocks, linearTarget.Params))) + _, span := otelutil.StartSpan(ctx, "devicemapper::CreateZeroSectorLinearTarget", trace.WithAttributes( + attribute.String("devicePath", devPath), + attribute.Int64("deviceStart", offset), + attribute.Int64("sectorSize", size), + attribute.String("linearTable", fmt.Sprintf("%s: '%d %d %s'", devName, linearTarget.SectorStart, linearTarget.LengthInBlocks, linearTarget.Params)))) + defer span.End() + defer func() { otelutil.SetSpanStatus(span, err) }() devMapperPath, err := CreateDeviceWithRetryErrors( ctx, @@ -72,9 +71,9 @@ func CreateZeroSectorLinearTarget(ctx context.Context, devPath, devName string, // // [dm-verity]: https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html#construction-parameters func CreateVerityTarget(ctx context.Context, devPath, devName string, verityInfo *guestresource.DeviceVerityInfo) (_ string, err error) { - _, span := oc.StartSpan(ctx, "devicemapper::CreateVerityTarget") + _, span := otelutil.StartSpan(ctx, "devicemapper::CreateVerityTarget") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() dmBlocks := verityInfo.Ext4SizeInBytes / blockSize dataBlocks := verityInfo.Ext4SizeInBytes / int64(verityInfo.BlockSize) @@ -93,10 +92,10 @@ func CreateVerityTarget(ctx context.Context, devPath, devName string, verityInfo Params: fmt.Sprintf("%d %s %s %s", verityInfo.Version, devices, blkInfo, hashes), } - span.AddAttributes( - trace.StringAttribute("devicePath", devPath), - trace.Int64Attribute("sectorSize", dmBlocks), - trace.StringAttribute("verityTable", verityTarget.Params)) + span.SetAttributes( + attribute.String("devicePath", devPath), + attribute.Int64("sectorSize", dmBlocks), + attribute.String("verityTable", verityTarget.Params)) devMapperPath, err := CreateDeviceWithRetryErrors( ctx, diff --git a/internal/guest/storage/mount.go b/internal/guest/storage/mount.go index a3d10a3b25..3daaf70e03 100644 --- a/internal/guest/storage/mount.go +++ b/internal/guest/storage/mount.go @@ -13,10 +13,11 @@ import ( "syscall" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/unix" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" ) const procMountFile = "/proc/mounts" @@ -116,13 +117,11 @@ func MountRShared(path string) error { // UnmountPath unmounts the target path if it exists and is a mount path. If // removeTarget this will remove the previously mounted folder. func UnmountPath(ctx context.Context, target string, removeTarget bool) (err error) { - _, span := oc.StartSpan(ctx, "storage::UnmountPath") + _, span := otelutil.StartSpan(ctx, "storage::UnmountPath", trace.WithAttributes( + attribute.String("target", target), + attribute.Bool("remove", removeTarget))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("target", target), - trace.BoolAttribute("remove", removeTarget)) + defer func() { otelutil.SetSpanStatus(span, err) }() if _, err := osStat(target); err != nil { if os.IsNotExist(err) { diff --git a/internal/guest/storage/overlay/overlay.go b/internal/guest/storage/overlay/overlay.go index aa4877508f..9af3adb9d4 100644 --- a/internal/guest/storage/overlay/overlay.go +++ b/internal/guest/storage/overlay/overlay.go @@ -12,10 +12,11 @@ import ( "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/memory" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/unix" ) @@ -64,9 +65,9 @@ func MountLayer( upperdirPath, workdirPath, rootfsPath string, readonly bool, ) (err error) { - _, span := oc.StartSpan(ctx, "overlay::MountLayer") + _, span := otelutil.StartSpan(ctx, "overlay::MountLayer") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() return Mount(ctx, layerPaths, upperdirPath, workdirPath, rootfsPath, readonly) } @@ -82,17 +83,16 @@ func MountLayer( // Always creates `target`. On mount failure the created `target` will // be automatically cleaned up. func Mount(ctx context.Context, basePaths []string, upperdirPath, workdirPath, target string, readonly bool) (err error) { - _, span := oc.StartSpan(ctx, "overlay::Mount") - defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - lowerdir := strings.Join(basePaths, ":") - span.AddAttributes( - trace.StringAttribute("lowerdir", lowerdir), - trace.StringAttribute("upperdirPath", upperdirPath), - trace.StringAttribute("workdirPath", workdirPath), - trace.StringAttribute("target", target), - trace.BoolAttribute("readonly", readonly)) + + _, span := otelutil.StartSpan(ctx, "overlay::Mount", trace.WithAttributes( + attribute.String("lowerdir", lowerdir), + attribute.String("upperdirPath", upperdirPath), + attribute.String("workdirPath", workdirPath), + attribute.String("target", target), + attribute.Bool("readonly", readonly))) + defer span.End() + defer func() { otelutil.SetSpanStatus(span, err) }() // If we got an ENOSPC error on creating any directories, log disk space and inode info for // the mount that the directory belongs to get a better view of the where the problem lies. diff --git a/internal/guest/storage/plan9/plan9.go b/internal/guest/storage/plan9/plan9.go index 5c1f1d74f4..f834d67e23 100644 --- a/internal/guest/storage/plan9/plan9.go +++ b/internal/guest/storage/plan9/plan9.go @@ -10,9 +10,10 @@ import ( "syscall" "github.com/Microsoft/hcsshim/internal/guest/transport" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/unix" ) @@ -30,15 +31,13 @@ var ( // `target` will be created. On mount failure the created `target` will be // automatically cleaned up. func Mount(ctx context.Context, vsock transport.Transport, target, share string, port uint32, readonly bool) (err error) { - _, span := oc.StartSpan(ctx, "plan9::Mount") + _, span := otelutil.StartSpan(ctx, "plan9::Mount", trace.WithAttributes( + attribute.String("target", target), + attribute.String("share", share), + attribute.Int64("port", int64(port)), + attribute.Bool("readonly", readonly))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.StringAttribute("target", target), - trace.StringAttribute("share", share), - trace.Int64Attribute("port", int64(port)), - trace.BoolAttribute("readonly", readonly)) + defer func() { otelutil.SetSpanStatus(span, err) }() if err := osMkdirAll(target, 0700); err != nil { return err diff --git a/internal/guest/storage/pmem/pmem.go b/internal/guest/storage/pmem/pmem.go index 52bf4fec88..3e08b03820 100644 --- a/internal/guest/storage/pmem/pmem.go +++ b/internal/guest/storage/pmem/pmem.go @@ -9,13 +9,14 @@ import ( "os" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/unix" "github.com/Microsoft/hcsshim/internal/guest/storage" dm "github.com/Microsoft/hcsshim/internal/guest/storage/devicemapper" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" ) @@ -81,13 +82,11 @@ func Mount( mappingInfo *guestresource.LCOWVPMemMappingInfo, verityInfo *guestresource.DeviceVerityInfo, ) (err error) { - mCtx, span := oc.StartSpan(ctx, "pmem::Mount") + mCtx, span := otelutil.StartSpan(ctx, "pmem::Mount", trace.WithAttributes( + attribute.Int64("deviceNumber", int64(device)), + attribute.String("target", target))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.Int64Attribute("deviceNumber", int64(device)), - trace.StringAttribute("target", target)) + defer func() { otelutil.SetSpanStatus(span, err) }() devicePath := GetDevicePath(device) @@ -132,13 +131,11 @@ func Unmount( mappingInfo *guestresource.LCOWVPMemMappingInfo, verityInfo *guestresource.DeviceVerityInfo, ) (err error) { - _, span := oc.StartSpan(ctx, "pmem::Unmount") + _, span := otelutil.StartSpan(ctx, "pmem::Unmount", trace.WithAttributes( + attribute.Int64("device", int64(devNumber)), + attribute.String("target", target))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.Int64Attribute("device", int64(devNumber)), - trace.StringAttribute("target", target)) + defer func() { otelutil.SetSpanStatus(span, err) }() if err := storage.UnmountPath(ctx, target, true); err != nil { return errors.Wrapf(err, "failed to unmount target: %s", target) diff --git a/internal/guest/storage/scsi/scsi.go b/internal/guest/storage/scsi/scsi.go index a24946e467..2b5ea441cf 100644 --- a/internal/guest/storage/scsi/scsi.go +++ b/internal/guest/storage/scsi/scsi.go @@ -15,7 +15,8 @@ import ( "time" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/unix" "github.com/Microsoft/hcsshim/ext4/tar2ext4" @@ -25,7 +26,7 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/storage/ext4" "github.com/Microsoft/hcsshim/internal/guest/storage/xfs" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" ) @@ -131,15 +132,12 @@ func Mount( readonly bool, options []string, config *Config) (err error) { - spnCtx, span := oc.StartSpan(ctx, "scsi::Mount") + spnCtx, span := otelutil.StartSpan(ctx, "scsi::Mount", trace.WithAttributes( + attribute.Int64("controller", int64(controller)), + attribute.Int64("lun", int64(lun)), + attribute.Int64("partition", int64(partition)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.Int64Attribute("controller", int64(controller)), - trace.Int64Attribute("lun", int64(lun)), - trace.Int64Attribute("partition", int64(partition)), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() source, err := getDevicePath(spnCtx, controller, lun, partition) if err != nil { @@ -270,15 +268,13 @@ func Unmount( target string, config *Config, ) (err error) { - ctx, span := oc.StartSpan(ctx, "scsi::Unmount") + ctx, span := otelutil.StartSpan(ctx, "scsi::Unmount", trace.WithAttributes( + attribute.Int64("controller", int64(controller)), + attribute.Int64("lun", int64(lun)), + attribute.Int64("partition", int64(partition)), + attribute.String("target", target))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.Int64Attribute("controller", int64(controller)), - trace.Int64Attribute("lun", int64(lun)), - trace.Int64Attribute("partition", int64(partition)), - trace.StringAttribute("target", target)) + defer func() { otelutil.SetSpanStatus(span, err) }() // unmount target if err := storageUnmountPath(ctx, target, true); err != nil { @@ -307,15 +303,12 @@ func Unmount( // index `lun` with partition index `partition` and also ensures that the device // is available under that path or context is canceled. func GetDevicePath(ctx context.Context, controller, lun uint8, partition uint64) (_ string, err error) { - ctx, span := oc.StartSpan(ctx, "scsi::GetDevicePath") + ctx, span := otelutil.StartSpan(ctx, "scsi::GetDevicePath", trace.WithAttributes( + attribute.Int64("controller", int64(controller)), + attribute.Int64("lun", int64(lun)), + attribute.Int64("partition", int64(partition)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.Int64Attribute("controller", int64(controller)), - trace.Int64Attribute("lun", int64(lun)), - trace.Int64Attribute("partition", int64(partition)), - ) + defer func() { otelutil.SetSpanStatus(span, err) }() scsiID := fmt.Sprintf("%d:0:0:%d", controller, lun) // Devices matching the given SCSI code should each have a subdirectory @@ -403,13 +396,11 @@ func GetDevicePath(ctx context.Context, controller, lun uint8, partition uint64) // // If the device is not attached returns no error. func UnplugDevice(ctx context.Context, controller, lun uint8) (err error) { - _, span := oc.StartSpan(ctx, "scsi::UnplugDevice") + _, span := otelutil.StartSpan(ctx, "scsi::UnplugDevice", trace.WithAttributes( + attribute.Int64("controller", int64(controller)), + attribute.Int64("lun", int64(lun)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - - span.AddAttributes( - trace.Int64Attribute("controller", int64(controller)), - trace.Int64Attribute("lun", int64(lun))) + defer func() { otelutil.SetSpanStatus(span, err) }() scsiID := fmt.Sprintf("%d:0:0:%d", controller, lun) f, err := os.OpenFile(filepath.Join(scsiDevicesPath, scsiID, "delete"), os.O_WRONLY, 0644) diff --git a/internal/hcs/process.go b/internal/hcs/process.go index 8ef611d6a0..8daa3a79f8 100644 --- a/internal/hcs/process.go +++ b/internal/hcs/process.go @@ -12,12 +12,13 @@ import ( "syscall" "time" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/Microsoft/hcsshim/internal/cow" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" "github.com/Microsoft/hcsshim/internal/vmcompute" ) @@ -212,11 +213,10 @@ func (process *Process) Kill(ctx context.Context) (bool, error) { // call multiple times. func (process *Process) waitBackground() { operation := "hcs::Process::waitBackground" - ctx, span := oc.StartSpan(context.Background(), operation) + ctx, span := otelutil.StartSpan(context.Background(), operation, trace.WithAttributes( + attribute.String("cid", process.SystemID()), + attribute.Int64("pid", int64(process.processID)))) defer span.End() - span.AddAttributes( - trace.StringAttribute("cid", process.SystemID()), - trace.Int64Attribute("pid", int64(process.processID))) var ( err error @@ -261,7 +261,7 @@ func (process *Process) waitBackground() { process.waitError = err close(process.waitBlock) }) - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) } // Wait waits for the process to exit. If the process has already exited returns @@ -330,12 +330,11 @@ func (process *Process) ExitCode() (int, error) { // are the responsibility of the caller to close. func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) { operation := "hcs::Process::StdioLegacy" - ctx, span := oc.StartSpan(context.Background(), operation) + ctx, span := otelutil.StartSpan(context.Background(), operation, trace.WithAttributes( + attribute.String("cid", process.SystemID()), + attribute.Int64("pid", int64(process.processID)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", process.SystemID()), - trace.Int64Attribute("pid", int64(process.processID))) + defer func() { otelutil.SetSpanStatus(span, err) }() process.handleLock.RLock() defer process.handleLock.RUnlock() @@ -379,12 +378,11 @@ func (process *Process) Stdio() (stdin io.Writer, stdout, stderr io.Reader) { // notified on the read side that there is no more data in stdin. func (process *Process) CloseStdin(ctx context.Context) (err error) { operation := "hcs::Process::CloseStdin" - ctx, span := trace.StartSpan(ctx, operation) + ctx, span := otelutil.StartSpan(ctx, operation, trace.WithAttributes( + attribute.String("cid", process.SystemID()), + attribute.Int64("pid", int64(process.processID)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", process.SystemID()), - trace.Int64Attribute("pid", int64(process.processID))) + defer func() { otelutil.SetSpanStatus(span, err) }() process.handleLock.RLock() defer process.handleLock.RUnlock() @@ -425,12 +423,11 @@ func (process *Process) CloseStdin(ctx context.Context) (err error) { } func (process *Process) CloseStdout(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "hcs::Process::CloseStdout") //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, "hcs::Process::CloseStdout", trace.WithAttributes( + attribute.String("cid", process.SystemID()), + attribute.Int64("pid", int64(process.processID)))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", process.SystemID()), - trace.Int64Attribute("pid", int64(process.processID))) + defer func() { otelutil.SetSpanStatus(span, err) }() process.handleLock.Lock() defer process.handleLock.Unlock() @@ -449,12 +446,11 @@ func (process *Process) CloseStdout(ctx context.Context) (err error) { } func (process *Process) CloseStderr(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "hcs::Process::CloseStderr") //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, "hcs::Process::CloseStderr", trace.WithAttributes( + attribute.String("cid", process.SystemID()), + attribute.Int64("pid", int64(process.processID)))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", process.SystemID()), - trace.Int64Attribute("pid", int64(process.processID))) + defer func() { otelutil.SetSpanStatus(span, err) }() process.handleLock.Lock() defer process.handleLock.Unlock() @@ -476,12 +472,11 @@ func (process *Process) CloseStderr(ctx context.Context) (err error) { // or wait on it. func (process *Process) Close() (err error) { operation := "hcs::Process::Close" - ctx, span := oc.StartSpan(context.Background(), operation) + ctx, span := otelutil.StartSpan(context.Background(), operation, trace.WithAttributes( + attribute.String("cid", process.SystemID()), + attribute.Int64("pid", int64(process.processID)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("cid", process.SystemID()), - trace.Int64Attribute("pid", int64(process.processID))) + defer func() { otelutil.SetSpanStatus(span, err) }() process.handleLock.Lock() defer process.handleLock.Unlock() diff --git a/internal/hcs/system.go b/internal/hcs/system.go index 81d60ed434..6cca70daef 100644 --- a/internal/hcs/system.go +++ b/internal/hcs/system.go @@ -18,11 +18,12 @@ import ( "github.com/Microsoft/hcsshim/internal/jobobject" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/timeout" "github.com/Microsoft/hcsshim/internal/vmcompute" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) type System struct { @@ -60,10 +61,10 @@ func CreateComputeSystem(ctx context.Context, id string, hcsDocumentInterface in // hcsCreateComputeSystemContext is an async operation. Start the outer span // here to measure the full create time. - ctx, span := oc.StartSpan(ctx, operation) + ctx, span := otelutil.StartSpan(ctx, operation, trace.WithAttributes( + attribute.String("cid", id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", id)) + defer func() { otelutil.SetSpanStatus(span, err) }() computeSystem := newSystem(id) @@ -196,10 +197,10 @@ func (computeSystem *System) Start(ctx context.Context) (err error) { // hcsStartComputeSystemContext is an async operation. Start the outer span // here to measure the full start time. - ctx, span := oc.StartSpan(ctx, operation) + ctx, span := otelutil.StartSpan(ctx, operation, trace.WithAttributes( + attribute.String("cid", computeSystem.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() computeSystem.handleLock.RLock() defer computeSystem.handleLock.RUnlock() @@ -274,9 +275,9 @@ func (computeSystem *System) Terminate(ctx context.Context) error { // safe to call multiple times. func (computeSystem *System) waitBackground() { operation := "hcs::System::waitBackground" - ctx, span := oc.StartSpan(context.Background(), operation) + ctx, span := otelutil.StartSpan(context.Background(), operation, trace.WithAttributes( + attribute.String("cid", computeSystem.id))) defer span.End() - span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) err := waitForNotification(ctx, computeSystem.callbackNumber, hcsNotificationSystemExited, nil) switch err { //nolint:errorlint @@ -293,7 +294,7 @@ func (computeSystem *System) waitBackground() { computeSystem.waitError = err close(computeSystem.waitBlock) }) - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) } func (computeSystem *System) WaitChannel() <-chan struct{} { @@ -577,10 +578,10 @@ func (computeSystem *System) Pause(ctx context.Context) (err error) { // hcsPauseComputeSystemContext is an async operation. Start the outer span // here to measure the full pause time. - ctx, span := oc.StartSpan(ctx, operation) + ctx, span := otelutil.StartSpan(ctx, operation, trace.WithAttributes( + attribute.String("cid", computeSystem.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() computeSystem.handleLock.RLock() defer computeSystem.handleLock.RUnlock() @@ -605,10 +606,10 @@ func (computeSystem *System) Resume(ctx context.Context) (err error) { // hcsResumeComputeSystemContext is an async operation. Start the outer span // here to measure the full restore time. - ctx, span := oc.StartSpan(ctx, operation) + ctx, span := otelutil.StartSpan(ctx, operation, trace.WithAttributes( + attribute.String("cid", computeSystem.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() computeSystem.handleLock.RLock() defer computeSystem.handleLock.RUnlock() @@ -633,10 +634,10 @@ func (computeSystem *System) Save(ctx context.Context, options interface{}) (err // hcsSaveComputeSystemContext is an async operation. Start the outer span // here to measure the full save time. - ctx, span := oc.StartSpan(ctx, operation) + ctx, span := otelutil.StartSpan(ctx, operation, trace.WithAttributes( + attribute.String("cid", computeSystem.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() saveOptions, err := json.Marshal(options) if err != nil { @@ -756,10 +757,10 @@ func (computeSystem *System) Close() error { // proper system cleanup. func (computeSystem *System) CloseCtx(ctx context.Context) (err error) { operation := "hcs::System::Close" - ctx, span := oc.StartSpan(ctx, operation) + ctx, span := otelutil.StartSpan(ctx, operation, trace.WithAttributes( + attribute.String("cid", computeSystem.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("cid", computeSystem.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() computeSystem.handleLock.Lock() defer computeSystem.handleLock.Unlock() diff --git a/internal/log/format.go b/internal/log/format.go index f26316fabf..90fe45d7bf 100644 --- a/internal/log/format.go +++ b/internal/log/format.go @@ -61,7 +61,7 @@ func formatAddr(a net.Addr) string { // HTML escapes. // Context is used to output a log waring if the conversion fails. // -// This is intended primarily for `trace.StringAttribute()` +// This is intended primarily for `attribute.String()` func Format(ctx context.Context, v interface{}) string { b, err := encode(v) if err != nil { diff --git a/internal/log/hook.go b/internal/log/hook.go index bb547a329f..428f612e4f 100644 --- a/internal/log/hook.go +++ b/internal/log/hook.go @@ -7,7 +7,7 @@ import ( "github.com/Microsoft/hcsshim/internal/logfields" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/trace" ) const nullString = "null" @@ -163,11 +163,11 @@ func (h *Hook) addSpanContext(e *logrus.Entry) { if !h.AddSpanContext || ctx == nil { return } - span := trace.FromContext(ctx) + span := trace.SpanFromContext(ctx) if span == nil { return } sctx := span.SpanContext() - e.Data[logfields.TraceID] = sctx.TraceID.String() - e.Data[logfields.SpanID] = sctx.SpanID.String() + e.Data[logfields.TraceID] = sctx.TraceID().String() + e.Data[logfields.SpanID] = sctx.SpanID().String() } diff --git a/internal/oc/exporter.go b/internal/oc/exporter.go deleted file mode 100644 index 28f8f43a93..0000000000 --- a/internal/oc/exporter.go +++ /dev/null @@ -1,86 +0,0 @@ -package oc - -import ( - "github.com/sirupsen/logrus" - "go.opencensus.io/trace" - "google.golang.org/grpc/codes" - - "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/logfields" -) - -const spanMessage = "Span" - -var _errorCodeKey = logrus.ErrorKey + "Code" - -// LogrusExporter is an OpenCensus `trace.Exporter` that exports -// `trace.SpanData` to logrus output. -type LogrusExporter struct{} - -var _ trace.Exporter = &LogrusExporter{} - -// ExportSpan exports `s` based on the the following rules: -// -// 1. All output will contain `s.Attributes`, `s.SpanKind`, `s.TraceID`, -// `s.SpanID`, and `s.ParentSpanID` for correlation -// -// 2. Any calls to .Annotate will not be supported. -// -// 3. The span itself will be written at `logrus.InfoLevel` unless -// `s.Status.Code != 0` in which case it will be written at `logrus.ErrorLevel` -// providing `s.Status.Message` as the error value. -func (le *LogrusExporter) ExportSpan(s *trace.SpanData) { - if s.DroppedAnnotationCount > 0 { - logrus.WithFields(logrus.Fields{ - "name": s.Name, - logfields.TraceID: s.TraceID.String(), - logfields.SpanID: s.SpanID.String(), - "dropped": s.DroppedAttributeCount, - "maxAttributes": len(s.Attributes), - }).Warning("span had dropped attributes") - } - - entry := log.L.Dup() - // Combine all span annotations with span data (eg, trace ID, span ID, parent span ID, - // error, status code) - // (OC) Span attributes are guaranteed to be strings, bools, or int64s, so we can - // can skip overhead in entry.WithFields() and add them directly to entry.Data. - // Preallocate ahead of time, since we should add, at most, 10 additional entries - data := make(logrus.Fields, len(entry.Data)+len(s.Attributes)+10) - - // Default log entry may have prexisting/application-wide data - for k, v := range entry.Data { - data[k] = v - } - for k, v := range s.Attributes { - data[k] = v - } - - data[logfields.Name] = s.Name - data[logfields.TraceID] = s.TraceID.String() - data[logfields.SpanID] = s.SpanID.String() - data[logfields.ParentSpanID] = s.ParentSpanID.String() - data[logfields.StartTime] = s.StartTime - data[logfields.EndTime] = s.EndTime - data[logfields.Duration] = s.EndTime.Sub(s.StartTime) - if sk := spanKindToString(s.SpanKind); sk != "" { - data["spanKind"] = sk - } - - level := logrus.InfoLevel - if s.Status.Code != 0 { - level = logrus.ErrorLevel - - // don't overwrite an existing "error" or "errorCode" attributes - if _, ok := data[logrus.ErrorKey]; !ok { - data[logrus.ErrorKey] = s.Status.Message - } - if _, ok := data[_errorCodeKey]; !ok { - data[_errorCodeKey] = codes.Code(s.Status.Code).String() - } - } - - entry.Data = data - entry.Time = s.StartTime - entry.Log(level, spanMessage) -} diff --git a/internal/oc/span.go b/internal/oc/span.go deleted file mode 100644 index 7260784326..0000000000 --- a/internal/oc/span.go +++ /dev/null @@ -1,58 +0,0 @@ -package oc - -import ( - "context" - - "github.com/Microsoft/hcsshim/internal/log" - "go.opencensus.io/trace" -) - -var DefaultSampler = trace.AlwaysSample() - -// SetSpanStatus sets `span.SetStatus` to the proper status depending on `err`. If -// `err` is `nil` assumes `trace.StatusCodeOk`. -func SetSpanStatus(span *trace.Span, err error) { - status := trace.Status{} - if err != nil { - status.Code = int32(toStatusCode(err)) - status.Message = err.Error() - } - span.SetStatus(status) -} - -// StartSpan wraps "go.opencensus.io/trace".StartSpan, but, if the span is sampling, -// adds a log entry to the context that points to the newly created span. -func StartSpan(ctx context.Context, name string, o ...trace.StartOption) (context.Context, *trace.Span) { - ctx, s := trace.StartSpan(ctx, name, o...) - return update(ctx, s) -} - -// StartSpanWithRemoteParent wraps "go.opencensus.io/trace".StartSpanWithRemoteParent. -// -// See StartSpan for more information. -func StartSpanWithRemoteParent(ctx context.Context, name string, parent trace.SpanContext, o ...trace.StartOption) (context.Context, *trace.Span) { - ctx, s := trace.StartSpanWithRemoteParent(ctx, name, parent, o...) - return update(ctx, s) -} - -func update(ctx context.Context, s *trace.Span) (context.Context, *trace.Span) { - if s.IsRecordingEvents() { - ctx = log.UpdateContext(ctx) - } - - return ctx, s -} - -var WithServerSpanKind = trace.WithSpanKind(trace.SpanKindServer) -var WithClientSpanKind = trace.WithSpanKind(trace.SpanKindClient) - -func spanKindToString(sk int) string { - switch sk { - case trace.SpanKindClient: - return "client" - case trace.SpanKindServer: - return "server" - default: - return "" - } -} diff --git a/internal/oc/errors.go b/internal/otelutil/errors.go similarity index 99% rename from internal/oc/errors.go rename to internal/otelutil/errors.go index 8c41a3661e..d1d692bb2d 100644 --- a/internal/oc/errors.go +++ b/internal/otelutil/errors.go @@ -1,4 +1,4 @@ -package oc +package otelutil import ( "errors" diff --git a/internal/otelutil/exporter.go b/internal/otelutil/exporter.go new file mode 100644 index 0000000000..2f134f0e6f --- /dev/null +++ b/internal/otelutil/exporter.go @@ -0,0 +1,102 @@ +package otelutil + +import ( + "context" + + "github.com/sirupsen/logrus" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "google.golang.org/grpc/codes" + + "github.com/Microsoft/hcsshim/internal/log" + "github.com/Microsoft/hcsshim/internal/logfields" +) + +const spanMessage = "Span" + +var _errorCodeKey = logrus.ErrorKey + "Code" + +// LogrusExporter is an OpenTelemetry `trace.Exporter` that exports +// `trace.SpanData` to logrus output. +type LogrusExporter struct{} + +var _ sdktrace.SpanExporter = &LogrusExporter{} + +// ExportSpans exports `spans` based on the the following rules: +// +// 1. All output will contain `s.Attributes`, `s.SpanKind`, `s.TraceID`, +// `s.SpanID`, and `s.ParentSpanID` for correlation +// +// 2. Any calls to .Annotate will not be supported. +// +// 3. The span itself will be written at `logrus.InfoLevel` unless +// `s.Status.Code != 0` in which case it will be written at `logrus.ErrorLevel` +// providing `s.Status.Message` as the error value. +func (le *LogrusExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error { + for _, s := range spans { + le.exportSpan(s) + } + return nil +} + +func (le *LogrusExporter) exportSpan(s sdktrace.ReadOnlySpan) { + sc := s.SpanContext() + if s.DroppedAttributes() > 0 || s.DroppedEvents() > 0 || s.DroppedLinks() > 0 { + logrus.WithFields(logrus.Fields{ + "name": s.Name, + logfields.TraceID: sc.TraceID().String(), + logfields.SpanID: sc.SpanID().String(), + "droppedAttributers": s.DroppedAttributes(), + "droppedEvents": s.DroppedEvents(), + "droppedLinks": s.DroppedLinks(), + "maxAttributes": len(s.Attributes()), + }).Warning("span had dropped attributes") + } + + entry := log.L.Dup() + // Combine all span annotations with span data (eg, trace ID, span ID, parent span ID, + // error, status code) + // (OC) Span attributes are guaranteed to be strings, bools, or int64s, so we can + // can skip overhead in entry.WithFields() and add them directly to entry.Data. + // Preallocate ahead of time, since we should add, at most, 10 additional entries + data := make(logrus.Fields, len(entry.Data)+len(s.Attributes())+10) + + // Default log entry may have prexisting/application-wide data + for k, v := range entry.Data { + data[k] = v + } + for _, v := range s.Attributes() { + data[string(v.Key)] = v.Value + } + + data[logfields.Name] = s.Name + data[logfields.TraceID] = sc.TraceID().String() + data[logfields.SpanID] = sc.SpanID().String() + data[logfields.ParentSpanID] = s.Parent().SpanID().String() + data[logfields.StartTime] = s.StartTime() + data[logfields.EndTime] = s.EndTime() + data[logfields.Duration] = s.EndTime().Sub(s.StartTime()) + if sk := spanKindToString(s.SpanKind()); sk != "" { + data["spanKind"] = sk + } + + level := logrus.InfoLevel + if s.Status().Code != 0 { + level = logrus.ErrorLevel + + // don't overwrite an existing "error" or "errorCode" attributes + if _, ok := data[logrus.ErrorKey]; !ok { + data[logrus.ErrorKey] = s.Status().Description + } + if _, ok := data[_errorCodeKey]; !ok { + data[_errorCodeKey] = codes.Code(s.Status().Code).String() + } + } + + entry.Data = data + entry.Time = s.StartTime() + entry.Log(level, spanMessage) +} + +func (le *LogrusExporter) Shutdown(context.Context) error { + return nil +} diff --git a/internal/otelutil/span.go b/internal/otelutil/span.go new file mode 100644 index 0000000000..bbb37e0911 --- /dev/null +++ b/internal/otelutil/span.go @@ -0,0 +1,53 @@ +package otelutil + +import ( + "context" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/codes" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/trace" + + "github.com/Microsoft/hcsshim/internal/log" +) + +var DefaultSampler = sdktrace.AlwaysSample() + +// SetSpanStatus sets `span.SetStatus` to the proper status depending on `err`. If +// `err` is `nil` assumes `codes.Ok`. +func SetSpanStatus(span trace.Span, err error) { + if err != nil { + span.SetStatus(codes.Code(toStatusCode(err)), err.Error()) + } else { + span.SetStatus(codes.Ok, "") + } +} + +// StartSpan wraps "go.opentelemetry.io/otel/trace".StartSpan, but, if the span is sampling, +// adds a log entry to the context that points to the newly created span. +func StartSpan(ctx context.Context, name string, o ...trace.SpanStartOption) (context.Context, trace.Span) { + ctx, s := otel.Tracer("").Start(ctx, name, o...) + return update(ctx, s) +} + +func update(ctx context.Context, s trace.Span) (context.Context, trace.Span) { + if s.IsRecording() { + ctx = log.UpdateContext(ctx) + } + + return ctx, s +} + +var WithServerSpanKind = trace.WithSpanKind(trace.SpanKindServer) +var WithClientSpanKind = trace.WithSpanKind(trace.SpanKindClient) + +func spanKindToString(sk trace.SpanKind) string { + switch sk { + case trace.SpanKindClient: + return "client" + case trace.SpanKindServer: + return "server" + default: + return "" + } +} diff --git a/internal/uvm/computeagent.go b/internal/uvm/computeagent.go index 7516cdf6ea..bf640248c0 100644 --- a/internal/uvm/computeagent.go +++ b/internal/uvm/computeagent.go @@ -21,7 +21,7 @@ import ( "github.com/Microsoft/hcsshim/internal/log" ncproxynetworking "github.com/Microsoft/hcsshim/internal/ncproxy/networking" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" - "github.com/Microsoft/hcsshim/pkg/octtrpc" + "github.com/Microsoft/hcsshim/pkg/otelttrpc" ) func init() { @@ -234,7 +234,7 @@ func setupAndServe(ctx context.Context, caAddr string, vm *UtilityVM) error { if err != nil { return errors.Wrapf(err, "failed to listen on %s", caAddr) } - s, err := ttrpc.NewServer(ttrpc.WithUnaryServerInterceptor(octtrpc.ServerInterceptor())) + s, err := ttrpc.NewServer(ttrpc.WithUnaryServerInterceptor(otelttrpc.ServerInterceptor())) if err != nil { return err } diff --git a/internal/uvm/create.go b/internal/uvm/create.go index fa28857617..112bca78f7 100644 --- a/internal/uvm/create.go +++ b/internal/uvm/create.go @@ -11,7 +11,8 @@ import ( "runtime" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/windows" "github.com/Microsoft/hcsshim/internal/cow" @@ -19,7 +20,7 @@ import ( hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/schemaversion" "github.com/Microsoft/hcsshim/osversion" ) @@ -216,10 +217,10 @@ func (uvm *UtilityVM) Close() error { return uvm.CloseCtx(context.Background()) // The context is used for all operations, including waits, so timeouts/cancellations may prevent // proper uVM cleanup. func (uvm *UtilityVM) CloseCtx(ctx context.Context) (err error) { - ctx, span := oc.StartSpan(ctx, "uvm::Close") + ctx, span := otelutil.StartSpan(ctx, "uvm::Close", trace.WithAttributes( + attribute.String(logfields.UVMID, uvm.id))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute(logfields.UVMID, uvm.id)) + defer func() { otelutil.SetSpanStatus(span, err) }() // TODO: check if uVM already closed diff --git a/internal/uvm/create_lcow.go b/internal/uvm/create_lcow.go index ced3518dbd..a5a8705de4 100644 --- a/internal/uvm/create_lcow.go +++ b/internal/uvm/create_lcow.go @@ -17,14 +17,14 @@ import ( "github.com/Microsoft/hcsshim/pkg/securitypolicy" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" "github.com/Microsoft/hcsshim/internal/copyfile" "github.com/Microsoft/hcsshim/internal/gcs" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/processorinfo" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" "github.com/Microsoft/hcsshim/internal/schemaversion" @@ -845,9 +845,9 @@ func makeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs // consumes a set of options derived from various defaults and options // expressed as annotations. func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error) { - ctx, span := oc.StartSpan(ctx, "uvm::CreateLCOW") + ctx, span := otelutil.StartSpan(ctx, "uvm::CreateLCOW") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() if opts.ID == "" { g, err := guid.NewV4() @@ -857,7 +857,7 @@ func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error opts.ID = g.String() } - span.AddAttributes(trace.StringAttribute(logfields.UVMID, opts.ID)) + span.SetAttributes(attribute.String(logfields.UVMID, opts.ID)) log.G(ctx).WithField("options", log.Format(ctx, opts)).Debug("uvm::CreateLCOW options") // We don't serialize OutputHandlerCreator so if it is missing we need to put it back to the default. diff --git a/internal/uvm/create_wcow.go b/internal/uvm/create_wcow.go index f413720b5c..c69fbcedc6 100644 --- a/internal/uvm/create_wcow.go +++ b/internal/uvm/create_wcow.go @@ -12,13 +12,13 @@ import ( "github.com/Microsoft/go-winio" "github.com/Microsoft/go-winio/pkg/guid" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" "github.com/Microsoft/hcsshim/internal/gcs" hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/processorinfo" "github.com/Microsoft/hcsshim/internal/protocol/guestrequest" "github.com/Microsoft/hcsshim/internal/schemaversion" @@ -241,9 +241,9 @@ func prepareConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWCOW) (* // WCOW Notes: // - The scratch is always attached to SCSI 0:0 func CreateWCOW(ctx context.Context, opts *OptionsWCOW) (_ *UtilityVM, err error) { - ctx, span := oc.StartSpan(ctx, "uvm::CreateWCOW") + ctx, span := otelutil.StartSpan(ctx, "uvm::CreateWCOW") defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() if opts.ID == "" { g, err := guid.NewV4() @@ -253,7 +253,7 @@ func CreateWCOW(ctx context.Context, opts *OptionsWCOW) (_ *UtilityVM, err error opts.ID = g.String() } - span.AddAttributes(trace.StringAttribute(logfields.UVMID, opts.ID)) + span.SetAttributes(attribute.String(logfields.UVMID, opts.ID)) log.G(ctx).WithField("options", log.Format(ctx, opts)).Debug("uvm::CreateWCOW options") uvm := &UtilityVM{ diff --git a/internal/vhdx/info.go b/internal/vhdx/info.go index 4fc3bfd288..32d6e00475 100644 --- a/internal/vhdx/info.go +++ b/internal/vhdx/info.go @@ -14,9 +14,10 @@ import ( "github.com/Microsoft/go-winio/pkg/guid" "github.com/Microsoft/go-winio/vhd" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/windows" ) @@ -154,11 +155,10 @@ func GetScratchVhdPartitionInfo(ctx context.Context, vhdxPath string) (_ Scratch ) title := "hcsshim::GetScratchVhdPartitionInfo" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", vhdxPath))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("path", vhdxPath)) + defer func() { otelutil.SetSpanStatus(span, err) }() diskHandle, err = vhd.OpenVirtualDisk(vhdxPath, vhd.VirtualDiskAccessNone, vhd.OpenVirtualDiskFlagNone) if err != nil { diff --git a/internal/vmcompute/vmcompute.go b/internal/vmcompute/vmcompute.go index 67ca897cfc..8780a70e4c 100644 --- a/internal/vmcompute/vmcompute.go +++ b/internal/vmcompute/vmcompute.go @@ -8,12 +8,13 @@ import ( "time" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "github.com/Microsoft/hcsshim/internal/interop" "github.com/Microsoft/hcsshim/internal/log" "github.com/Microsoft/hcsshim/internal/logfields" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/timeout" ) @@ -117,15 +118,15 @@ func execute(ctx gcontext.Context, timeout time.Duration, f func() error) error } func HcsEnumerateComputeSystems(ctx gcontext.Context, query string) (computeSystems, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsEnumerateComputeSystems") + ctx, span := otelutil.StartSpan(ctx, "HcsEnumerateComputeSystems", trace.WithAttributes( + attribute.String("query", query))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - span.AddAttributes(trace.StringAttribute("query", query)) return computeSystems, result, execute(ctx, timeout.SyscallWatcher, func() error { var ( @@ -144,19 +145,18 @@ func HcsEnumerateComputeSystems(ctx gcontext.Context, query string) (computeSyst } func HcsCreateComputeSystem(ctx gcontext.Context, id string, configuration string, identity syscall.Handle) (computeSystem HcsSystem, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsCreateComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsCreateComputeSystem", trace.WithAttributes( + attribute.String("id", id), + attribute.String("configuration", configuration))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } if hr != errVmcomputeOperationPending { //nolint:errorlint // explicitly returned - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) } }() - span.AddAttributes( - trace.StringAttribute("id", id), - trace.StringAttribute("configuration", configuration)) return computeSystem, result, execute(ctx, timeout.SystemCreate, func() error { var resultp *uint16 @@ -169,13 +169,13 @@ func HcsCreateComputeSystem(ctx gcontext.Context, id string, configuration strin } func HcsOpenComputeSystem(ctx gcontext.Context, id string) (computeSystem HcsSystem, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsOpenComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsOpenComputeSystem") defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() return computeSystem, result, execute(ctx, timeout.SyscallWatcher, func() error { @@ -189,9 +189,9 @@ func HcsOpenComputeSystem(ctx gcontext.Context, id string) (computeSystem HcsSys } func HcsCloseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem) (hr error) { - ctx, span := oc.StartSpan(ctx, "HcsCloseComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsCloseComputeSystem") defer span.End() - defer func() { oc.SetSpanStatus(span, hr) }() + defer func() { otelutil.SetSpanStatus(span, hr) }() return execute(ctx, timeout.SyscallWatcher, func() error { return hcsCloseComputeSystem(computeSystem) @@ -199,17 +199,17 @@ func HcsCloseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem) (hr er } func HcsStartComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsStartComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsStartComputeSystem", trace.WithAttributes( + attribute.String("options", options))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } if hr != errVmcomputeOperationPending { //nolint:errorlint // explicitly returned - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) } }() - span.AddAttributes(trace.StringAttribute("options", options)) return result, execute(ctx, timeout.SystemStart, func() error { var resultp *uint16 @@ -222,17 +222,17 @@ func HcsStartComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, option } func HcsShutdownComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsShutdownComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsShutdownComputeSystem", trace.WithAttributes( + attribute.String("options", options))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } if hr != errVmcomputeOperationPending { //nolint:errorlint // explicitly returned - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) } }() - span.AddAttributes(trace.StringAttribute("options", options)) return result, execute(ctx, timeout.SyscallWatcher, func() error { var resultp *uint16 @@ -245,17 +245,17 @@ func HcsShutdownComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, opt } func HcsTerminateComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsTerminateComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsTerminateComputeSystem", trace.WithAttributes( + attribute.String("options", options))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } if hr != errVmcomputeOperationPending { //nolint:errorlint // explicitly returned - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) } }() - span.AddAttributes(trace.StringAttribute("options", options)) return result, execute(ctx, timeout.SyscallWatcher, func() error { var resultp *uint16 @@ -268,17 +268,17 @@ func HcsTerminateComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, op } func HcsPauseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsPauseComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsPauseComputeSystem", trace.WithAttributes( + attribute.String("options", options))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } if hr != errVmcomputeOperationPending { //nolint:errorlint // explicitly returned - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) } }() - span.AddAttributes(trace.StringAttribute("options", options)) return result, execute(ctx, timeout.SystemPause, func() error { var resultp *uint16 @@ -291,17 +291,17 @@ func HcsPauseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, option } func HcsResumeComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsResumeComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsResumeComputeSystem", trace.WithAttributes( + attribute.String("options", options))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } if hr != errVmcomputeOperationPending { //nolint:errorlint // explicitly returned - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) } }() - span.AddAttributes(trace.StringAttribute("options", options)) return result, execute(ctx, timeout.SystemResume, func() error { var resultp *uint16 @@ -314,15 +314,15 @@ func HcsResumeComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, optio } func HcsGetComputeSystemProperties(ctx gcontext.Context, computeSystem HcsSystem, propertyQuery string) (properties, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsGetComputeSystemProperties") + ctx, span := otelutil.StartSpan(ctx, "HcsGetComputeSystemProperties", trace.WithAttributes( + attribute.String("propertyQuery", propertyQuery))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - span.AddAttributes(trace.StringAttribute("propertyQuery", propertyQuery)) return properties, result, execute(ctx, timeout.SyscallWatcher, func() error { var ( @@ -341,15 +341,15 @@ func HcsGetComputeSystemProperties(ctx gcontext.Context, computeSystem HcsSystem } func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, configuration string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsModifyComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsModifyComputeSystem", trace.WithAttributes( + attribute.String("configuration", configuration))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - span.AddAttributes(trace.StringAttribute("configuration", configuration)) return result, execute(ctx, timeout.SyscallWatcher, func() error { var resultp *uint16 @@ -362,15 +362,15 @@ func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, confi } func HcsModifyServiceSettings(ctx gcontext.Context, settings string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsModifyServiceSettings") + ctx, span := otelutil.StartSpan(ctx, "HcsModifyServiceSettings", trace.WithAttributes( + attribute.String("settings", settings))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - span.AddAttributes(trace.StringAttribute("settings", settings)) return result, execute(ctx, timeout.SyscallWatcher, func() error { var resultp *uint16 @@ -383,9 +383,9 @@ func HcsModifyServiceSettings(ctx gcontext.Context, settings string) (result str } func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSystem, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsRegisterComputeSystemCallback") + ctx, span := otelutil.StartSpan(ctx, "HcsRegisterComputeSystemCallback") defer span.End() - defer func() { oc.SetSpanStatus(span, hr) }() + defer func() { otelutil.SetSpanStatus(span, hr) }() return callbackHandle, execute(ctx, timeout.SyscallWatcher, func() error { return hcsRegisterComputeSystemCallback(computeSystem, callback, context, &callbackHandle) @@ -393,9 +393,9 @@ func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSys } func HcsUnregisterComputeSystemCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) { - ctx, span := oc.StartSpan(ctx, "HcsUnregisterComputeSystemCallback") + ctx, span := otelutil.StartSpan(ctx, "HcsUnregisterComputeSystemCallback") defer span.End() - defer func() { oc.SetSpanStatus(span, hr) }() + defer func() { otelutil.SetSpanStatus(span, hr) }() return execute(ctx, timeout.SyscallWatcher, func() error { return hcsUnregisterComputeSystemCallback(callbackHandle) @@ -403,18 +403,18 @@ func HcsUnregisterComputeSystemCallback(ctx gcontext.Context, callbackHandle Hcs } func HcsCreateProcess(ctx gcontext.Context, computeSystem HcsSystem, processParameters string) (processInformation HcsProcessInformation, process HcsProcess, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsCreateProcess") + ctx, span := otelutil.StartSpan(ctx, "HcsCreateProcess") defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - if span.IsRecordingEvents() { + if span.IsRecording() { // wont handle v1 process parameters if s, err := log.ScrubProcessParameters(processParameters); err == nil { - span.AddAttributes(trace.StringAttribute("processParameters", s)) + span.SetAttributes(attribute.String("processParameters", s)) } } @@ -429,15 +429,15 @@ func HcsCreateProcess(ctx gcontext.Context, computeSystem HcsSystem, processPara } func HcsOpenProcess(ctx gcontext.Context, computeSystem HcsSystem, pid uint32) (process HcsProcess, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsOpenProcess") + ctx, span := otelutil.StartSpan(ctx, "HcsOpenProcess", trace.WithAttributes( + attribute.Int64("pid", int64(pid)))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - span.AddAttributes(trace.Int64Attribute("pid", int64(pid))) return process, result, execute(ctx, timeout.SyscallWatcher, func() error { var resultp *uint16 @@ -450,9 +450,9 @@ func HcsOpenProcess(ctx gcontext.Context, computeSystem HcsSystem, pid uint32) ( } func HcsCloseProcess(ctx gcontext.Context, process HcsProcess) (hr error) { - ctx, span := oc.StartSpan(ctx, "HcsCloseProcess") + ctx, span := otelutil.StartSpan(ctx, "HcsCloseProcess") defer span.End() - defer func() { oc.SetSpanStatus(span, hr) }() + defer func() { otelutil.SetSpanStatus(span, hr) }() return execute(ctx, timeout.SyscallWatcher, func() error { return hcsCloseProcess(process) @@ -460,13 +460,13 @@ func HcsCloseProcess(ctx gcontext.Context, process HcsProcess) (hr error) { } func HcsTerminateProcess(ctx gcontext.Context, process HcsProcess) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsTerminateProcess") + ctx, span := otelutil.StartSpan(ctx, "HcsTerminateProcess") defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() return result, execute(ctx, timeout.SyscallWatcher, func() error { @@ -480,15 +480,15 @@ func HcsTerminateProcess(ctx gcontext.Context, process HcsProcess) (result strin } func HcsSignalProcess(ctx gcontext.Context, process HcsProcess, options string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsSignalProcess") + ctx, span := otelutil.StartSpan(ctx, "HcsSignalProcess", trace.WithAttributes( + attribute.String("options", options))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - span.AddAttributes(trace.StringAttribute("options", options)) return result, execute(ctx, timeout.SyscallWatcher, func() error { var resultp *uint16 @@ -501,13 +501,13 @@ func HcsSignalProcess(ctx gcontext.Context, process HcsProcess, options string) } func HcsGetProcessInfo(ctx gcontext.Context, process HcsProcess) (processInformation HcsProcessInformation, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsGetProcessInfo") + ctx, span := otelutil.StartSpan(ctx, "HcsGetProcessInfo") defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() return processInformation, result, execute(ctx, timeout.SyscallWatcher, func() error { @@ -521,13 +521,13 @@ func HcsGetProcessInfo(ctx gcontext.Context, process HcsProcess) (processInforma } func HcsGetProcessProperties(ctx gcontext.Context, process HcsProcess) (processProperties, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsGetProcessProperties") + ctx, span := otelutil.StartSpan(ctx, "HcsGetProcessProperties") defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() return processProperties, result, execute(ctx, timeout.SyscallWatcher, func() error { @@ -547,15 +547,15 @@ func HcsGetProcessProperties(ctx gcontext.Context, process HcsProcess) (processP } func HcsModifyProcess(ctx gcontext.Context, process HcsProcess, settings string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsModifyProcess") + ctx, span := otelutil.StartSpan(ctx, "HcsModifyProcess", trace.WithAttributes( + attribute.String("settings", settings))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - span.AddAttributes(trace.StringAttribute("settings", settings)) return result, execute(ctx, timeout.SyscallWatcher, func() error { var resultp *uint16 @@ -568,15 +568,15 @@ func HcsModifyProcess(ctx gcontext.Context, process HcsProcess, settings string) } func HcsGetServiceProperties(ctx gcontext.Context, propertyQuery string) (properties, result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsGetServiceProperties") + ctx, span := otelutil.StartSpan(ctx, "HcsGetServiceProperties", trace.WithAttributes( + attribute.String("propertyQuery", propertyQuery))) defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) }() - span.AddAttributes(trace.StringAttribute("propertyQuery", propertyQuery)) return properties, result, execute(ctx, timeout.SyscallWatcher, func() error { var ( @@ -595,9 +595,9 @@ func HcsGetServiceProperties(ctx gcontext.Context, propertyQuery string) (proper } func HcsRegisterProcessCallback(ctx gcontext.Context, process HcsProcess, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsRegisterProcessCallback") + ctx, span := otelutil.StartSpan(ctx, "HcsRegisterProcessCallback") defer span.End() - defer func() { oc.SetSpanStatus(span, hr) }() + defer func() { otelutil.SetSpanStatus(span, hr) }() return callbackHandle, execute(ctx, timeout.SyscallWatcher, func() error { return hcsRegisterProcessCallback(process, callback, context, &callbackHandle) @@ -605,9 +605,9 @@ func HcsRegisterProcessCallback(ctx gcontext.Context, process HcsProcess, callba } func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) { - ctx, span := oc.StartSpan(ctx, "HcsUnregisterProcessCallback") + ctx, span := otelutil.StartSpan(ctx, "HcsUnregisterProcessCallback") defer span.End() - defer func() { oc.SetSpanStatus(span, hr) }() + defer func() { otelutil.SetSpanStatus(span, hr) }() return execute(ctx, timeout.SyscallWatcher, func() error { return hcsUnregisterProcessCallback(callbackHandle) @@ -615,14 +615,14 @@ func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallba } func HcsSaveComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) { - ctx, span := oc.StartSpan(ctx, "HcsSaveComputeSystem") + ctx, span := otelutil.StartSpan(ctx, "HcsSaveComputeSystem") defer span.End() defer func() { if result != "" { - span.AddAttributes(trace.StringAttribute("result", result)) + span.SetAttributes(attribute.String("result", result)) } if hr != errVmcomputeOperationPending { //nolint:errorlint // explicitly returned - oc.SetSpanStatus(span, hr) + otelutil.SetSpanStatus(span, hr) } }() diff --git a/internal/wclayer/activatelayer.go b/internal/wclayer/activatelayer.go index e12253c947..bc8e09afdd 100644 --- a/internal/wclayer/activatelayer.go +++ b/internal/wclayer/activatelayer.go @@ -6,8 +6,9 @@ import ( "context" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // ActivateLayer will find the layer with the given id and mount it's filesystem. @@ -16,10 +17,10 @@ import ( // An activated layer must later be deactivated via DeactivateLayer. func ActivateLayer(ctx context.Context, path string) (err error) { title := "hcsshim::ActivateLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = activateLayer(&stdDriverInfo, path) if err != nil { diff --git a/internal/wclayer/baselayerreader.go b/internal/wclayer/baselayerreader.go index 807b7de1fb..fe84809f61 100644 --- a/internal/wclayer/baselayerreader.go +++ b/internal/wclayer/baselayerreader.go @@ -12,12 +12,12 @@ import ( "github.com/Microsoft/go-winio" "github.com/Microsoft/hcsshim/internal/longpath" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/trace" ) type baseLayerReader struct { - s *trace.Span + s trace.Span root string result chan *fileEntry proceed chan bool @@ -25,7 +25,7 @@ type baseLayerReader struct { backupReader *winio.BackupFileReader } -func newBaseLayerReader(root string, s *trace.Span) (r *baseLayerReader) { +func newBaseLayerReader(root string, s trace.Span) (r *baseLayerReader) { r = &baseLayerReader{ s: s, root: root, @@ -207,7 +207,7 @@ func (r *baseLayerReader) Read(b []byte) (int, error) { func (r *baseLayerReader) Close() (err error) { defer r.s.End() defer func() { - oc.SetSpanStatus(r.s, err) + otelutil.SetSpanStatus(r.s, err) close(r.proceed) }() r.proceed <- false diff --git a/internal/wclayer/baselayerwriter.go b/internal/wclayer/baselayerwriter.go index aea8b421ef..ff83dfa40b 100644 --- a/internal/wclayer/baselayerwriter.go +++ b/internal/wclayer/baselayerwriter.go @@ -11,15 +11,15 @@ import ( "github.com/Microsoft/go-winio" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/safefile" "github.com/Microsoft/hcsshim/internal/winapi" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/trace" ) type baseLayerWriter struct { ctx context.Context - s *trace.Span + s trace.Span root *os.File f *os.File @@ -145,7 +145,7 @@ func (w *baseLayerWriter) Write(b []byte) (int, error) { func (w *baseLayerWriter) Close() (err error) { defer w.s.End() - defer func() { oc.SetSpanStatus(w.s, err) }() + defer func() { otelutil.SetSpanStatus(w.s, err) }() defer func() { w.root.Close() w.root = nil diff --git a/internal/wclayer/cim/LayerWriter.go b/internal/wclayer/cim/LayerWriter.go index 9315971b64..23b8354038 100644 --- a/internal/wclayer/cim/LayerWriter.go +++ b/internal/wclayer/cim/LayerWriter.go @@ -10,10 +10,11 @@ import ( "strings" "github.com/Microsoft/go-winio" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/wclayer" "github.com/Microsoft/hcsshim/pkg/cimfs" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // A CimLayerWriter implements the wclayer.LayerWriter interface to allow writing container @@ -22,7 +23,7 @@ import ( // some other files which are stored in the directory of that layer (i.e the `path` directory). type CimLayerWriter struct { ctx context.Context - s *trace.Span + s trace.Span // path to the layer (i.e layer's directory) as provided by the caller. // Even if a layer is stored as a cim in the cim directory, some files associated // with a layer are still stored in this path. @@ -196,18 +197,17 @@ func NewCimLayerWriter(ctx context.Context, layerPath, cimPath string, parentLay return nil, fmt.Errorf("CimFs not supported on this build") } - ctx, span := trace.StartSpan(ctx, "hcsshim::NewCimLayerWriter") + ctx, span := otelutil.StartSpan(ctx, "hcsshim::NewCimLayerWriter", trace.WithAttributes( + attribute.String("path", layerPath), + attribute.String("cimPath", cimPath), + attribute.String("parentLayerPaths", strings.Join(parentLayerCimPaths, ", ")), + attribute.String("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))) defer func() { if err != nil { - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) span.End() } }() - span.AddAttributes( - trace.StringAttribute("path", layerPath), - trace.StringAttribute("cimPath", cimPath), - trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerCimPaths, ", ")), - trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", "))) parentCim := "" if len(parentLayerPaths) > 0 { diff --git a/internal/wclayer/converttobaselayer.go b/internal/wclayer/converttobaselayer.go index d25c3c5206..7c77f8313d 100644 --- a/internal/wclayer/converttobaselayer.go +++ b/internal/wclayer/converttobaselayer.go @@ -10,11 +10,12 @@ import ( "github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/longpath" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/safefile" "github.com/Microsoft/hcsshim/internal/winapi" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sys/windows" ) @@ -137,10 +138,10 @@ func convertToBaseLayer(ctx context.Context, root *os.File) error { // desired file content for a UtilityVM under UtilityVM/Files/ func ConvertToBaseLayer(ctx context.Context, path string) (err error) { title := "hcsshim::ConvertToBaseLayer" - ctx, span := trace.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() root, err := safefile.OpenRoot(path) if err != nil { diff --git a/internal/wclayer/createlayer.go b/internal/wclayer/createlayer.go index 932475723a..fa366d7df6 100644 --- a/internal/wclayer/createlayer.go +++ b/internal/wclayer/createlayer.go @@ -6,20 +6,20 @@ import ( "context" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // CreateLayer creates a new, empty, read-only layer on the filesystem based on // the parent layer provided. func CreateLayer(ctx context.Context, path, parent string) (err error) { title := "hcsshim::CreateLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path), + attribute.String("parent", parent))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("path", path), - trace.StringAttribute("parent", parent)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = createLayer(&stdDriverInfo, path, parent) if err != nil { diff --git a/internal/wclayer/createscratchlayer.go b/internal/wclayer/createscratchlayer.go index 5c9d5d2507..10d614ee64 100644 --- a/internal/wclayer/createscratchlayer.go +++ b/internal/wclayer/createscratchlayer.go @@ -7,20 +7,20 @@ import ( "strings" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // CreateScratchLayer creates and populates new read-write layer for use by a container. // This requires the full list of paths to all parent layers up to the base func CreateScratchLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) { title := "hcsshim::CreateScratchLayer" - ctx, span := oc.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path), + attribute.String("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("path", path), - trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", "))) + defer func() { otelutil.SetSpanStatus(span, err) }() // Generate layer descriptors layers, err := layerPathsToDescriptors(ctx, parentLayerPaths) diff --git a/internal/wclayer/deactivatelayer.go b/internal/wclayer/deactivatelayer.go index e3bc77cbc8..77da5fbfe9 100644 --- a/internal/wclayer/deactivatelayer.go +++ b/internal/wclayer/deactivatelayer.go @@ -6,17 +6,18 @@ import ( "context" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // DeactivateLayer will dismount a layer that was mounted via ActivateLayer. func DeactivateLayer(ctx context.Context, path string) (err error) { title := "hcsshim::DeactivateLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = deactivateLayer(&stdDriverInfo, path) if err != nil { diff --git a/internal/wclayer/destroylayer.go b/internal/wclayer/destroylayer.go index d0a59efe12..bc81d52661 100644 --- a/internal/wclayer/destroylayer.go +++ b/internal/wclayer/destroylayer.go @@ -6,18 +6,19 @@ import ( "context" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // DestroyLayer will remove the on-disk files representing the layer with the given // path, including that layer's containing folder, if any. func DestroyLayer(ctx context.Context, path string) (err error) { title := "hcsshim::DestroyLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = destroyLayer(&stdDriverInfo, path) if err != nil { diff --git a/internal/wclayer/expandscratchsize.go b/internal/wclayer/expandscratchsize.go index 35fcbedb3c..51cd6e52a7 100644 --- a/internal/wclayer/expandscratchsize.go +++ b/internal/wclayer/expandscratchsize.go @@ -10,19 +10,19 @@ import ( "unsafe" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // ExpandScratchSize expands the size of a layer to at least size bytes. func ExpandScratchSize(ctx context.Context, path string, size uint64) (err error) { title := "hcsshim::ExpandScratchSize" - ctx, span := oc.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path), + attribute.Int64("size", int64(size)))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("path", path), - trace.Int64Attribute("size", int64(size))) + defer func() { otelutil.SetSpanStatus(span, err) }() err = expandSandboxSize(&stdDriverInfo, path, size) if err != nil { diff --git a/internal/wclayer/exportlayer.go b/internal/wclayer/exportlayer.go index d4c677aabf..f1dc49cd6c 100644 --- a/internal/wclayer/exportlayer.go +++ b/internal/wclayer/exportlayer.go @@ -9,8 +9,9 @@ import ( "github.com/Microsoft/go-winio" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // ExportLayer will create a folder at exportFolderPath and fill that folder with @@ -20,13 +21,12 @@ import ( // perform the export. func ExportLayer(ctx context.Context, path string, exportFolderPath string, parentLayerPaths []string) (err error) { title := "hcsshim::ExportLayer" - ctx, span := oc.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path), + attribute.String("exportFolderPath", exportFolderPath), + attribute.String("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("path", path), - trace.StringAttribute("exportFolderPath", exportFolderPath), - trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", "))) + defer func() { otelutil.SetSpanStatus(span, err) }() // Generate layer descriptors layers, err := layerPathsToDescriptors(ctx, parentLayerPaths) @@ -58,16 +58,15 @@ type LayerReader interface { // The caller must have taken the SeBackupPrivilege privilege // to call this and any methods on the resulting LayerReader. func NewLayerReader(ctx context.Context, path string, parentLayerPaths []string) (_ LayerReader, err error) { - ctx, span := oc.StartSpan(ctx, "hcsshim::NewLayerReader") + ctx, span := otelutil.StartSpan(ctx, "hcsshim::NewLayerReader", trace.WithAttributes( + attribute.String("path", path), + attribute.String("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))) defer func() { if err != nil { - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) span.End() } }() - span.AddAttributes( - trace.StringAttribute("path", path), - trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", "))) if len(parentLayerPaths) == 0 { // This is a base layer. It gets exported differently. @@ -92,14 +91,14 @@ func NewLayerReader(ctx context.Context, path string, parentLayerPaths []string) type legacyLayerReaderWrapper struct { ctx context.Context - s *trace.Span + s trace.Span *legacyLayerReader } func (r *legacyLayerReaderWrapper) Close() (err error) { defer r.s.End() - defer func() { oc.SetSpanStatus(r.s, err) }() + defer func() { otelutil.SetSpanStatus(r.s, err) }() err = r.legacyLayerReader.Close() os.RemoveAll(r.root) diff --git a/internal/wclayer/getlayermountpath.go b/internal/wclayer/getlayermountpath.go index 715e06e379..f6153f8e93 100644 --- a/internal/wclayer/getlayermountpath.go +++ b/internal/wclayer/getlayermountpath.go @@ -8,8 +8,9 @@ import ( "github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // GetLayerMountPath will look for a mounted layer with the given path and return @@ -18,10 +19,10 @@ import ( // folder path at which the layer is stored. func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) { title := "hcsshim::GetLayerMountPath" - ctx, span := oc.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() var mountPathLength uintptr = 0 @@ -47,6 +48,6 @@ func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) { } mountPath := syscall.UTF16ToString(mountPathp[0:]) - span.AddAttributes(trace.StringAttribute("mountPath", mountPath)) + span.SetAttributes(attribute.String("mountPath", mountPath)) return mountPath, nil } diff --git a/internal/wclayer/getsharedbaseimages.go b/internal/wclayer/getsharedbaseimages.go index 5e400fb209..0efea5aedf 100644 --- a/internal/wclayer/getsharedbaseimages.go +++ b/internal/wclayer/getsharedbaseimages.go @@ -7,8 +7,8 @@ import ( "github.com/Microsoft/hcsshim/internal/hcserror" "github.com/Microsoft/hcsshim/internal/interop" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" ) // GetSharedBaseImages will enumerate the images stored in the common central @@ -16,9 +16,9 @@ import ( // of registering them with the graphdriver, graph, and tagstore. func GetSharedBaseImages(ctx context.Context) (_ string, err error) { title := "hcsshim::GetSharedBaseImages" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() + defer func() { otelutil.SetSpanStatus(span, err) }() var buffer *uint16 err = getBaseImages(&buffer) @@ -26,6 +26,6 @@ func GetSharedBaseImages(ctx context.Context) (_ string, err error) { return "", hcserror.New(err, title, "") } imageData := interop.ConvertAndFreeCoTaskMemString(buffer) - span.AddAttributes(trace.StringAttribute("imageData", imageData)) + span.SetAttributes(attribute.String("imageData", imageData)) return imageData, nil } diff --git a/internal/wclayer/grantvmaccess.go b/internal/wclayer/grantvmaccess.go index 20217ed81b..cc3a91bd13 100644 --- a/internal/wclayer/grantvmaccess.go +++ b/internal/wclayer/grantvmaccess.go @@ -6,19 +6,19 @@ import ( "context" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // GrantVmAccess adds access to a file for a given VM func GrantVmAccess(ctx context.Context, vmid string, filepath string) (err error) { title := "hcsshim::GrantVmAccess" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("vm-id", vmid), + attribute.String("path", filepath))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("vm-id", vmid), - trace.StringAttribute("path", filepath)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = grantVmAccess(vmid, filepath) if err != nil { diff --git a/internal/wclayer/importlayer.go b/internal/wclayer/importlayer.go index 50f669a261..a87229b84d 100644 --- a/internal/wclayer/importlayer.go +++ b/internal/wclayer/importlayer.go @@ -10,9 +10,10 @@ import ( "github.com/Microsoft/go-winio" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/safefile" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // ImportLayer will take the contents of the folder at importFolderPath and import @@ -21,13 +22,12 @@ import ( // be present on the system at the paths provided in parentLayerPaths. func ImportLayer(ctx context.Context, path string, importFolderPath string, parentLayerPaths []string) (err error) { title := "hcsshim::ImportLayer" - ctx, span := oc.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path), + attribute.String("importFolderPath", importFolderPath), + attribute.String("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("path", path), - trace.StringAttribute("importFolderPath", importFolderPath), - trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", "))) + defer func() { otelutil.SetSpanStatus(span, err) }() // Generate layer descriptors layers, err := layerPathsToDescriptors(ctx, parentLayerPaths) @@ -59,7 +59,7 @@ type LayerWriter interface { type legacyLayerWriterWrapper struct { ctx context.Context - s *trace.Span + s trace.Span *legacyLayerWriter path string @@ -68,7 +68,7 @@ type legacyLayerWriterWrapper struct { func (r *legacyLayerWriterWrapper) Close() (err error) { defer r.s.End() - defer func() { oc.SetSpanStatus(r.s, err) }() + defer func() { otelutil.SetSpanStatus(r.s, err) }() defer os.RemoveAll(r.root.Name()) defer r.legacyLayerWriter.CloseRoots() @@ -125,16 +125,15 @@ func (r *legacyLayerWriterWrapper) Close() (err error) { // The caller must have taken the SeBackupPrivilege and SeRestorePrivilege privileges // to call this and any methods on the resulting LayerWriter. func NewLayerWriter(ctx context.Context, path string, parentLayerPaths []string) (_ LayerWriter, err error) { - ctx, span := oc.StartSpan(ctx, "hcsshim::NewLayerWriter") + ctx, span := otelutil.StartSpan(ctx, "hcsshim::NewLayerWriter", trace.WithAttributes( + attribute.String("path", path), + attribute.String("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))) defer func() { if err != nil { - oc.SetSpanStatus(span, err) + otelutil.SetSpanStatus(span, err) span.End() } }() - span.AddAttributes( - trace.StringAttribute("path", path), - trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", "))) if len(parentLayerPaths) == 0 { // This is a base layer. It gets imported differently. diff --git a/internal/wclayer/layerexists.go b/internal/wclayer/layerexists.go index 4d82977ea1..dd65c75fe9 100644 --- a/internal/wclayer/layerexists.go +++ b/internal/wclayer/layerexists.go @@ -6,18 +6,19 @@ import ( "context" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // LayerExists will return true if a layer with the given id exists and is known // to the system. func LayerExists(ctx context.Context, path string) (_ bool, err error) { title := "hcsshim::LayerExists" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() // Call the procedure itself. var exists uint32 @@ -25,6 +26,6 @@ func LayerExists(ctx context.Context, path string) (_ bool, err error) { if err != nil { return false, hcserror.New(err, title, "") } - span.AddAttributes(trace.BoolAttribute("layer-exists", exists != 0)) + span.SetAttributes(attribute.Bool("layer-exists", exists != 0)) return exists != 0, nil } diff --git a/internal/wclayer/layerid.go b/internal/wclayer/layerid.go index d4805f1444..4eafe19a47 100644 --- a/internal/wclayer/layerid.go +++ b/internal/wclayer/layerid.go @@ -7,17 +7,18 @@ import ( "path/filepath" "github.com/Microsoft/go-winio/pkg/guid" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // LayerID returns the layer ID of a layer on disk. func LayerID(ctx context.Context, path string) (_ guid.GUID, err error) { title := "hcsshim::LayerID" - ctx, span := oc.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() _, file := filepath.Split(path) return NameToGuid(ctx, file) diff --git a/internal/wclayer/nametoguid.go b/internal/wclayer/nametoguid.go index c45fa2750c..f7094b5d3b 100644 --- a/internal/wclayer/nametoguid.go +++ b/internal/wclayer/nametoguid.go @@ -7,8 +7,9 @@ import ( "github.com/Microsoft/go-winio/pkg/guid" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // NameToGuid converts the given string into a GUID using the algorithm in the @@ -16,16 +17,16 @@ import ( // across all clients. func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) { title := "hcsshim::NameToGuid" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("objectName", name))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("objectName", name)) + defer func() { otelutil.SetSpanStatus(span, err) }() var id guid.GUID err = nameToGuid(name, &id) if err != nil { return guid.GUID{}, hcserror.New(err, title, "") } - span.AddAttributes(trace.StringAttribute("guid", id.String())) + span.SetAttributes(attribute.String("guid", id.String())) return id, nil } diff --git a/internal/wclayer/preparelayer.go b/internal/wclayer/preparelayer.go index b66e071245..b252a3d5a5 100644 --- a/internal/wclayer/preparelayer.go +++ b/internal/wclayer/preparelayer.go @@ -8,8 +8,9 @@ import ( "sync" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) var prepareLayerLock sync.Mutex @@ -21,12 +22,11 @@ var prepareLayerLock sync.Mutex // Disabling the filter must be done via UnprepareLayer. func PrepareLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) { title := "hcsshim::PrepareLayer" - ctx, span := oc.StartSpan(ctx, title) + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path), + attribute.String("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))) defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes( - trace.StringAttribute("path", path), - trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", "))) + defer func() { otelutil.SetSpanStatus(span, err) }() // Generate layer descriptors layers, err := layerPathsToDescriptors(ctx, parentLayerPaths) diff --git a/internal/wclayer/processimage.go b/internal/wclayer/processimage.go index 7c49cbda45..1109f24723 100644 --- a/internal/wclayer/processimage.go +++ b/internal/wclayer/processimage.go @@ -6,18 +6,19 @@ import ( "context" "os" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // ProcessBaseLayer post-processes a base layer that has had its files extracted. // The files should have been extracted to \Files. func ProcessBaseLayer(ctx context.Context, path string) (err error) { title := "hcsshim::ProcessBaseLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = processBaseImage(path) if err != nil { @@ -30,10 +31,10 @@ func ProcessBaseLayer(ctx context.Context, path string) (err error) { // The files should have been extracted to \Files. func ProcessUtilityVMImage(ctx context.Context, path string) (err error) { title := "hcsshim::ProcessUtilityVMImage" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = processUtilityImage(path) if err != nil { diff --git a/internal/wclayer/unpreparelayer.go b/internal/wclayer/unpreparelayer.go index fe20702c18..26d4b454d1 100644 --- a/internal/wclayer/unpreparelayer.go +++ b/internal/wclayer/unpreparelayer.go @@ -6,18 +6,19 @@ import ( "context" "github.com/Microsoft/hcsshim/internal/hcserror" - "github.com/Microsoft/hcsshim/internal/oc" - "go.opencensus.io/trace" + "github.com/Microsoft/hcsshim/internal/otelutil" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // UnprepareLayer disables the filesystem filter for the read-write layer with // the given id. func UnprepareLayer(ctx context.Context, path string) (err error) { title := "hcsshim::UnprepareLayer" - ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck + ctx, span := otelutil.StartSpan(ctx, title, trace.WithAttributes( + attribute.String("path", path))) //nolint:ineffassign,staticcheck defer span.End() - defer func() { oc.SetSpanStatus(span, err) }() - span.AddAttributes(trace.StringAttribute("path", path)) + defer func() { otelutil.SetSpanStatus(span, err) }() err = unprepareLayer(&stdDriverInfo, path) if err != nil { diff --git a/pkg/octtrpc/interceptor.go b/pkg/octtrpc/interceptor.go deleted file mode 100644 index 673b29b5a6..0000000000 --- a/pkg/octtrpc/interceptor.go +++ /dev/null @@ -1,117 +0,0 @@ -package octtrpc - -import ( - "context" - "encoding/base64" - "strings" - - "github.com/containerd/ttrpc" - "go.opencensus.io/trace" - "go.opencensus.io/trace/propagation" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - "github.com/Microsoft/hcsshim/internal/oc" -) - -type options struct { - sampler trace.Sampler -} - -// Option represents an option function that can be used with the OC TTRPC -// interceptors. -type Option func(*options) - -// WithSampler returns an option function to set the OC sampler used for the -// auto-created spans. -func WithSampler(sampler trace.Sampler) Option { - return func(opts *options) { - opts.sampler = sampler - } -} - -const metadataTraceContextKey = "octtrpc.tracecontext" - -func convertMethodName(name string) string { - name = strings.TrimPrefix(name, "/") - name = strings.Replace(name, "/", ".", -1) - return name -} - -func getParentSpanFromContext(ctx context.Context) (trace.SpanContext, bool) { - md, _ := ttrpc.GetMetadata(ctx) - traceContext := md[metadataTraceContextKey] - if len(traceContext) > 0 { - traceContextBinary, _ := base64.StdEncoding.DecodeString(traceContext[0]) - return propagation.FromBinary(traceContextBinary) - } - return trace.SpanContext{}, false -} - -func setSpanStatus(span *trace.Span, err error) { - // This error handling matches that used in ocgrpc. - if err != nil { - s, ok := status.FromError(err) - if ok { - span.SetStatus(trace.Status{Code: int32(s.Code()), Message: s.Message()}) - } else { - span.SetStatus(trace.Status{Code: int32(codes.Internal), Message: err.Error()}) - } - } -} - -// ClientInterceptor returns a TTRPC unary client interceptor that automatically -// creates a new span for outgoing TTRPC calls, and passes the span context as -// metadata on the call. -func ClientInterceptor(opts ...Option) ttrpc.UnaryClientInterceptor { - o := options{ - sampler: oc.DefaultSampler, - } - for _, opt := range opts { - opt(&o) - } - return func(ctx context.Context, req *ttrpc.Request, resp *ttrpc.Response, info *ttrpc.UnaryClientInfo, inv ttrpc.Invoker) (err error) { - ctx, span := oc.StartSpan( - ctx, - convertMethodName(info.FullMethod), - trace.WithSampler(o.sampler), - oc.WithClientSpanKind) - defer span.End() - defer setSpanStatus(span, err) - - spanContextBinary := propagation.Binary(span.SpanContext()) - b64 := base64.StdEncoding.EncodeToString(spanContextBinary) - kvp := &ttrpc.KeyValue{Key: metadataTraceContextKey, Value: b64} - req.Metadata = append(req.Metadata, kvp) - - return inv(ctx, req, resp) - } -} - -// ServerInterceptor returns a TTRPC unary server interceptor that automatically -// creates a new span for incoming TTRPC calls, and parents the span to the -// span context received via metadata, if it exists. -func ServerInterceptor(opts ...Option) ttrpc.UnaryServerInterceptor { - o := options{ - sampler: oc.DefaultSampler, - } - for _, opt := range opts { - opt(&o) - } - return func(ctx context.Context, unmarshal ttrpc.Unmarshaler, info *ttrpc.UnaryServerInfo, method ttrpc.Method) (_ interface{}, err error) { - name := convertMethodName(info.FullMethod) - - var span *trace.Span - opts := []trace.StartOption{trace.WithSampler(o.sampler), oc.WithServerSpanKind} - parent, ok := getParentSpanFromContext(ctx) - if ok { - ctx, span = oc.StartSpanWithRemoteParent(ctx, name, parent, opts...) - } else { - ctx, span = oc.StartSpan(ctx, name, opts...) - } - defer span.End() - defer setSpanStatus(span, err) - - return method(ctx, unmarshal) - } -} diff --git a/pkg/otelttrpc/interceptor.go b/pkg/otelttrpc/interceptor.go new file mode 100644 index 0000000000..fa28d00dbd --- /dev/null +++ b/pkg/otelttrpc/interceptor.go @@ -0,0 +1,95 @@ +package otelttrpc + +import ( + "context" + "strings" + + "github.com/containerd/ttrpc" + "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" + grpccodes "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/Microsoft/hcsshim/internal/otelutil" +) + +const ( + metadataTraceContextKey = "otelttrpc.tracecontext" + metadataTraceParent = metadataTraceContextKey + ".traceparent" + metadataTraceState = metadataTraceContextKey + ".tracestate" +) + +var propagator = propagation.TraceContext{} + +func convertMethodName(name string) string { + name = strings.TrimPrefix(name, "/") + name = strings.Replace(name, "/", ".", -1) + return name +} + +func extractParentSpan(ctx context.Context) context.Context { + var traceParent string + var traceState string + + md, _ := ttrpc.GetMetadata(ctx) + if tp, ok := md[metadataTraceContextKey]; ok && len(tp) > 0 { + traceParent = tp[0] + } + if ts, ok := md[metadataTraceState]; ok && len(ts) > 0 { + traceState = ts[0] + } + + return propagator.Extract(ctx, propagation.MapCarrier{ + "traceparent": traceParent, + "tracestate": traceState, + }) +} + +func setSpanStatus(span trace.Span, err error) { + // This error handling matches that used in ocgrpc. + if err != nil { + s, ok := status.FromError(err) + if ok { + span.SetStatus(codes.Code(s.Code()), s.Message()) + } else { + span.SetStatus(codes.Code(grpccodes.Internal), err.Error()) + } + } +} + +// ClientInterceptor returns a TTRPC unary client interceptor that automatically +// creates a new span for outgoing TTRPC calls, and passes the span context as +// metadata on the call. +func ClientInterceptor() ttrpc.UnaryClientInterceptor { + return func(ctx context.Context, req *ttrpc.Request, resp *ttrpc.Response, info *ttrpc.UnaryClientInfo, inv ttrpc.Invoker) (err error) { + ctx, span := otelutil.StartSpan(ctx, convertMethodName(info.FullMethod), otelutil.WithClientSpanKind) + defer span.End() + defer setSpanStatus(span, err) + + carrier := propagation.MapCarrier{} + propagator.Inject(ctx, carrier) + + req.Metadata = append(req.Metadata, + &ttrpc.KeyValue{Key: metadataTraceParent, Value: carrier.Get("traceparent")}, + &ttrpc.KeyValue{Key: metadataTraceState, Value: carrier.Get("tracestate")}, + ) + + return inv(ctx, req, resp) + } +} + +// ServerInterceptor returns a TTRPC unary server interceptor that automatically +// creates a new span for incoming TTRPC calls, and parents the span to the +// span context received via metadata, if it exists. +func ServerInterceptor() ttrpc.UnaryServerInterceptor { + return func(ctx context.Context, unmarshal ttrpc.Unmarshaler, info *ttrpc.UnaryServerInfo, method ttrpc.Method) (_ interface{}, err error) { + name := convertMethodName(info.FullMethod) + + ctx, span := otelutil.StartSpan(extractParentSpan(ctx), name, otelutil.WithServerSpanKind) + defer span.End() + defer setSpanStatus(span, err) + + return method(ctx, unmarshal) + } +} diff --git a/test/functional/main_test.go b/test/functional/main_test.go index 0dd7f478cb..6b69ed29e7 100644 --- a/test/functional/main_test.go +++ b/test/functional/main_test.go @@ -23,11 +23,12 @@ import ( "github.com/containerd/containerd/namespaces" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel" + sdktrace "go.opentelemetry.io/otel/sdk/trace" "github.com/Microsoft/hcsshim/internal/layers" "github.com/Microsoft/hcsshim/internal/log" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/sync" "github.com/Microsoft/hcsshim/internal/uvm" "github.com/Microsoft/hcsshim/internal/winapi" @@ -161,8 +162,10 @@ func runTests(m *testing.M) error { return fmt.Errorf("tests must be run in an elevated context") } - trace.ApplyConfig(trace.Config{DefaultSampler: oc.DefaultSampler}) - trace.RegisterExporter(&oc.LogrusExporter{}) + otel.SetTracerProvider(sdktrace.NewTracerProvider( + sdktrace.WithSampler(otelutil.DefaultSampler), + sdktrace.WithBatcher(&otelutil.LogrusExporter{}), + )) // default is stderr, but test2json does not consume stderr, so logs would be out of sync // and powershell considers output on stderr as an error when execing diff --git a/test/gcs/main_test.go b/test/gcs/main_test.go index f4b32b34c8..78608435ea 100644 --- a/test/gcs/main_test.go +++ b/test/gcs/main_test.go @@ -13,7 +13,8 @@ import ( cgroups "github.com/containerd/cgroups/v3/cgroup1" "github.com/sirupsen/logrus" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel" + sdktrace "go.opentelemetry.io/otel/sdk/trace" "golang.org/x/sys/unix" "github.com/Microsoft/hcsshim/internal/guest/runtime" @@ -21,7 +22,7 @@ import ( "github.com/Microsoft/hcsshim/internal/guest/runtime/runc" "github.com/Microsoft/hcsshim/internal/guest/transport" "github.com/Microsoft/hcsshim/internal/guestpath" - "github.com/Microsoft/hcsshim/internal/oc" + "github.com/Microsoft/hcsshim/internal/otelutil" "github.com/Microsoft/hcsshim/internal/protocol/guestresource" "github.com/Microsoft/hcsshim/pkg/securitypolicy" @@ -110,8 +111,10 @@ func TestMain(m *testing.M) { func setup() (err error) { _ = os.MkdirAll(guestpath.LCOWRootPrefixInUVM, 0755) - trace.ApplyConfig(trace.Config{DefaultSampler: oc.DefaultSampler}) - trace.RegisterExporter(&oc.LogrusExporter{}) + otel.SetTracerProvider(sdktrace.NewTracerProvider( + sdktrace.WithSampler(otelutil.DefaultSampler), + sdktrace.WithBatcher(&otelutil.LogrusExporter{}), + )) logrus.SetLevel(flagLogLevel.Level) // test2json does not consume stderr diff --git a/test/go.mod b/test/go.mod index 2860a0c4f7..dc5a29126a 100644 --- a/test/go.mod +++ b/test/go.mod @@ -19,7 +19,8 @@ require ( github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 github.com/urfave/cli/v2 v2.27.1 - go.opencensus.io v0.24.0 + go.opentelemetry.io/otel v1.21.0 + go.opentelemetry.io/otel/sdk v1.21.0 golang.org/x/sync v0.7.0 golang.org/x/sys v0.20.0 google.golang.org/grpc v1.63.2 @@ -63,7 +64,6 @@ require ( github.com/goccy/go-json v0.10.2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/mux v1.8.1 // indirect @@ -105,9 +105,7 @@ require ( github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/yashtewari/glob-intersection v0.2.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect - go.opentelemetry.io/otel v1.21.0 // indirect go.opentelemetry.io/otel/metric v1.21.0 // indirect - go.opentelemetry.io/otel/sdk v1.21.0 // indirect go.opentelemetry.io/otel/trace v1.21.0 // indirect golang.org/x/crypto v0.22.0 // indirect golang.org/x/mod v0.14.0 // indirect diff --git a/test/go.sum b/test/go.sum index cfc592e023..8c83f1a56f 100644 --- a/test/go.sum +++ b/test/go.sum @@ -1,9 +1,7 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 h1:59MxjQVfjXsBpLy+dbd2/ELV5ofnUkUZBvWSC85sheA= github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0/go.mod h1:OahwfttHWG6eJ0clwcfBAHoDI6X/LV/15hx/wlMZSrU= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Microsoft/cosesign1go v1.1.0 h1:JnHY2wQkIK4HmstaK5rMdM4S83nIC7fJmD1phOLj9qo= github.com/Microsoft/cosesign1go v1.1.0/go.mod h1:o+sw7nhlGE6twhfjXQDWmBJO8zmfQXEmCcXEi3zha8I= @@ -28,12 +26,12 @@ github.com/bytecodealliance/wasmtime-go/v3 v3.0.2/go.mod h1:RnUjnIXxEJcL6BgCvNyz github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0= github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0= github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw= @@ -89,10 +87,6 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4 github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= @@ -119,22 +113,10 @@ github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= @@ -142,19 +124,12 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/flatbuffers v1.12.1 h1:MVlul7pQNoDzWRLTw5imwYsl+usrS1TXG2H4jg6ImGw= github.com/google/flatbuffers v1.12.1/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-containerregistry v0.19.1 h1:yMQ62Al6/V0Z7CqIrrS1iYoA5/oQCm88DeNujc7C1KY= github.com/google/go-containerregistry v0.19.1/go.mod h1:YCMFNQeeXeLF+dnhhWkqDItx/JSkH01j1Kis4PsjzFI= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -240,6 +215,8 @@ github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdU github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= @@ -338,15 +315,10 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= @@ -357,6 +329,8 @@ golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -364,7 +338,6 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -401,10 +374,6 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= @@ -416,33 +385,14 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0= google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY= google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= @@ -457,8 +407,6 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= k8s.io/cri-api v0.27.1 h1:KWO+U8MfI9drXB/P4oU9VchaWYOlwDglJZVHWMpTT3Q= k8s.io/cri-api v0.27.1/go.mod h1:+Ts/AVYbIo04S86XbTD73UPp/DkTiYxtsFeOFEu32L0= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= diff --git a/vendor/github.com/golang/groupcache/LICENSE b/vendor/github.com/golang/groupcache/LICENSE deleted file mode 100644 index 37ec93a14f..0000000000 --- a/vendor/github.com/golang/groupcache/LICENSE +++ /dev/null @@ -1,191 +0,0 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and -distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities -that control, are controlled by, or are under common control with that entity. -For the purposes of this definition, "control" means (i) the power, direct or -indirect, to cause the direction or management of such entity, whether by -contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the -outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising -permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. - -"Object" form shall mean any form resulting from mechanical transformation or -translation of a Source form, including but not limited to compiled object code, -generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made -available under the License, as indicated by a copyright notice that is included -in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that -is based on (or derived from) the Work and for which the editorial revisions, -annotations, elaborations, or other modifications represent, as a whole, an -original work of authorship. For the purposes of this License, Derivative Works -shall not include works that remain separable from, or merely link (or bind by -name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version -of the Work and any modifications or additions to that Work or Derivative Works -thereof, that is intentionally submitted to Licensor for inclusion in the Work -by the copyright owner or by an individual or Legal Entity authorized to submit -on behalf of the copyright owner. For the purposes of this definition, -"submitted" means any form of electronic, verbal, or written communication sent -to the Licensor or its representatives, including but not limited to -communication on electronic mailing lists, source code control systems, and -issue tracking systems that are managed by, or on behalf of, the Licensor for -the purpose of discussing and improving the Work, but excluding communication -that is conspicuously marked or otherwise designated in writing by the copyright -owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf -of whom a Contribution has been received by Licensor and subsequently -incorporated within the Work. - -2. Grant of Copyright License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable copyright license to reproduce, prepare Derivative Works of, -publicly display, publicly perform, sublicense, and distribute the Work and such -Derivative Works in Source or Object form. - -3. Grant of Patent License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable (except as stated in this section) patent license to make, have -made, use, offer to sell, sell, import, and otherwise transfer the Work, where -such license applies only to those patent claims licensable by such Contributor -that are necessarily infringed by their Contribution(s) alone or by combination -of their Contribution(s) with the Work to which such Contribution(s) was -submitted. If You institute patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Work or a -Contribution incorporated within the Work constitutes direct or contributory -patent infringement, then any patent licenses granted to You under this License -for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. - -You may reproduce and distribute copies of the Work or Derivative Works thereof -in any medium, with or without modifications, and in Source or Object form, -provided that You meet the following conditions: - -You must give any other recipients of the Work or Derivative Works a copy of -this License; and -You must cause any modified files to carry prominent notices stating that You -changed the files; and -You must retain, in the Source form of any Derivative Works that You distribute, -all copyright, patent, trademark, and attribution notices from the Source form -of the Work, excluding those notices that do not pertain to any part of the -Derivative Works; and -If the Work includes a "NOTICE" text file as part of its distribution, then any -Derivative Works that You distribute must include a readable copy of the -attribution notices contained within such NOTICE file, excluding those notices -that do not pertain to any part of the Derivative Works, in at least one of the -following places: within a NOTICE text file distributed as part of the -Derivative Works; within the Source form or documentation, if provided along -with the Derivative Works; or, within a display generated by the Derivative -Works, if and wherever such third-party notices normally appear. The contents of -the NOTICE file are for informational purposes only and do not modify the -License. You may add Your own attribution notices within Derivative Works that -You distribute, alongside or as an addendum to the NOTICE text from the Work, -provided that such additional attribution notices cannot be construed as -modifying the License. -You may add Your own copyright statement to Your modifications and may provide -additional or different license terms and conditions for use, reproduction, or -distribution of Your modifications, or for any such Derivative Works as a whole, -provided Your use, reproduction, and distribution of the Work otherwise complies -with the conditions stated in this License. - -5. Submission of Contributions. - -Unless You explicitly state otherwise, any Contribution intentionally submitted -for inclusion in the Work by You to the Licensor shall be under the terms and -conditions of this License, without any additional terms or conditions. -Notwithstanding the above, nothing herein shall supersede or modify the terms of -any separate license agreement you may have executed with Licensor regarding -such Contributions. - -6. Trademarks. - -This License does not grant permission to use the trade names, trademarks, -service marks, or product names of the Licensor, except as required for -reasonable and customary use in describing the origin of the Work and -reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. - -Unless required by applicable law or agreed to in writing, Licensor provides the -Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, -including, without limitation, any warranties or conditions of TITLE, -NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are -solely responsible for determining the appropriateness of using or -redistributing the Work and assume any risks associated with Your exercise of -permissions under this License. - -8. Limitation of Liability. - -In no event and under no legal theory, whether in tort (including negligence), -contract, or otherwise, unless required by applicable law (such as deliberate -and grossly negligent acts) or agreed to in writing, shall any Contributor be -liable to You for damages, including any direct, indirect, special, incidental, -or consequential damages of any character arising as a result of this License or -out of the use or inability to use the Work (including but not limited to -damages for loss of goodwill, work stoppage, computer failure or malfunction, or -any and all other commercial damages or losses), even if such Contributor has -been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. - -While redistributing the Work or Derivative Works thereof, You may choose to -offer, and charge a fee for, acceptance of support, warranty, indemnity, or -other liability obligations and/or rights consistent with this License. However, -in accepting such obligations, You may act only on Your own behalf and on Your -sole responsibility, not on behalf of any other Contributor, and only if You -agree to indemnify, defend, and hold each Contributor harmless for any liability -incurred by, or claims asserted against, such Contributor by reason of your -accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work - -To apply the Apache License to your work, attach the following boilerplate -notice, with the fields enclosed by brackets "[]" replaced with your own -identifying information. (Don't include the brackets!) The text should be -enclosed in the appropriate comment syntax for the file format. We also -recommend that a file or class name and description of purpose be included on -the same "printed page" as the copyright notice for easier identification within -third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/golang/groupcache/lru/lru.go b/vendor/github.com/golang/groupcache/lru/lru.go deleted file mode 100644 index eac1c7664f..0000000000 --- a/vendor/github.com/golang/groupcache/lru/lru.go +++ /dev/null @@ -1,133 +0,0 @@ -/* -Copyright 2013 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package lru implements an LRU cache. -package lru - -import "container/list" - -// Cache is an LRU cache. It is not safe for concurrent access. -type Cache struct { - // MaxEntries is the maximum number of cache entries before - // an item is evicted. Zero means no limit. - MaxEntries int - - // OnEvicted optionally specifies a callback function to be - // executed when an entry is purged from the cache. - OnEvicted func(key Key, value interface{}) - - ll *list.List - cache map[interface{}]*list.Element -} - -// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators -type Key interface{} - -type entry struct { - key Key - value interface{} -} - -// New creates a new Cache. -// If maxEntries is zero, the cache has no limit and it's assumed -// that eviction is done by the caller. -func New(maxEntries int) *Cache { - return &Cache{ - MaxEntries: maxEntries, - ll: list.New(), - cache: make(map[interface{}]*list.Element), - } -} - -// Add adds a value to the cache. -func (c *Cache) Add(key Key, value interface{}) { - if c.cache == nil { - c.cache = make(map[interface{}]*list.Element) - c.ll = list.New() - } - if ee, ok := c.cache[key]; ok { - c.ll.MoveToFront(ee) - ee.Value.(*entry).value = value - return - } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries { - c.RemoveOldest() - } -} - -// Get looks up a key's value from the cache. -func (c *Cache) Get(key Key) (value interface{}, ok bool) { - if c.cache == nil { - return - } - if ele, hit := c.cache[key]; hit { - c.ll.MoveToFront(ele) - return ele.Value.(*entry).value, true - } - return -} - -// Remove removes the provided key from the cache. -func (c *Cache) Remove(key Key) { - if c.cache == nil { - return - } - if ele, hit := c.cache[key]; hit { - c.removeElement(ele) - } -} - -// RemoveOldest removes the oldest item from the cache. -func (c *Cache) RemoveOldest() { - if c.cache == nil { - return - } - ele := c.ll.Back() - if ele != nil { - c.removeElement(ele) - } -} - -func (c *Cache) removeElement(e *list.Element) { - c.ll.Remove(e) - kv := e.Value.(*entry) - delete(c.cache, kv.key) - if c.OnEvicted != nil { - c.OnEvicted(kv.key, kv.value) - } -} - -// Len returns the number of items in the cache. -func (c *Cache) Len() int { - if c.cache == nil { - return 0 - } - return c.ll.Len() -} - -// Clear purges all stored items from the cache. -func (c *Cache) Clear() { - if c.OnEvicted != nil { - for _, e := range c.cache { - kv := e.Value.(*entry) - c.OnEvicted(kv.key, kv.value) - } - } - c.ll = nil - c.cache = nil -} diff --git a/vendor/go.opencensus.io/.gitignore b/vendor/go.opencensus.io/.gitignore deleted file mode 100644 index 74a6db472e..0000000000 --- a/vendor/go.opencensus.io/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -/.idea/ - -# go.opencensus.io/exporter/aws -/exporter/aws/ - -# Exclude vendor, use dep ensure after checkout: -/vendor/github.com/ -/vendor/golang.org/ -/vendor/google.golang.org/ diff --git a/vendor/go.opencensus.io/AUTHORS b/vendor/go.opencensus.io/AUTHORS deleted file mode 100644 index e491a9e7f7..0000000000 --- a/vendor/go.opencensus.io/AUTHORS +++ /dev/null @@ -1 +0,0 @@ -Google Inc. diff --git a/vendor/go.opencensus.io/CONTRIBUTING.md b/vendor/go.opencensus.io/CONTRIBUTING.md deleted file mode 100644 index 1ba3962c8b..0000000000 --- a/vendor/go.opencensus.io/CONTRIBUTING.md +++ /dev/null @@ -1,63 +0,0 @@ -# How to contribute - -We'd love to accept your patches and contributions to this project. There are -just a few small guidelines you need to follow. - -## Contributor License Agreement - -Contributions to this project must be accompanied by a Contributor License -Agreement. You (or your employer) retain the copyright to your contribution, -this simply gives us permission to use and redistribute your contributions as -part of the project. Head over to to see -your current agreements on file or to sign a new one. - -You generally only need to submit a CLA once, so if you've already submitted one -(even if it was for a different project), you probably don't need to do it -again. - -## Code reviews - -All submissions, including submissions by project members, require review. We -use GitHub pull requests for this purpose. Consult [GitHub Help] for more -information on using pull requests. - -[GitHub Help]: https://help.github.com/articles/about-pull-requests/ - -## Instructions - -Fork the repo, checkout the upstream repo to your GOPATH by: - -``` -$ go get -d go.opencensus.io -``` - -Add your fork as an origin: - -``` -cd $(go env GOPATH)/src/go.opencensus.io -git remote add fork git@github.com:YOUR_GITHUB_USERNAME/opencensus-go.git -``` - -Run tests: - -``` -$ make install-tools # Only first time. -$ make -``` - -Checkout a new branch, make modifications and push the branch to your fork: - -``` -$ git checkout -b feature -# edit files -$ git commit -$ git push fork feature -``` - -Open a pull request against the main opencensus-go repo. - -## General Notes -This project uses Appveyor and Travis for CI. - -The dependencies are managed with `go mod` if you work with the sources under your -`$GOPATH` you need to set the environment variable `GO111MODULE=on`. \ No newline at end of file diff --git a/vendor/go.opencensus.io/Makefile b/vendor/go.opencensus.io/Makefile deleted file mode 100644 index d896edc996..0000000000 --- a/vendor/go.opencensus.io/Makefile +++ /dev/null @@ -1,97 +0,0 @@ -# TODO: Fix this on windows. -ALL_SRC := $(shell find . -name '*.go' \ - -not -path './vendor/*' \ - -not -path '*/gen-go/*' \ - -type f | sort) -ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC)))) - -GOTEST_OPT?=-v -race -timeout 30s -GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic -GOTEST=go test -GOIMPORTS=goimports -GOLINT=golint -GOVET=go vet -EMBEDMD=embedmd -# TODO decide if we need to change these names. -TRACE_ID_LINT_EXCEPTION="type name will be used as trace.TraceID by other packages" -TRACE_OPTION_LINT_EXCEPTION="type name will be used as trace.TraceOptions by other packages" -README_FILES := $(shell find . -name '*README.md' | sort | tr '\n' ' ') - -.DEFAULT_GOAL := imports-lint-vet-embedmd-test - -.PHONY: imports-lint-vet-embedmd-test -imports-lint-vet-embedmd-test: imports lint vet embedmd test - -# TODO enable test-with-coverage in tavis -.PHONY: travis-ci -travis-ci: imports lint vet embedmd test test-386 - -all-pkgs: - @echo $(ALL_PKGS) | tr ' ' '\n' | sort - -all-srcs: - @echo $(ALL_SRC) | tr ' ' '\n' | sort - -.PHONY: test -test: - $(GOTEST) $(GOTEST_OPT) $(ALL_PKGS) - -.PHONY: test-386 -test-386: - GOARCH=386 $(GOTEST) -v -timeout 30s $(ALL_PKGS) - -.PHONY: test-with-coverage -test-with-coverage: - $(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS) - -.PHONY: imports -imports: - @IMPORTSOUT=`$(GOIMPORTS) -l $(ALL_SRC) 2>&1`; \ - if [ "$$IMPORTSOUT" ]; then \ - echo "$(GOIMPORTS) FAILED => goimports the following files:\n"; \ - echo "$$IMPORTSOUT\n"; \ - exit 1; \ - else \ - echo "Imports finished successfully"; \ - fi - -.PHONY: lint -lint: - @LINTOUT=`$(GOLINT) $(ALL_PKGS) | grep -v $(TRACE_ID_LINT_EXCEPTION) | grep -v $(TRACE_OPTION_LINT_EXCEPTION) 2>&1`; \ - if [ "$$LINTOUT" ]; then \ - echo "$(GOLINT) FAILED => clean the following lint errors:\n"; \ - echo "$$LINTOUT\n"; \ - exit 1; \ - else \ - echo "Lint finished successfully"; \ - fi - -.PHONY: vet -vet: - # TODO: Understand why go vet downloads "github.com/google/go-cmp v0.2.0" - @VETOUT=`$(GOVET) ./... | grep -v "go: downloading" 2>&1`; \ - if [ "$$VETOUT" ]; then \ - echo "$(GOVET) FAILED => go vet the following files:\n"; \ - echo "$$VETOUT\n"; \ - exit 1; \ - else \ - echo "Vet finished successfully"; \ - fi - -.PHONY: embedmd -embedmd: - @EMBEDMDOUT=`$(EMBEDMD) -d $(README_FILES) 2>&1`; \ - if [ "$$EMBEDMDOUT" ]; then \ - echo "$(EMBEDMD) FAILED => embedmd the following files:\n"; \ - echo "$$EMBEDMDOUT\n"; \ - exit 1; \ - else \ - echo "Embedmd finished successfully"; \ - fi - -.PHONY: install-tools -install-tools: - go install golang.org/x/lint/golint@latest - go install golang.org/x/tools/cmd/cover@latest - go install golang.org/x/tools/cmd/goimports@latest - go install github.com/rakyll/embedmd@latest diff --git a/vendor/go.opencensus.io/README.md b/vendor/go.opencensus.io/README.md deleted file mode 100644 index 1d7e837116..0000000000 --- a/vendor/go.opencensus.io/README.md +++ /dev/null @@ -1,267 +0,0 @@ -# OpenCensus Libraries for Go - -[![Build Status][travis-image]][travis-url] -[![Windows Build Status][appveyor-image]][appveyor-url] -[![GoDoc][godoc-image]][godoc-url] -[![Gitter chat][gitter-image]][gitter-url] - -OpenCensus Go is a Go implementation of OpenCensus, a toolkit for -collecting application performance and behavior monitoring data. -Currently it consists of three major components: tags, stats and tracing. - -#### OpenCensus and OpenTracing have merged to form OpenTelemetry, which serves as the next major version of OpenCensus and OpenTracing. OpenTelemetry will offer backwards compatibility with existing OpenCensus integrations, and we will continue to make security patches to existing OpenCensus libraries for two years. Read more about the merger [here](https://medium.com/opentracing/a-roadmap-to-convergence-b074e5815289). - -## Installation - -``` -$ go get -u go.opencensus.io -``` - -The API of this project is still evolving, see: [Deprecation Policy](#deprecation-policy). -The use of vendoring or a dependency management tool is recommended. - -## Prerequisites - -OpenCensus Go libraries require Go 1.8 or later. - -## Getting Started - -The easiest way to get started using OpenCensus in your application is to use an existing -integration with your RPC framework: - -* [net/http](https://godoc.org/go.opencensus.io/plugin/ochttp) -* [gRPC](https://godoc.org/go.opencensus.io/plugin/ocgrpc) -* [database/sql](https://godoc.org/github.com/opencensus-integrations/ocsql) -* [Go kit](https://godoc.org/github.com/go-kit/kit/tracing/opencensus) -* [Groupcache](https://godoc.org/github.com/orijtech/groupcache) -* [Caddy webserver](https://godoc.org/github.com/orijtech/caddy) -* [MongoDB](https://godoc.org/github.com/orijtech/mongo-go-driver) -* [Redis gomodule/redigo](https://godoc.org/github.com/orijtech/redigo) -* [Redis goredis/redis](https://godoc.org/github.com/orijtech/redis) -* [Memcache](https://godoc.org/github.com/orijtech/gomemcache) - -If you're using a framework not listed here, you could either implement your own middleware for your -framework or use [custom stats](#stats) and [spans](#spans) directly in your application. - -## Exporters - -OpenCensus can export instrumentation data to various backends. -OpenCensus has exporter implementations for the following, users -can implement their own exporters by implementing the exporter interfaces -([stats](https://godoc.org/go.opencensus.io/stats/view#Exporter), -[trace](https://godoc.org/go.opencensus.io/trace#Exporter)): - -* [Prometheus][exporter-prom] for stats -* [OpenZipkin][exporter-zipkin] for traces -* [Stackdriver][exporter-stackdriver] Monitoring for stats and Trace for traces -* [Jaeger][exporter-jaeger] for traces -* [AWS X-Ray][exporter-xray] for traces -* [Datadog][exporter-datadog] for stats and traces -* [Graphite][exporter-graphite] for stats -* [Honeycomb][exporter-honeycomb] for traces -* [New Relic][exporter-newrelic] for stats and traces - -## Overview - -![OpenCensus Overview](https://i.imgur.com/cf4ElHE.jpg) - -In a microservices environment, a user request may go through -multiple services until there is a response. OpenCensus allows -you to instrument your services and collect diagnostics data all -through your services end-to-end. - -## Tags - -Tags represent propagated key-value pairs. They are propagated using `context.Context` -in the same process or can be encoded to be transmitted on the wire. Usually, this will -be handled by an integration plugin, e.g. `ocgrpc.ServerHandler` and `ocgrpc.ClientHandler` -for gRPC. - -Package `tag` allows adding or modifying tags in the current context. - -[embedmd]:# (internal/readme/tags.go new) -```go -ctx, err := tag.New(ctx, - tag.Insert(osKey, "macOS-10.12.5"), - tag.Upsert(userIDKey, "cde36753ed"), -) -if err != nil { - log.Fatal(err) -} -``` - -## Stats - -OpenCensus is a low-overhead framework even if instrumentation is always enabled. -In order to be so, it is optimized to make recording of data points fast -and separate from the data aggregation. - -OpenCensus stats collection happens in two stages: - -* Definition of measures and recording of data points -* Definition of views and aggregation of the recorded data - -### Recording - -Measurements are data points associated with a measure. -Recording implicitly tags the set of Measurements with the tags from the -provided context: - -[embedmd]:# (internal/readme/stats.go record) -```go -stats.Record(ctx, videoSize.M(102478)) -``` - -### Views - -Views are how Measures are aggregated. You can think of them as queries over the -set of recorded data points (measurements). - -Views have two parts: the tags to group by and the aggregation type used. - -Currently three types of aggregations are supported: -* CountAggregation is used to count the number of times a sample was recorded. -* DistributionAggregation is used to provide a histogram of the values of the samples. -* SumAggregation is used to sum up all sample values. - -[embedmd]:# (internal/readme/stats.go aggs) -```go -distAgg := view.Distribution(1<<32, 2<<32, 3<<32) -countAgg := view.Count() -sumAgg := view.Sum() -``` - -Here we create a view with the DistributionAggregation over our measure. - -[embedmd]:# (internal/readme/stats.go view) -```go -if err := view.Register(&view.View{ - Name: "example.com/video_size_distribution", - Description: "distribution of processed video size over time", - Measure: videoSize, - Aggregation: view.Distribution(1<<32, 2<<32, 3<<32), -}); err != nil { - log.Fatalf("Failed to register view: %v", err) -} -``` - -Register begins collecting data for the view. Registered views' data will be -exported via the registered exporters. - -## Traces - -A distributed trace tracks the progression of a single user request as -it is handled by the services and processes that make up an application. -Each step is called a span in the trace. Spans include metadata about the step, -including especially the time spent in the step, called the span’s latency. - -Below you see a trace and several spans underneath it. - -![Traces and spans](https://i.imgur.com/7hZwRVj.png) - -### Spans - -Span is the unit step in a trace. Each span has a name, latency, status and -additional metadata. - -Below we are starting a span for a cache read and ending it -when we are done: - -[embedmd]:# (internal/readme/trace.go startend) -```go -ctx, span := trace.StartSpan(ctx, "cache.Get") -defer span.End() - -// Do work to get from cache. -``` - -### Propagation - -Spans can have parents or can be root spans if they don't have any parents. -The current span is propagated in-process and across the network to allow associating -new child spans with the parent. - -In the same process, `context.Context` is used to propagate spans. -`trace.StartSpan` creates a new span as a root if the current context -doesn't contain a span. Or, it creates a child of the span that is -already in current context. The returned context can be used to keep -propagating the newly created span in the current context. - -[embedmd]:# (internal/readme/trace.go startend) -```go -ctx, span := trace.StartSpan(ctx, "cache.Get") -defer span.End() - -// Do work to get from cache. -``` - -Across the network, OpenCensus provides different propagation -methods for different protocols. - -* gRPC integrations use the OpenCensus' [binary propagation format](https://godoc.org/go.opencensus.io/trace/propagation). -* HTTP integrations use Zipkin's [B3](https://github.com/openzipkin/b3-propagation) - by default but can be configured to use a custom propagation method by setting another - [propagation.HTTPFormat](https://godoc.org/go.opencensus.io/trace/propagation#HTTPFormat). - -## Execution Tracer - -With Go 1.11, OpenCensus Go will support integration with the Go execution tracer. -See [Debugging Latency in Go](https://medium.com/observability/debugging-latency-in-go-1-11-9f97a7910d68) -for an example of their mutual use. - -## Profiles - -OpenCensus tags can be applied as profiler labels -for users who are on Go 1.9 and above. - -[embedmd]:# (internal/readme/tags.go profiler) -```go -ctx, err = tag.New(ctx, - tag.Insert(osKey, "macOS-10.12.5"), - tag.Insert(userIDKey, "fff0989878"), -) -if err != nil { - log.Fatal(err) -} -tag.Do(ctx, func(ctx context.Context) { - // Do work. - // When profiling is on, samples will be - // recorded with the key/values from the tag map. -}) -``` - -A screenshot of the CPU profile from the program above: - -![CPU profile](https://i.imgur.com/jBKjlkw.png) - -## Deprecation Policy - -Before version 1.0.0, the following deprecation policy will be observed: - -No backwards-incompatible changes will be made except for the removal of symbols that have -been marked as *Deprecated* for at least one minor release (e.g. 0.9.0 to 0.10.0). A release -removing the *Deprecated* functionality will be made no sooner than 28 days after the first -release in which the functionality was marked *Deprecated*. - -[travis-image]: https://travis-ci.org/census-instrumentation/opencensus-go.svg?branch=master -[travis-url]: https://travis-ci.org/census-instrumentation/opencensus-go -[appveyor-image]: https://ci.appveyor.com/api/projects/status/vgtt29ps1783ig38?svg=true -[appveyor-url]: https://ci.appveyor.com/project/opencensusgoteam/opencensus-go/branch/master -[godoc-image]: https://godoc.org/go.opencensus.io?status.svg -[godoc-url]: https://godoc.org/go.opencensus.io -[gitter-image]: https://badges.gitter.im/census-instrumentation/lobby.svg -[gitter-url]: https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge - - -[new-ex]: https://godoc.org/go.opencensus.io/tag#example-NewMap -[new-replace-ex]: https://godoc.org/go.opencensus.io/tag#example-NewMap--Replace - -[exporter-prom]: https://godoc.org/contrib.go.opencensus.io/exporter/prometheus -[exporter-stackdriver]: https://godoc.org/contrib.go.opencensus.io/exporter/stackdriver -[exporter-zipkin]: https://godoc.org/contrib.go.opencensus.io/exporter/zipkin -[exporter-jaeger]: https://godoc.org/contrib.go.opencensus.io/exporter/jaeger -[exporter-xray]: https://github.com/census-ecosystem/opencensus-go-exporter-aws -[exporter-datadog]: https://github.com/DataDog/opencensus-go-exporter-datadog -[exporter-graphite]: https://github.com/census-ecosystem/opencensus-go-exporter-graphite -[exporter-honeycomb]: https://github.com/honeycombio/opencensus-exporter -[exporter-newrelic]: https://github.com/newrelic/newrelic-opencensus-exporter-go diff --git a/vendor/go.opencensus.io/appveyor.yml b/vendor/go.opencensus.io/appveyor.yml deleted file mode 100644 index d08f0edaff..0000000000 --- a/vendor/go.opencensus.io/appveyor.yml +++ /dev/null @@ -1,24 +0,0 @@ -version: "{build}" - -platform: x64 - -clone_folder: c:\gopath\src\go.opencensus.io - -environment: - GOPATH: 'c:\gopath' - GO111MODULE: 'on' - CGO_ENABLED: '0' # See: https://github.com/appveyor/ci/issues/2613 - -stack: go 1.11 - -before_test: - - go version - - go env - -build: false -deploy: false - -test_script: - - cd %APPVEYOR_BUILD_FOLDER% - - go build -v .\... - - go test -v .\... # No -race because cgo is disabled diff --git a/vendor/go.opencensus.io/internal/internal.go b/vendor/go.opencensus.io/internal/internal.go deleted file mode 100644 index 81dc7183ec..0000000000 --- a/vendor/go.opencensus.io/internal/internal.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package internal // import "go.opencensus.io/internal" - -import ( - "fmt" - "time" - - opencensus "go.opencensus.io" -) - -// UserAgent is the user agent to be added to the outgoing -// requests from the exporters. -var UserAgent = fmt.Sprintf("opencensus-go/%s", opencensus.Version()) - -// MonotonicEndTime returns the end time at present -// but offset from start, monotonically. -// -// The monotonic clock is used in subtractions hence -// the duration since start added back to start gives -// end as a monotonic time. -// See https://golang.org/pkg/time/#hdr-Monotonic_Clocks -func MonotonicEndTime(start time.Time) time.Time { - return start.Add(time.Since(start)) -} diff --git a/vendor/go.opencensus.io/internal/sanitize.go b/vendor/go.opencensus.io/internal/sanitize.go deleted file mode 100644 index de8ccf236c..0000000000 --- a/vendor/go.opencensus.io/internal/sanitize.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package internal - -import ( - "strings" - "unicode" -) - -const labelKeySizeLimit = 100 - -// Sanitize returns a string that is trunacated to 100 characters if it's too -// long, and replaces non-alphanumeric characters to underscores. -func Sanitize(s string) string { - if len(s) == 0 { - return s - } - if len(s) > labelKeySizeLimit { - s = s[:labelKeySizeLimit] - } - s = strings.Map(sanitizeRune, s) - if unicode.IsDigit(rune(s[0])) { - s = "key_" + s - } - if s[0] == '_' { - s = "key" + s - } - return s -} - -// converts anything that is not a letter or digit to an underscore -func sanitizeRune(r rune) rune { - if unicode.IsLetter(r) || unicode.IsDigit(r) { - return r - } - // Everything else turns into an underscore - return '_' -} diff --git a/vendor/go.opencensus.io/internal/tagencoding/tagencoding.go b/vendor/go.opencensus.io/internal/tagencoding/tagencoding.go deleted file mode 100644 index 41b2c3fc03..0000000000 --- a/vendor/go.opencensus.io/internal/tagencoding/tagencoding.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -// Package tagencoding contains the tag encoding -// used interally by the stats collector. -package tagencoding // import "go.opencensus.io/internal/tagencoding" - -// Values represent the encoded buffer for the values. -type Values struct { - Buffer []byte - WriteIndex int - ReadIndex int -} - -func (vb *Values) growIfRequired(expected int) { - if len(vb.Buffer)-vb.WriteIndex < expected { - tmp := make([]byte, 2*(len(vb.Buffer)+1)+expected) - copy(tmp, vb.Buffer) - vb.Buffer = tmp - } -} - -// WriteValue is the helper method to encode Values from map[Key][]byte. -func (vb *Values) WriteValue(v []byte) { - length := len(v) & 0xff - vb.growIfRequired(1 + length) - - // writing length of v - vb.Buffer[vb.WriteIndex] = byte(length) - vb.WriteIndex++ - - if length == 0 { - // No value was encoded for this key - return - } - - // writing v - copy(vb.Buffer[vb.WriteIndex:], v[:length]) - vb.WriteIndex += length -} - -// ReadValue is the helper method to decode Values to a map[Key][]byte. -func (vb *Values) ReadValue() []byte { - // read length of v - length := int(vb.Buffer[vb.ReadIndex]) - vb.ReadIndex++ - if length == 0 { - // No value was encoded for this key - return nil - } - - // read value of v - v := make([]byte, length) - endIdx := vb.ReadIndex + length - copy(v, vb.Buffer[vb.ReadIndex:endIdx]) - vb.ReadIndex = endIdx - return v -} - -// Bytes returns a reference to already written bytes in the Buffer. -func (vb *Values) Bytes() []byte { - return vb.Buffer[:vb.WriteIndex] -} diff --git a/vendor/go.opencensus.io/internal/traceinternals.go b/vendor/go.opencensus.io/internal/traceinternals.go deleted file mode 100644 index 073af7b473..0000000000 --- a/vendor/go.opencensus.io/internal/traceinternals.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package internal - -import ( - "time" -) - -// Trace allows internal access to some trace functionality. -// TODO(#412): remove this -var Trace interface{} - -// LocalSpanStoreEnabled true if the local span store is enabled. -var LocalSpanStoreEnabled bool - -// BucketConfiguration stores the number of samples to store for span buckets -// for successful and failed spans for a particular span name. -type BucketConfiguration struct { - Name string - MaxRequestsSucceeded int - MaxRequestsErrors int -} - -// PerMethodSummary is a summary of the spans stored for a single span name. -type PerMethodSummary struct { - Active int - LatencyBuckets []LatencyBucketSummary - ErrorBuckets []ErrorBucketSummary -} - -// LatencyBucketSummary is a summary of a latency bucket. -type LatencyBucketSummary struct { - MinLatency, MaxLatency time.Duration - Size int -} - -// ErrorBucketSummary is a summary of an error bucket. -type ErrorBucketSummary struct { - ErrorCode int32 - Size int -} diff --git a/vendor/go.opencensus.io/metric/metricdata/doc.go b/vendor/go.opencensus.io/metric/metricdata/doc.go deleted file mode 100644 index 52a7b3bf85..0000000000 --- a/vendor/go.opencensus.io/metric/metricdata/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package metricdata contains the metrics data model. -// -// This is an EXPERIMENTAL package, and may change in arbitrary ways without -// notice. -package metricdata // import "go.opencensus.io/metric/metricdata" diff --git a/vendor/go.opencensus.io/metric/metricdata/exemplar.go b/vendor/go.opencensus.io/metric/metricdata/exemplar.go deleted file mode 100644 index 12695ce2dc..0000000000 --- a/vendor/go.opencensus.io/metric/metricdata/exemplar.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metricdata - -import ( - "time" -) - -// Exemplars keys. -const ( - AttachmentKeySpanContext = "SpanContext" -) - -// Exemplar is an example data point associated with each bucket of a -// distribution type aggregation. -// -// Their purpose is to provide an example of the kind of thing -// (request, RPC, trace span, etc.) that resulted in that measurement. -type Exemplar struct { - Value float64 // the value that was recorded - Timestamp time.Time // the time the value was recorded - Attachments Attachments // attachments (if any) -} - -// Attachments is a map of extra values associated with a recorded data point. -type Attachments map[string]interface{} diff --git a/vendor/go.opencensus.io/metric/metricdata/label.go b/vendor/go.opencensus.io/metric/metricdata/label.go deleted file mode 100644 index aadae41e6a..0000000000 --- a/vendor/go.opencensus.io/metric/metricdata/label.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metricdata - -// LabelKey represents key of a label. It has optional -// description attribute. -type LabelKey struct { - Key string - Description string -} - -// LabelValue represents the value of a label. -// The zero value represents a missing label value, which may be treated -// differently to an empty string value by some back ends. -type LabelValue struct { - Value string // string value of the label - Present bool // flag that indicated whether a value is present or not -} - -// NewLabelValue creates a new non-nil LabelValue that represents the given string. -func NewLabelValue(val string) LabelValue { - return LabelValue{Value: val, Present: true} -} diff --git a/vendor/go.opencensus.io/metric/metricdata/metric.go b/vendor/go.opencensus.io/metric/metricdata/metric.go deleted file mode 100644 index 8293712c77..0000000000 --- a/vendor/go.opencensus.io/metric/metricdata/metric.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metricdata - -import ( - "time" - - "go.opencensus.io/resource" -) - -// Descriptor holds metadata about a metric. -type Descriptor struct { - Name string // full name of the metric - Description string // human-readable description - Unit Unit // units for the measure - Type Type // type of measure - LabelKeys []LabelKey // label keys -} - -// Metric represents a quantity measured against a resource with different -// label value combinations. -type Metric struct { - Descriptor Descriptor // metric descriptor - Resource *resource.Resource // resource against which this was measured - TimeSeries []*TimeSeries // one time series for each combination of label values -} - -// TimeSeries is a sequence of points associated with a combination of label -// values. -type TimeSeries struct { - LabelValues []LabelValue // label values, same order as keys in the metric descriptor - Points []Point // points sequence - StartTime time.Time // time we started recording this time series -} diff --git a/vendor/go.opencensus.io/metric/metricdata/point.go b/vendor/go.opencensus.io/metric/metricdata/point.go deleted file mode 100644 index 7fe057b19c..0000000000 --- a/vendor/go.opencensus.io/metric/metricdata/point.go +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metricdata - -import ( - "time" -) - -// Point is a single data point of a time series. -type Point struct { - // Time is the point in time that this point represents in a time series. - Time time.Time - // Value is the value of this point. Prefer using ReadValue to switching on - // the value type, since new value types might be added. - Value interface{} -} - -//go:generate stringer -type ValueType - -// NewFloat64Point creates a new Point holding a float64 value. -func NewFloat64Point(t time.Time, val float64) Point { - return Point{ - Value: val, - Time: t, - } -} - -// NewInt64Point creates a new Point holding an int64 value. -func NewInt64Point(t time.Time, val int64) Point { - return Point{ - Value: val, - Time: t, - } -} - -// NewDistributionPoint creates a new Point holding a Distribution value. -func NewDistributionPoint(t time.Time, val *Distribution) Point { - return Point{ - Value: val, - Time: t, - } -} - -// NewSummaryPoint creates a new Point holding a Summary value. -func NewSummaryPoint(t time.Time, val *Summary) Point { - return Point{ - Value: val, - Time: t, - } -} - -// ValueVisitor allows reading the value of a point. -type ValueVisitor interface { - VisitFloat64Value(float64) - VisitInt64Value(int64) - VisitDistributionValue(*Distribution) - VisitSummaryValue(*Summary) -} - -// ReadValue accepts a ValueVisitor and calls the appropriate method with the -// value of this point. -// Consumers of Point should use this in preference to switching on the type -// of the value directly, since new value types may be added. -func (p Point) ReadValue(vv ValueVisitor) { - switch v := p.Value.(type) { - case int64: - vv.VisitInt64Value(v) - case float64: - vv.VisitFloat64Value(v) - case *Distribution: - vv.VisitDistributionValue(v) - case *Summary: - vv.VisitSummaryValue(v) - default: - panic("unexpected value type") - } -} - -// Distribution contains summary statistics for a population of values. It -// optionally contains a histogram representing the distribution of those -// values across a set of buckets. -type Distribution struct { - // Count is the number of values in the population. Must be non-negative. This value - // must equal the sum of the values in bucket_counts if a histogram is - // provided. - Count int64 - // Sum is the sum of the values in the population. If count is zero then this field - // must be zero. - Sum float64 - // SumOfSquaredDeviation is the sum of squared deviations from the mean of the values in the - // population. For values x_i this is: - // - // Sum[i=1..n]((x_i - mean)^2) - // - // Knuth, "The Art of Computer Programming", Vol. 2, page 323, 3rd edition - // describes Welford's method for accumulating this sum in one pass. - // - // If count is zero then this field must be zero. - SumOfSquaredDeviation float64 - // BucketOptions describes the bounds of the histogram buckets in this - // distribution. - // - // A Distribution may optionally contain a histogram of the values in the - // population. - // - // If nil, there is no associated histogram. - BucketOptions *BucketOptions - // Bucket If the distribution does not have a histogram, then omit this field. - // If there is a histogram, then the sum of the values in the Bucket counts - // must equal the value in the count field of the distribution. - Buckets []Bucket -} - -// BucketOptions describes the bounds of the histogram buckets in this -// distribution. -type BucketOptions struct { - // Bounds specifies a set of bucket upper bounds. - // This defines len(bounds) + 1 (= N) buckets. The boundaries for bucket - // index i are: - // - // [0, Bounds[i]) for i == 0 - // [Bounds[i-1], Bounds[i]) for 0 < i < N-1 - // [Bounds[i-1], +infinity) for i == N-1 - Bounds []float64 -} - -// Bucket represents a single bucket (value range) in a distribution. -type Bucket struct { - // Count is the number of values in each bucket of the histogram, as described in - // bucket_bounds. - Count int64 - // Exemplar associated with this bucket (if any). - Exemplar *Exemplar -} - -// Summary is a representation of percentiles. -type Summary struct { - // Count is the cumulative count (if available). - Count int64 - // Sum is the cumulative sum of values (if available). - Sum float64 - // HasCountAndSum is true if Count and Sum are available. - HasCountAndSum bool - // Snapshot represents percentiles calculated over an arbitrary time window. - // The values in this struct can be reset at arbitrary unknown times, with - // the requirement that all of them are reset at the same time. - Snapshot Snapshot -} - -// Snapshot represents percentiles over an arbitrary time. -// The values in this struct can be reset at arbitrary unknown times, with -// the requirement that all of them are reset at the same time. -type Snapshot struct { - // Count is the number of values in the snapshot. Optional since some systems don't - // expose this. Set to 0 if not available. - Count int64 - // Sum is the sum of values in the snapshot. Optional since some systems don't - // expose this. If count is 0 then this field must be zero. - Sum float64 - // Percentiles is a map from percentile (range (0-100.0]) to the value of - // the percentile. - Percentiles map[float64]float64 -} - -//go:generate stringer -type Type - -// Type is the overall type of metric, including its value type and whether it -// represents a cumulative total (since the start time) or if it represents a -// gauge value. -type Type int - -// Metric types. -const ( - TypeGaugeInt64 Type = iota - TypeGaugeFloat64 - TypeGaugeDistribution - TypeCumulativeInt64 - TypeCumulativeFloat64 - TypeCumulativeDistribution - TypeSummary -) diff --git a/vendor/go.opencensus.io/metric/metricdata/type_string.go b/vendor/go.opencensus.io/metric/metricdata/type_string.go deleted file mode 100644 index c3f8ec27b5..0000000000 --- a/vendor/go.opencensus.io/metric/metricdata/type_string.go +++ /dev/null @@ -1,16 +0,0 @@ -// Code generated by "stringer -type Type"; DO NOT EDIT. - -package metricdata - -import "strconv" - -const _Type_name = "TypeGaugeInt64TypeGaugeFloat64TypeGaugeDistributionTypeCumulativeInt64TypeCumulativeFloat64TypeCumulativeDistributionTypeSummary" - -var _Type_index = [...]uint8{0, 14, 30, 51, 70, 91, 117, 128} - -func (i Type) String() string { - if i < 0 || i >= Type(len(_Type_index)-1) { - return "Type(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _Type_name[_Type_index[i]:_Type_index[i+1]] -} diff --git a/vendor/go.opencensus.io/metric/metricdata/unit.go b/vendor/go.opencensus.io/metric/metricdata/unit.go deleted file mode 100644 index b483a1371b..0000000000 --- a/vendor/go.opencensus.io/metric/metricdata/unit.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metricdata - -// Unit is a string encoded according to the case-sensitive abbreviations from the -// Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html -type Unit string - -// Predefined units. To record against a unit not represented here, create your -// own Unit type constant from a string. -const ( - UnitDimensionless Unit = "1" - UnitBytes Unit = "By" - UnitMilliseconds Unit = "ms" -) diff --git a/vendor/go.opencensus.io/metric/metricproducer/manager.go b/vendor/go.opencensus.io/metric/metricproducer/manager.go deleted file mode 100644 index ca1f390493..0000000000 --- a/vendor/go.opencensus.io/metric/metricproducer/manager.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2019, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metricproducer - -import ( - "sync" -) - -// Manager maintains a list of active producers. Producers can register -// with the manager to allow readers to read all metrics provided by them. -// Readers can retrieve all producers registered with the manager, -// read metrics from the producers and export them. -type Manager struct { - mu sync.RWMutex - producers map[Producer]struct{} -} - -var prodMgr *Manager -var once sync.Once - -// GlobalManager is a single instance of producer manager -// that is used by all producers and all readers. -func GlobalManager() *Manager { - once.Do(func() { - prodMgr = &Manager{} - prodMgr.producers = make(map[Producer]struct{}) - }) - return prodMgr -} - -// AddProducer adds the producer to the Manager if it is not already present. -func (pm *Manager) AddProducer(producer Producer) { - if producer == nil { - return - } - pm.mu.Lock() - defer pm.mu.Unlock() - pm.producers[producer] = struct{}{} -} - -// DeleteProducer deletes the producer from the Manager if it is present. -func (pm *Manager) DeleteProducer(producer Producer) { - if producer == nil { - return - } - pm.mu.Lock() - defer pm.mu.Unlock() - delete(pm.producers, producer) -} - -// GetAll returns a slice of all producer currently registered with -// the Manager. For each call it generates a new slice. The slice -// should not be cached as registration may change at any time. It is -// typically called periodically by exporter to read metrics from -// the producers. -func (pm *Manager) GetAll() []Producer { - pm.mu.Lock() - defer pm.mu.Unlock() - producers := make([]Producer, len(pm.producers)) - i := 0 - for producer := range pm.producers { - producers[i] = producer - i++ - } - return producers -} diff --git a/vendor/go.opencensus.io/metric/metricproducer/producer.go b/vendor/go.opencensus.io/metric/metricproducer/producer.go deleted file mode 100644 index 6cee9ed178..0000000000 --- a/vendor/go.opencensus.io/metric/metricproducer/producer.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2019, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metricproducer - -import ( - "go.opencensus.io/metric/metricdata" -) - -// Producer is a source of metrics. -type Producer interface { - // Read should return the current values of all metrics supported by this - // metric provider. - // The returned metrics should be unique for each combination of name and - // resource. - Read() []*metricdata.Metric -} diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/client.go b/vendor/go.opencensus.io/plugin/ocgrpc/client.go deleted file mode 100644 index 2063b6f76a..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/client.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ocgrpc - -import ( - "context" - - "go.opencensus.io/trace" - "google.golang.org/grpc/stats" -) - -// ClientHandler implements a gRPC stats.Handler for recording OpenCensus stats and -// traces. Use with gRPC clients only. -type ClientHandler struct { - // StartOptions allows configuring the StartOptions used to create new spans. - // - // StartOptions.SpanKind will always be set to trace.SpanKindClient - // for spans started by this handler. - StartOptions trace.StartOptions -} - -// HandleConn exists to satisfy gRPC stats.Handler. -func (c *ClientHandler) HandleConn(ctx context.Context, cs stats.ConnStats) { - // no-op -} - -// TagConn exists to satisfy gRPC stats.Handler. -func (c *ClientHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context { - // no-op - return ctx -} - -// HandleRPC implements per-RPC tracing and stats instrumentation. -func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) { - traceHandleRPC(ctx, rs) - statsHandleRPC(ctx, rs) -} - -// TagRPC implements per-RPC context management. -func (c *ClientHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context { - ctx = c.traceTagRPC(ctx, rti) - ctx = c.statsTagRPC(ctx, rti) - return ctx -} diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/client_metrics.go b/vendor/go.opencensus.io/plugin/ocgrpc/client_metrics.go deleted file mode 100644 index fb3c19d6b6..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/client_metrics.go +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package ocgrpc - -import ( - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" -) - -// The following variables are measures are recorded by ClientHandler: -var ( - ClientSentMessagesPerRPC = stats.Int64("grpc.io/client/sent_messages_per_rpc", "Number of messages sent in the RPC (always 1 for non-streaming RPCs).", stats.UnitDimensionless) - ClientSentBytesPerRPC = stats.Int64("grpc.io/client/sent_bytes_per_rpc", "Total bytes sent across all request messages per RPC.", stats.UnitBytes) - ClientReceivedMessagesPerRPC = stats.Int64("grpc.io/client/received_messages_per_rpc", "Number of response messages received per RPC (always 1 for non-streaming RPCs).", stats.UnitDimensionless) - ClientReceivedBytesPerRPC = stats.Int64("grpc.io/client/received_bytes_per_rpc", "Total bytes received across all response messages per RPC.", stats.UnitBytes) - ClientRoundtripLatency = stats.Float64("grpc.io/client/roundtrip_latency", "Time between first byte of request sent to last byte of response received, or terminal error.", stats.UnitMilliseconds) - ClientStartedRPCs = stats.Int64("grpc.io/client/started_rpcs", "Number of started client RPCs.", stats.UnitDimensionless) - ClientServerLatency = stats.Float64("grpc.io/client/server_latency", `Propagated from the server and should have the same value as "grpc.io/server/latency".`, stats.UnitMilliseconds) -) - -// Predefined views may be registered to collect data for the above measures. -// As always, you may also define your own custom views over measures collected by this -// package. These are declared as a convenience only; none are registered by -// default. -var ( - ClientSentBytesPerRPCView = &view.View{ - Measure: ClientSentBytesPerRPC, - Name: "grpc.io/client/sent_bytes_per_rpc", - Description: "Distribution of bytes sent per RPC, by method.", - TagKeys: []tag.Key{KeyClientMethod}, - Aggregation: DefaultBytesDistribution, - } - - ClientReceivedBytesPerRPCView = &view.View{ - Measure: ClientReceivedBytesPerRPC, - Name: "grpc.io/client/received_bytes_per_rpc", - Description: "Distribution of bytes received per RPC, by method.", - TagKeys: []tag.Key{KeyClientMethod}, - Aggregation: DefaultBytesDistribution, - } - - ClientRoundtripLatencyView = &view.View{ - Measure: ClientRoundtripLatency, - Name: "grpc.io/client/roundtrip_latency", - Description: "Distribution of round-trip latency, by method.", - TagKeys: []tag.Key{KeyClientMethod}, - Aggregation: DefaultMillisecondsDistribution, - } - - // Purposely reuses the count from `ClientRoundtripLatency`, tagging - // with method and status to result in ClientCompletedRpcs. - ClientCompletedRPCsView = &view.View{ - Measure: ClientRoundtripLatency, - Name: "grpc.io/client/completed_rpcs", - Description: "Count of RPCs by method and status.", - TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus}, - Aggregation: view.Count(), - } - - ClientStartedRPCsView = &view.View{ - Measure: ClientStartedRPCs, - Name: "grpc.io/client/started_rpcs", - Description: "Number of started client RPCs.", - TagKeys: []tag.Key{KeyClientMethod}, - Aggregation: view.Count(), - } - - ClientSentMessagesPerRPCView = &view.View{ - Measure: ClientSentMessagesPerRPC, - Name: "grpc.io/client/sent_messages_per_rpc", - Description: "Distribution of sent messages count per RPC, by method.", - TagKeys: []tag.Key{KeyClientMethod}, - Aggregation: DefaultMessageCountDistribution, - } - - ClientReceivedMessagesPerRPCView = &view.View{ - Measure: ClientReceivedMessagesPerRPC, - Name: "grpc.io/client/received_messages_per_rpc", - Description: "Distribution of received messages count per RPC, by method.", - TagKeys: []tag.Key{KeyClientMethod}, - Aggregation: DefaultMessageCountDistribution, - } - - ClientServerLatencyView = &view.View{ - Measure: ClientServerLatency, - Name: "grpc.io/client/server_latency", - Description: "Distribution of server latency as viewed by client, by method.", - TagKeys: []tag.Key{KeyClientMethod}, - Aggregation: DefaultMillisecondsDistribution, - } -) - -// DefaultClientViews are the default client views provided by this package. -var DefaultClientViews = []*view.View{ - ClientSentBytesPerRPCView, - ClientReceivedBytesPerRPCView, - ClientRoundtripLatencyView, - ClientCompletedRPCsView, -} - -// TODO(jbd): Add roundtrip_latency, uncompressed_request_bytes, uncompressed_response_bytes, request_count, response_count. -// TODO(acetechnologist): This is temporary and will need to be replaced by a -// mechanism to load these defaults from a common repository/config shared by -// all supported languages. Likely a serialized protobuf of these defaults. diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/client_stats_handler.go b/vendor/go.opencensus.io/plugin/ocgrpc/client_stats_handler.go deleted file mode 100644 index b36349820d..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/client_stats_handler.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package ocgrpc - -import ( - "context" - "time" - - "go.opencensus.io/tag" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/stats" -) - -// statsTagRPC gets the tag.Map populated by the application code, serializes -// its tags into the GRPC metadata in order to be sent to the server. -func (h *ClientHandler) statsTagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context { - startTime := time.Now() - if info == nil { - if grpclog.V(2) { - grpclog.Info("clientHandler.TagRPC called with nil info.") - } - return ctx - } - - d := &rpcData{ - startTime: startTime, - method: info.FullMethodName, - } - ts := tag.FromContext(ctx) - if ts != nil { - encoded := tag.Encode(ts) - ctx = stats.SetTags(ctx, encoded) - } - - return context.WithValue(ctx, rpcDataKey, d) -} diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/doc.go b/vendor/go.opencensus.io/plugin/ocgrpc/doc.go deleted file mode 100644 index 1370323fb7..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ocgrpc contains OpenCensus stats and trace -// integrations for gRPC. -// -// Use ServerHandler for servers and ClientHandler for clients. -package ocgrpc // import "go.opencensus.io/plugin/ocgrpc" diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/server.go b/vendor/go.opencensus.io/plugin/ocgrpc/server.go deleted file mode 100644 index 8a53e09727..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/server.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ocgrpc - -import ( - "context" - - "google.golang.org/grpc/stats" - - "go.opencensus.io/trace" -) - -// ServerHandler implements gRPC stats.Handler recording OpenCensus stats and -// traces. Use with gRPC servers. -// -// When installed (see Example), tracing metadata is read from inbound RPCs -// by default. If no tracing metadata is present, or if the tracing metadata is -// present but the SpanContext isn't sampled, then a new trace may be started -// (as determined by Sampler). -type ServerHandler struct { - // IsPublicEndpoint may be set to true to always start a new trace around - // each RPC. Any SpanContext in the RPC metadata will be added as a linked - // span instead of making it the parent of the span created around the - // server RPC. - // - // Be aware that if you leave this false (the default) on a public-facing - // server, callers will be able to send tracing metadata in gRPC headers - // and trigger traces in your backend. - IsPublicEndpoint bool - - // StartOptions to use for to spans started around RPCs handled by this server. - // - // These will apply even if there is tracing metadata already - // present on the inbound RPC but the SpanContext is not sampled. This - // ensures that each service has some opportunity to be traced. If you would - // like to not add any additional traces for this gRPC service, set: - // - // StartOptions.Sampler = trace.ProbabilitySampler(0.0) - // - // StartOptions.SpanKind will always be set to trace.SpanKindServer - // for spans started by this handler. - StartOptions trace.StartOptions -} - -var _ stats.Handler = (*ServerHandler)(nil) - -// HandleConn exists to satisfy gRPC stats.Handler. -func (s *ServerHandler) HandleConn(ctx context.Context, cs stats.ConnStats) { - // no-op -} - -// TagConn exists to satisfy gRPC stats.Handler. -func (s *ServerHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context { - // no-op - return ctx -} - -// HandleRPC implements per-RPC tracing and stats instrumentation. -func (s *ServerHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) { - traceHandleRPC(ctx, rs) - statsHandleRPC(ctx, rs) -} - -// TagRPC implements per-RPC context management. -func (s *ServerHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context { - ctx = s.traceTagRPC(ctx, rti) - ctx = s.statsTagRPC(ctx, rti) - return ctx -} diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/server_metrics.go b/vendor/go.opencensus.io/plugin/ocgrpc/server_metrics.go deleted file mode 100644 index fe0e971086..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/server_metrics.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package ocgrpc - -import ( - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" -) - -// The following variables are measures are recorded by ServerHandler: -var ( - ServerReceivedMessagesPerRPC = stats.Int64("grpc.io/server/received_messages_per_rpc", "Number of messages received in each RPC. Has value 1 for non-streaming RPCs.", stats.UnitDimensionless) - ServerReceivedBytesPerRPC = stats.Int64("grpc.io/server/received_bytes_per_rpc", "Total bytes received across all messages per RPC.", stats.UnitBytes) - ServerSentMessagesPerRPC = stats.Int64("grpc.io/server/sent_messages_per_rpc", "Number of messages sent in each RPC. Has value 1 for non-streaming RPCs.", stats.UnitDimensionless) - ServerSentBytesPerRPC = stats.Int64("grpc.io/server/sent_bytes_per_rpc", "Total bytes sent in across all response messages per RPC.", stats.UnitBytes) - ServerStartedRPCs = stats.Int64("grpc.io/server/started_rpcs", "Number of started server RPCs.", stats.UnitDimensionless) - ServerLatency = stats.Float64("grpc.io/server/server_latency", "Time between first byte of request received to last byte of response sent, or terminal error.", stats.UnitMilliseconds) -) - -// TODO(acetechnologist): This is temporary and will need to be replaced by a -// mechanism to load these defaults from a common repository/config shared by -// all supported languages. Likely a serialized protobuf of these defaults. - -// Predefined views may be registered to collect data for the above measures. -// As always, you may also define your own custom views over measures collected by this -// package. These are declared as a convenience only; none are registered by -// default. -var ( - ServerReceivedBytesPerRPCView = &view.View{ - Name: "grpc.io/server/received_bytes_per_rpc", - Description: "Distribution of received bytes per RPC, by method.", - Measure: ServerReceivedBytesPerRPC, - TagKeys: []tag.Key{KeyServerMethod}, - Aggregation: DefaultBytesDistribution, - } - - ServerSentBytesPerRPCView = &view.View{ - Name: "grpc.io/server/sent_bytes_per_rpc", - Description: "Distribution of total sent bytes per RPC, by method.", - Measure: ServerSentBytesPerRPC, - TagKeys: []tag.Key{KeyServerMethod}, - Aggregation: DefaultBytesDistribution, - } - - ServerLatencyView = &view.View{ - Name: "grpc.io/server/server_latency", - Description: "Distribution of server latency in milliseconds, by method.", - TagKeys: []tag.Key{KeyServerMethod}, - Measure: ServerLatency, - Aggregation: DefaultMillisecondsDistribution, - } - - // Purposely reuses the count from `ServerLatency`, tagging - // with method and status to result in ServerCompletedRpcs. - ServerCompletedRPCsView = &view.View{ - Name: "grpc.io/server/completed_rpcs", - Description: "Count of RPCs by method and status.", - TagKeys: []tag.Key{KeyServerMethod, KeyServerStatus}, - Measure: ServerLatency, - Aggregation: view.Count(), - } - - ServerStartedRPCsView = &view.View{ - Measure: ServerStartedRPCs, - Name: "grpc.io/server/started_rpcs", - Description: "Number of started server RPCs.", - TagKeys: []tag.Key{KeyServerMethod}, - Aggregation: view.Count(), - } - - ServerReceivedMessagesPerRPCView = &view.View{ - Name: "grpc.io/server/received_messages_per_rpc", - Description: "Distribution of messages received count per RPC, by method.", - TagKeys: []tag.Key{KeyServerMethod}, - Measure: ServerReceivedMessagesPerRPC, - Aggregation: DefaultMessageCountDistribution, - } - - ServerSentMessagesPerRPCView = &view.View{ - Name: "grpc.io/server/sent_messages_per_rpc", - Description: "Distribution of messages sent count per RPC, by method.", - TagKeys: []tag.Key{KeyServerMethod}, - Measure: ServerSentMessagesPerRPC, - Aggregation: DefaultMessageCountDistribution, - } -) - -// DefaultServerViews are the default server views provided by this package. -var DefaultServerViews = []*view.View{ - ServerReceivedBytesPerRPCView, - ServerSentBytesPerRPCView, - ServerLatencyView, - ServerCompletedRPCsView, -} diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/server_stats_handler.go b/vendor/go.opencensus.io/plugin/ocgrpc/server_stats_handler.go deleted file mode 100644 index afcef023af..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/server_stats_handler.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package ocgrpc - -import ( - "time" - - "context" - - "go.opencensus.io/tag" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/stats" -) - -// statsTagRPC gets the metadata from gRPC context, extracts the encoded tags from -// it and creates a new tag.Map and puts them into the returned context. -func (h *ServerHandler) statsTagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context { - startTime := time.Now() - if info == nil { - if grpclog.V(2) { - grpclog.Infof("opencensus: TagRPC called with nil info.") - } - return ctx - } - d := &rpcData{ - startTime: startTime, - method: info.FullMethodName, - } - propagated := h.extractPropagatedTags(ctx) - ctx = tag.NewContext(ctx, propagated) - ctx, _ = tag.New(ctx, tag.Upsert(KeyServerMethod, methodName(info.FullMethodName))) - return context.WithValue(ctx, rpcDataKey, d) -} - -// extractPropagatedTags creates a new tag map containing the tags extracted from the -// gRPC metadata. -func (h *ServerHandler) extractPropagatedTags(ctx context.Context) *tag.Map { - buf := stats.Tags(ctx) - if buf == nil { - return nil - } - propagated, err := tag.Decode(buf) - if err != nil { - if grpclog.V(2) { - grpclog.Warningf("opencensus: Failed to decode tags from gRPC metadata failed to decode: %v", err) - } - return nil - } - return propagated -} diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/stats_common.go b/vendor/go.opencensus.io/plugin/ocgrpc/stats_common.go deleted file mode 100644 index 9cb27320ca..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/stats_common.go +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package ocgrpc - -import ( - "context" - "strconv" - "strings" - "sync/atomic" - "time" - - "go.opencensus.io/metric/metricdata" - ocstats "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" - "go.opencensus.io/trace" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/stats" - "google.golang.org/grpc/status" -) - -type grpcInstrumentationKey string - -// rpcData holds the instrumentation RPC data that is needed between the start -// and end of an call. It holds the info that this package needs to keep track -// of between the various GRPC events. -type rpcData struct { - // reqCount and respCount has to be the first words - // in order to be 64-aligned on 32-bit architectures. - sentCount, sentBytes, recvCount, recvBytes int64 // access atomically - - // startTime represents the time at which TagRPC was invoked at the - // beginning of an RPC. It is an appoximation of the time when the - // application code invoked GRPC code. - startTime time.Time - method string -} - -// The following variables define the default hard-coded auxiliary data used by -// both the default GRPC client and GRPC server metrics. -var ( - DefaultBytesDistribution = view.Distribution(1024, 2048, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864, 268435456, 1073741824, 4294967296) - DefaultMillisecondsDistribution = view.Distribution(0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000) - DefaultMessageCountDistribution = view.Distribution(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536) -) - -// Server tags are applied to the context used to process each RPC, as well as -// the measures at the end of each RPC. -var ( - KeyServerMethod = tag.MustNewKey("grpc_server_method") - KeyServerStatus = tag.MustNewKey("grpc_server_status") -) - -// Client tags are applied to measures at the end of each RPC. -var ( - KeyClientMethod = tag.MustNewKey("grpc_client_method") - KeyClientStatus = tag.MustNewKey("grpc_client_status") -) - -var ( - rpcDataKey = grpcInstrumentationKey("opencensus-rpcData") -) - -func methodName(fullname string) string { - return strings.TrimLeft(fullname, "/") -} - -// statsHandleRPC processes the RPC events. -func statsHandleRPC(ctx context.Context, s stats.RPCStats) { - switch st := s.(type) { - case *stats.OutHeader, *stats.InHeader, *stats.InTrailer, *stats.OutTrailer: - // do nothing for client - case *stats.Begin: - handleRPCBegin(ctx, st) - case *stats.OutPayload: - handleRPCOutPayload(ctx, st) - case *stats.InPayload: - handleRPCInPayload(ctx, st) - case *stats.End: - handleRPCEnd(ctx, st) - default: - grpclog.Infof("unexpected stats: %T", st) - } -} - -func handleRPCBegin(ctx context.Context, s *stats.Begin) { - d, ok := ctx.Value(rpcDataKey).(*rpcData) - if !ok { - if grpclog.V(2) { - grpclog.Infoln("Failed to retrieve *rpcData from context.") - } - } - - if s.IsClient() { - ocstats.RecordWithOptions(ctx, - ocstats.WithTags(tag.Upsert(KeyClientMethod, methodName(d.method))), - ocstats.WithMeasurements(ClientStartedRPCs.M(1))) - } else { - ocstats.RecordWithOptions(ctx, - ocstats.WithTags(tag.Upsert(KeyClientMethod, methodName(d.method))), - ocstats.WithMeasurements(ServerStartedRPCs.M(1))) - } -} - -func handleRPCOutPayload(ctx context.Context, s *stats.OutPayload) { - d, ok := ctx.Value(rpcDataKey).(*rpcData) - if !ok { - if grpclog.V(2) { - grpclog.Infoln("Failed to retrieve *rpcData from context.") - } - return - } - - atomic.AddInt64(&d.sentBytes, int64(s.Length)) - atomic.AddInt64(&d.sentCount, 1) -} - -func handleRPCInPayload(ctx context.Context, s *stats.InPayload) { - d, ok := ctx.Value(rpcDataKey).(*rpcData) - if !ok { - if grpclog.V(2) { - grpclog.Infoln("Failed to retrieve *rpcData from context.") - } - return - } - - atomic.AddInt64(&d.recvBytes, int64(s.Length)) - atomic.AddInt64(&d.recvCount, 1) -} - -func handleRPCEnd(ctx context.Context, s *stats.End) { - d, ok := ctx.Value(rpcDataKey).(*rpcData) - if !ok { - if grpclog.V(2) { - grpclog.Infoln("Failed to retrieve *rpcData from context.") - } - return - } - - elapsedTime := time.Since(d.startTime) - - var st string - if s.Error != nil { - s, ok := status.FromError(s.Error) - if ok { - st = statusCodeToString(s) - } - } else { - st = "OK" - } - - latencyMillis := float64(elapsedTime) / float64(time.Millisecond) - attachments := getSpanCtxAttachment(ctx) - if s.Client { - ocstats.RecordWithOptions(ctx, - ocstats.WithTags( - tag.Upsert(KeyClientMethod, methodName(d.method)), - tag.Upsert(KeyClientStatus, st)), - ocstats.WithAttachments(attachments), - ocstats.WithMeasurements( - ClientSentBytesPerRPC.M(atomic.LoadInt64(&d.sentBytes)), - ClientSentMessagesPerRPC.M(atomic.LoadInt64(&d.sentCount)), - ClientReceivedMessagesPerRPC.M(atomic.LoadInt64(&d.recvCount)), - ClientReceivedBytesPerRPC.M(atomic.LoadInt64(&d.recvBytes)), - ClientRoundtripLatency.M(latencyMillis))) - } else { - ocstats.RecordWithOptions(ctx, - ocstats.WithTags( - tag.Upsert(KeyServerStatus, st), - ), - ocstats.WithAttachments(attachments), - ocstats.WithMeasurements( - ServerSentBytesPerRPC.M(atomic.LoadInt64(&d.sentBytes)), - ServerSentMessagesPerRPC.M(atomic.LoadInt64(&d.sentCount)), - ServerReceivedMessagesPerRPC.M(atomic.LoadInt64(&d.recvCount)), - ServerReceivedBytesPerRPC.M(atomic.LoadInt64(&d.recvBytes)), - ServerLatency.M(latencyMillis))) - } -} - -func statusCodeToString(s *status.Status) string { - // see https://github.com/grpc/grpc/blob/master/doc/statuscodes.md - switch c := s.Code(); c { - case codes.OK: - return "OK" - case codes.Canceled: - return "CANCELLED" - case codes.Unknown: - return "UNKNOWN" - case codes.InvalidArgument: - return "INVALID_ARGUMENT" - case codes.DeadlineExceeded: - return "DEADLINE_EXCEEDED" - case codes.NotFound: - return "NOT_FOUND" - case codes.AlreadyExists: - return "ALREADY_EXISTS" - case codes.PermissionDenied: - return "PERMISSION_DENIED" - case codes.ResourceExhausted: - return "RESOURCE_EXHAUSTED" - case codes.FailedPrecondition: - return "FAILED_PRECONDITION" - case codes.Aborted: - return "ABORTED" - case codes.OutOfRange: - return "OUT_OF_RANGE" - case codes.Unimplemented: - return "UNIMPLEMENTED" - case codes.Internal: - return "INTERNAL" - case codes.Unavailable: - return "UNAVAILABLE" - case codes.DataLoss: - return "DATA_LOSS" - case codes.Unauthenticated: - return "UNAUTHENTICATED" - default: - return "CODE_" + strconv.FormatInt(int64(c), 10) - } -} - -func getSpanCtxAttachment(ctx context.Context) metricdata.Attachments { - attachments := map[string]interface{}{} - span := trace.FromContext(ctx) - if span == nil { - return attachments - } - spanCtx := span.SpanContext() - if spanCtx.IsSampled() { - attachments[metricdata.AttachmentKeySpanContext] = spanCtx - } - return attachments -} diff --git a/vendor/go.opencensus.io/plugin/ocgrpc/trace_common.go b/vendor/go.opencensus.io/plugin/ocgrpc/trace_common.go deleted file mode 100644 index 61bc543d0a..0000000000 --- a/vendor/go.opencensus.io/plugin/ocgrpc/trace_common.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ocgrpc - -import ( - "context" - "strings" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/stats" - "google.golang.org/grpc/status" - - "go.opencensus.io/trace" - "go.opencensus.io/trace/propagation" -) - -const traceContextKey = "grpc-trace-bin" - -// TagRPC creates a new trace span for the client side of the RPC. -// -// It returns ctx with the new trace span added and a serialization of the -// SpanContext added to the outgoing gRPC metadata. -func (c *ClientHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context { - name := strings.TrimPrefix(rti.FullMethodName, "/") - name = strings.Replace(name, "/", ".", -1) - ctx, span := trace.StartSpan(ctx, name, - trace.WithSampler(c.StartOptions.Sampler), - trace.WithSpanKind(trace.SpanKindClient)) // span is ended by traceHandleRPC - traceContextBinary := propagation.Binary(span.SpanContext()) - return metadata.AppendToOutgoingContext(ctx, traceContextKey, string(traceContextBinary)) -} - -// TagRPC creates a new trace span for the server side of the RPC. -// -// It checks the incoming gRPC metadata in ctx for a SpanContext, and if -// it finds one, uses that SpanContext as the parent context of the new span. -// -// It returns ctx, with the new trace span added. -func (s *ServerHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context { - md, _ := metadata.FromIncomingContext(ctx) - name := strings.TrimPrefix(rti.FullMethodName, "/") - name = strings.Replace(name, "/", ".", -1) - traceContext := md[traceContextKey] - var ( - parent trace.SpanContext - haveParent bool - ) - if len(traceContext) > 0 { - // Metadata with keys ending in -bin are actually binary. They are base64 - // encoded before being put on the wire, see: - // https://github.com/grpc/grpc-go/blob/08d6261/Documentation/grpc-metadata.md#storing-binary-data-in-metadata - traceContextBinary := []byte(traceContext[0]) - parent, haveParent = propagation.FromBinary(traceContextBinary) - if haveParent && !s.IsPublicEndpoint { - ctx, _ := trace.StartSpanWithRemoteParent(ctx, name, parent, - trace.WithSpanKind(trace.SpanKindServer), - trace.WithSampler(s.StartOptions.Sampler), - ) - return ctx - } - } - ctx, span := trace.StartSpan(ctx, name, - trace.WithSpanKind(trace.SpanKindServer), - trace.WithSampler(s.StartOptions.Sampler)) - if haveParent { - span.AddLink(trace.Link{TraceID: parent.TraceID, SpanID: parent.SpanID, Type: trace.LinkTypeChild}) - } - return ctx -} - -func traceHandleRPC(ctx context.Context, rs stats.RPCStats) { - span := trace.FromContext(ctx) - // TODO: compressed and uncompressed sizes are not populated in every message. - switch rs := rs.(type) { - case *stats.Begin: - span.AddAttributes( - trace.BoolAttribute("Client", rs.Client), - trace.BoolAttribute("FailFast", rs.FailFast)) - case *stats.InPayload: - span.AddMessageReceiveEvent(0 /* TODO: messageID */, int64(rs.Length), int64(rs.WireLength)) - case *stats.OutPayload: - span.AddMessageSendEvent(0, int64(rs.Length), int64(rs.WireLength)) - case *stats.End: - if rs.Error != nil { - s, ok := status.FromError(rs.Error) - if ok { - span.SetStatus(trace.Status{Code: int32(s.Code()), Message: s.Message()}) - } else { - span.SetStatus(trace.Status{Code: int32(codes.Internal), Message: rs.Error.Error()}) - } - } - span.End() - } -} diff --git a/vendor/go.opencensus.io/resource/resource.go b/vendor/go.opencensus.io/resource/resource.go deleted file mode 100644 index b1764e1d3b..0000000000 --- a/vendor/go.opencensus.io/resource/resource.go +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package resource provides functionality for resource, which capture -// identifying information about the entities for which signals are exported. -package resource - -import ( - "context" - "fmt" - "os" - "regexp" - "sort" - "strconv" - "strings" -) - -// Environment variables used by FromEnv to decode a resource. -const ( - EnvVarType = "OC_RESOURCE_TYPE" - EnvVarLabels = "OC_RESOURCE_LABELS" -) - -// Resource describes an entity about which identifying information and metadata is exposed. -// For example, a type "k8s.io/container" may hold labels describing the pod name and namespace. -type Resource struct { - Type string - Labels map[string]string -} - -// EncodeLabels encodes a labels map to a string as provided via the OC_RESOURCE_LABELS environment variable. -func EncodeLabels(labels map[string]string) string { - sortedKeys := make([]string, 0, len(labels)) - for k := range labels { - sortedKeys = append(sortedKeys, k) - } - sort.Strings(sortedKeys) - - s := "" - for i, k := range sortedKeys { - if i > 0 { - s += "," - } - s += k + "=" + strconv.Quote(labels[k]) - } - return s -} - -var labelRegex = regexp.MustCompile(`^\s*([[:ascii:]]{1,256}?)=("[[:ascii:]]{0,256}?")\s*,`) - -// DecodeLabels decodes a serialized label map as used in the OC_RESOURCE_LABELS variable. -// A list of labels of the form `="",="",...` is accepted. -// Domain names and paths are accepted as label keys. -// Most users will want to use FromEnv instead. -func DecodeLabels(s string) (map[string]string, error) { - m := map[string]string{} - // Ensure a trailing comma, which allows us to keep the regex simpler - s = strings.TrimRight(strings.TrimSpace(s), ",") + "," - - for len(s) > 0 { - match := labelRegex.FindStringSubmatch(s) - if len(match) == 0 { - return nil, fmt.Errorf("invalid label formatting, remainder: %s", s) - } - v := match[2] - if v == "" { - v = match[3] - } else { - var err error - if v, err = strconv.Unquote(v); err != nil { - return nil, fmt.Errorf("invalid label formatting, remainder: %s, err: %s", s, err) - } - } - m[match[1]] = v - - s = s[len(match[0]):] - } - return m, nil -} - -// FromEnv is a detector that loads resource information from the OC_RESOURCE_TYPE -// and OC_RESOURCE_labelS environment variables. -func FromEnv(context.Context) (*Resource, error) { - res := &Resource{ - Type: strings.TrimSpace(os.Getenv(EnvVarType)), - } - labels := strings.TrimSpace(os.Getenv(EnvVarLabels)) - if labels == "" { - return res, nil - } - var err error - if res.Labels, err = DecodeLabels(labels); err != nil { - return nil, err - } - return res, nil -} - -var _ Detector = FromEnv - -// merge resource information from b into a. In case of a collision, a takes precedence. -func merge(a, b *Resource) *Resource { - if a == nil { - return b - } - if b == nil { - return a - } - res := &Resource{ - Type: a.Type, - Labels: map[string]string{}, - } - if res.Type == "" { - res.Type = b.Type - } - for k, v := range b.Labels { - res.Labels[k] = v - } - // Labels from resource a overwrite labels from resource b. - for k, v := range a.Labels { - res.Labels[k] = v - } - return res -} - -// Detector attempts to detect resource information. -// If the detector cannot find resource information, the returned resource is nil but no -// error is returned. -// An error is only returned on unexpected failures. -type Detector func(context.Context) (*Resource, error) - -// MultiDetector returns a Detector that calls all input detectors in order and -// merges each result with the previous one. In case a type of label key is already set, -// the first set value is takes precedence. -// It returns on the first error that a sub-detector encounters. -func MultiDetector(detectors ...Detector) Detector { - return func(ctx context.Context) (*Resource, error) { - return detectAll(ctx, detectors...) - } -} - -// detectall calls all input detectors sequentially an merges each result with the previous one. -// It returns on the first error that a sub-detector encounters. -func detectAll(ctx context.Context, detectors ...Detector) (*Resource, error) { - var res *Resource - for _, d := range detectors { - r, err := d(ctx) - if err != nil { - return nil, err - } - res = merge(res, r) - } - return res, nil -} diff --git a/vendor/go.opencensus.io/stats/doc.go b/vendor/go.opencensus.io/stats/doc.go deleted file mode 100644 index 31477a464f..0000000000 --- a/vendor/go.opencensus.io/stats/doc.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/* -Package stats contains support for OpenCensus stats recording. - -OpenCensus allows users to create typed measures, record measurements, -aggregate the collected data, and export the aggregated data. - -# Measures - -A measure represents a type of data point to be tracked and recorded. -For example, latency, request Mb/s, and response Mb/s are measures -to collect from a server. - -Measure constructors such as Int64 and Float64 automatically -register the measure by the given name. Each registered measure needs -to be unique by name. Measures also have a description and a unit. - -Libraries can define and export measures. Application authors can then -create views and collect and break down measures by the tags they are -interested in. - -# Recording measurements - -Measurement is a data point to be collected for a measure. For example, -for a latency (ms) measure, 100 is a measurement that represents a 100ms -latency event. Measurements are created from measures with -the current context. Tags from the current context are recorded with the -measurements if they are any. - -Recorded measurements are dropped immediately if no views are registered for them. -There is usually no need to conditionally enable and disable -recording to reduce cost. Recording of measurements is cheap. - -Libraries can always record measurements, and applications can later decide -on which measurements they want to collect by registering views. This allows -libraries to turn on the instrumentation by default. - -# Exemplars - -For a given recorded measurement, the associated exemplar is a diagnostic map -that gives more information about the measurement. - -When aggregated using a Distribution aggregation, an exemplar is kept for each -bucket in the Distribution. This allows you to easily find an example of a -measurement that fell into each bucket. - -For example, if you also use the OpenCensus trace package and you -record a measurement with a context that contains a sampled trace span, -then the trace span will be added to the exemplar associated with the measurement. - -When exported to a supporting back end, you should be able to easily navigate -to example traces that fell into each bucket in the Distribution. -*/ -package stats // import "go.opencensus.io/stats" diff --git a/vendor/go.opencensus.io/stats/internal/record.go b/vendor/go.opencensus.io/stats/internal/record.go deleted file mode 100644 index 436dc791f8..0000000000 --- a/vendor/go.opencensus.io/stats/internal/record.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package internal - -import ( - "go.opencensus.io/tag" -) - -// DefaultRecorder will be called for each Record call. -var DefaultRecorder func(tags *tag.Map, measurement interface{}, attachments map[string]interface{}) - -// MeasurementRecorder will be called for each Record call. This is the same as DefaultRecorder but -// avoids interface{} conversion. -// This will be a func(tags *tag.Map, measurement []Measurement, attachments map[string]interface{}) type, -// but is interface{} here to avoid import loops -var MeasurementRecorder interface{} - -// SubscriptionReporter reports when a view subscribed with a measure. -var SubscriptionReporter func(measure string) diff --git a/vendor/go.opencensus.io/stats/measure.go b/vendor/go.opencensus.io/stats/measure.go deleted file mode 100644 index 1ffd3cefc7..0000000000 --- a/vendor/go.opencensus.io/stats/measure.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package stats - -import ( - "sync" - "sync/atomic" -) - -// Measure represents a single numeric value to be tracked and recorded. -// For example, latency, request bytes, and response bytes could be measures -// to collect from a server. -// -// Measures by themselves have no outside effects. In order to be exported, -// the measure needs to be used in a View. If no Views are defined over a -// measure, there is very little cost in recording it. -type Measure interface { - // Name returns the name of this measure. - // - // Measure names are globally unique (among all libraries linked into your program). - // We recommend prefixing the measure name with a domain name relevant to your - // project or application. - // - // Measure names are never sent over the wire or exported to backends. - // They are only used to create Views. - Name() string - - // Description returns the human-readable description of this measure. - Description() string - - // Unit returns the units for the values this measure takes on. - // - // Units are encoded according to the case-sensitive abbreviations from the - // Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html - Unit() string -} - -// measureDescriptor is the untyped descriptor associated with each measure. -// Int64Measure and Float64Measure wrap measureDescriptor to provide typed -// recording APIs. -// Two Measures with the same name will have the same measureDescriptor. -type measureDescriptor struct { - subs int32 // access atomically - - name string - description string - unit string -} - -func (m *measureDescriptor) subscribe() { - atomic.StoreInt32(&m.subs, 1) -} - -func (m *measureDescriptor) subscribed() bool { - return atomic.LoadInt32(&m.subs) == 1 -} - -var ( - mu sync.RWMutex - measures = make(map[string]*measureDescriptor) -) - -func registerMeasureHandle(name, desc, unit string) *measureDescriptor { - mu.Lock() - defer mu.Unlock() - - if stored, ok := measures[name]; ok { - return stored - } - m := &measureDescriptor{ - name: name, - description: desc, - unit: unit, - } - measures[name] = m - return m -} - -// Measurement is the numeric value measured when recording stats. Each measure -// provides methods to create measurements of their kind. For example, Int64Measure -// provides M to convert an int64 into a measurement. -type Measurement struct { - v float64 - m Measure - desc *measureDescriptor -} - -// Value returns the value of the Measurement as a float64. -func (m Measurement) Value() float64 { - return m.v -} - -// Measure returns the Measure from which this Measurement was created. -func (m Measurement) Measure() Measure { - return m.m -} diff --git a/vendor/go.opencensus.io/stats/measure_float64.go b/vendor/go.opencensus.io/stats/measure_float64.go deleted file mode 100644 index f02c1eda84..0000000000 --- a/vendor/go.opencensus.io/stats/measure_float64.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package stats - -// Float64Measure is a measure for float64 values. -type Float64Measure struct { - desc *measureDescriptor -} - -// M creates a new float64 measurement. -// Use Record to record measurements. -func (m *Float64Measure) M(v float64) Measurement { - return Measurement{ - m: m, - desc: m.desc, - v: v, - } -} - -// Float64 creates a new measure for float64 values. -// -// See the documentation for interface Measure for more guidance on the -// parameters of this function. -func Float64(name, description, unit string) *Float64Measure { - mi := registerMeasureHandle(name, description, unit) - return &Float64Measure{mi} -} - -// Name returns the name of the measure. -func (m *Float64Measure) Name() string { - return m.desc.name -} - -// Description returns the description of the measure. -func (m *Float64Measure) Description() string { - return m.desc.description -} - -// Unit returns the unit of the measure. -func (m *Float64Measure) Unit() string { - return m.desc.unit -} diff --git a/vendor/go.opencensus.io/stats/measure_int64.go b/vendor/go.opencensus.io/stats/measure_int64.go deleted file mode 100644 index d101d79735..0000000000 --- a/vendor/go.opencensus.io/stats/measure_int64.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package stats - -// Int64Measure is a measure for int64 values. -type Int64Measure struct { - desc *measureDescriptor -} - -// M creates a new int64 measurement. -// Use Record to record measurements. -func (m *Int64Measure) M(v int64) Measurement { - return Measurement{ - m: m, - desc: m.desc, - v: float64(v), - } -} - -// Int64 creates a new measure for int64 values. -// -// See the documentation for interface Measure for more guidance on the -// parameters of this function. -func Int64(name, description, unit string) *Int64Measure { - mi := registerMeasureHandle(name, description, unit) - return &Int64Measure{mi} -} - -// Name returns the name of the measure. -func (m *Int64Measure) Name() string { - return m.desc.name -} - -// Description returns the description of the measure. -func (m *Int64Measure) Description() string { - return m.desc.description -} - -// Unit returns the unit of the measure. -func (m *Int64Measure) Unit() string { - return m.desc.unit -} diff --git a/vendor/go.opencensus.io/stats/record.go b/vendor/go.opencensus.io/stats/record.go deleted file mode 100644 index 8b5b99803c..0000000000 --- a/vendor/go.opencensus.io/stats/record.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package stats - -import ( - "context" - - "go.opencensus.io/metric/metricdata" - "go.opencensus.io/stats/internal" - "go.opencensus.io/tag" -) - -func init() { - internal.SubscriptionReporter = func(measure string) { - mu.Lock() - measures[measure].subscribe() - mu.Unlock() - } -} - -// Recorder provides an interface for exporting measurement information from -// the static Record method by using the WithRecorder option. -type Recorder interface { - // Record records a set of measurements associated with the given tags and attachments. - // The second argument is a `[]Measurement`. - Record(*tag.Map, interface{}, map[string]interface{}) -} - -type recordOptions struct { - attachments metricdata.Attachments - mutators []tag.Mutator - measurements []Measurement - recorder Recorder -} - -// WithAttachments applies provided exemplar attachments. -func WithAttachments(attachments metricdata.Attachments) Options { - return func(ro *recordOptions) { - ro.attachments = attachments - } -} - -// WithTags applies provided tag mutators. -func WithTags(mutators ...tag.Mutator) Options { - return func(ro *recordOptions) { - ro.mutators = mutators - } -} - -// WithMeasurements applies provided measurements. -func WithMeasurements(measurements ...Measurement) Options { - return func(ro *recordOptions) { - ro.measurements = measurements - } -} - -// WithRecorder records the measurements to the specified `Recorder`, rather -// than to the global metrics recorder. -func WithRecorder(meter Recorder) Options { - return func(ro *recordOptions) { - ro.recorder = meter - } -} - -// Options apply changes to recordOptions. -type Options func(*recordOptions) - -func createRecordOption(ros ...Options) *recordOptions { - o := &recordOptions{} - for _, ro := range ros { - ro(o) - } - return o -} - -type measurementRecorder = func(tags *tag.Map, measurement []Measurement, attachments map[string]interface{}) - -// Record records one or multiple measurements with the same context at once. -// If there are any tags in the context, measurements will be tagged with them. -func Record(ctx context.Context, ms ...Measurement) { - // Record behaves the same as RecordWithOptions, but because we do not have to handle generic functionality - // (RecordOptions) we can reduce some allocations to speed up this hot path - if len(ms) == 0 { - return - } - recorder := internal.MeasurementRecorder.(measurementRecorder) - record := false - for _, m := range ms { - if m.desc.subscribed() { - record = true - break - } - } - if !record { - return - } - recorder(tag.FromContext(ctx), ms, nil) - return -} - -// RecordWithTags records one or multiple measurements at once. -// -// Measurements will be tagged with the tags in the context mutated by the mutators. -// RecordWithTags is useful if you want to record with tag mutations but don't want -// to propagate the mutations in the context. -func RecordWithTags(ctx context.Context, mutators []tag.Mutator, ms ...Measurement) error { - return RecordWithOptions(ctx, WithTags(mutators...), WithMeasurements(ms...)) -} - -// RecordWithOptions records measurements from the given options (if any) against context -// and tags and attachments in the options (if any). -// If there are any tags in the context, measurements will be tagged with them. -func RecordWithOptions(ctx context.Context, ros ...Options) error { - o := createRecordOption(ros...) - if len(o.measurements) == 0 { - return nil - } - recorder := internal.DefaultRecorder - if o.recorder != nil { - recorder = o.recorder.Record - } - if recorder == nil { - return nil - } - record := false - for _, m := range o.measurements { - if m.desc.subscribed() { - record = true - break - } - } - if !record { - return nil - } - if len(o.mutators) > 0 { - var err error - if ctx, err = tag.New(ctx, o.mutators...); err != nil { - return err - } - } - recorder(tag.FromContext(ctx), o.measurements, o.attachments) - return nil -} diff --git a/vendor/go.opencensus.io/stats/units.go b/vendor/go.opencensus.io/stats/units.go deleted file mode 100644 index 736399652c..0000000000 --- a/vendor/go.opencensus.io/stats/units.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package stats - -// Units are encoded according to the case-sensitive abbreviations from the -// Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html -const ( - UnitNone = "1" // Deprecated: Use UnitDimensionless. - UnitDimensionless = "1" - UnitBytes = "By" - UnitMilliseconds = "ms" - UnitSeconds = "s" -) diff --git a/vendor/go.opencensus.io/stats/view/aggregation.go b/vendor/go.opencensus.io/stats/view/aggregation.go deleted file mode 100644 index 61f72d20da..0000000000 --- a/vendor/go.opencensus.io/stats/view/aggregation.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package view - -import "time" - -// AggType represents the type of aggregation function used on a View. -type AggType int - -// All available aggregation types. -const ( - AggTypeNone AggType = iota // no aggregation; reserved for future use. - AggTypeCount // the count aggregation, see Count. - AggTypeSum // the sum aggregation, see Sum. - AggTypeDistribution // the distribution aggregation, see Distribution. - AggTypeLastValue // the last value aggregation, see LastValue. -) - -func (t AggType) String() string { - return aggTypeName[t] -} - -var aggTypeName = map[AggType]string{ - AggTypeNone: "None", - AggTypeCount: "Count", - AggTypeSum: "Sum", - AggTypeDistribution: "Distribution", - AggTypeLastValue: "LastValue", -} - -// Aggregation represents a data aggregation method. Use one of the functions: -// Count, Sum, or Distribution to construct an Aggregation. -type Aggregation struct { - Type AggType // Type is the AggType of this Aggregation. - Buckets []float64 // Buckets are the bucket endpoints if this Aggregation represents a distribution, see Distribution. - - newData func(time.Time) AggregationData -} - -var ( - aggCount = &Aggregation{ - Type: AggTypeCount, - newData: func(t time.Time) AggregationData { - return &CountData{Start: t} - }, - } - aggSum = &Aggregation{ - Type: AggTypeSum, - newData: func(t time.Time) AggregationData { - return &SumData{Start: t} - }, - } -) - -// Count indicates that data collected and aggregated -// with this method will be turned into a count value. -// For example, total number of accepted requests can be -// aggregated by using Count. -func Count() *Aggregation { - return aggCount -} - -// Sum indicates that data collected and aggregated -// with this method will be summed up. -// For example, accumulated request bytes can be aggregated by using -// Sum. -func Sum() *Aggregation { - return aggSum -} - -// Distribution indicates that the desired aggregation is -// a histogram distribution. -// -// A distribution aggregation may contain a histogram of the values in the -// population. The bucket boundaries for that histogram are described -// by the bounds. This defines len(bounds)+1 buckets. -// -// If len(bounds) >= 2 then the boundaries for bucket index i are: -// -// [-infinity, bounds[i]) for i = 0 -// [bounds[i-1], bounds[i]) for 0 < i < length -// [bounds[i-1], +infinity) for i = length -// -// If len(bounds) is 0 then there is no histogram associated with the -// distribution. There will be a single bucket with boundaries -// (-infinity, +infinity). -// -// If len(bounds) is 1 then there is no finite buckets, and that single -// element is the common boundary of the overflow and underflow buckets. -func Distribution(bounds ...float64) *Aggregation { - agg := &Aggregation{ - Type: AggTypeDistribution, - Buckets: bounds, - } - agg.newData = func(t time.Time) AggregationData { - return newDistributionData(agg, t) - } - return agg -} - -// LastValue only reports the last value recorded using this -// aggregation. All other measurements will be dropped. -func LastValue() *Aggregation { - return &Aggregation{ - Type: AggTypeLastValue, - newData: func(_ time.Time) AggregationData { - return &LastValueData{} - }, - } -} diff --git a/vendor/go.opencensus.io/stats/view/aggregation_data.go b/vendor/go.opencensus.io/stats/view/aggregation_data.go deleted file mode 100644 index d93b520662..0000000000 --- a/vendor/go.opencensus.io/stats/view/aggregation_data.go +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package view - -import ( - "math" - "time" - - "go.opencensus.io/metric/metricdata" -) - -// AggregationData represents an aggregated value from a collection. -// They are reported on the view data during exporting. -// Mosts users won't directly access aggregration data. -type AggregationData interface { - isAggregationData() bool - addSample(v float64, attachments map[string]interface{}, t time.Time) - clone() AggregationData - equal(other AggregationData) bool - toPoint(t metricdata.Type, time time.Time) metricdata.Point - StartTime() time.Time -} - -const epsilon = 1e-9 - -// CountData is the aggregated data for the Count aggregation. -// A count aggregation processes data and counts the recordings. -// -// Most users won't directly access count data. -type CountData struct { - Start time.Time - Value int64 -} - -func (a *CountData) isAggregationData() bool { return true } - -func (a *CountData) addSample(_ float64, _ map[string]interface{}, _ time.Time) { - a.Value = a.Value + 1 -} - -func (a *CountData) clone() AggregationData { - return &CountData{Value: a.Value, Start: a.Start} -} - -func (a *CountData) equal(other AggregationData) bool { - a2, ok := other.(*CountData) - if !ok { - return false - } - - return a.Start.Equal(a2.Start) && a.Value == a2.Value -} - -func (a *CountData) toPoint(metricType metricdata.Type, t time.Time) metricdata.Point { - switch metricType { - case metricdata.TypeCumulativeInt64: - return metricdata.NewInt64Point(t, a.Value) - default: - panic("unsupported metricdata.Type") - } -} - -// StartTime returns the start time of the data being aggregated by CountData. -func (a *CountData) StartTime() time.Time { - return a.Start -} - -// SumData is the aggregated data for the Sum aggregation. -// A sum aggregation processes data and sums up the recordings. -// -// Most users won't directly access sum data. -type SumData struct { - Start time.Time - Value float64 -} - -func (a *SumData) isAggregationData() bool { return true } - -func (a *SumData) addSample(v float64, _ map[string]interface{}, _ time.Time) { - a.Value += v -} - -func (a *SumData) clone() AggregationData { - return &SumData{Value: a.Value, Start: a.Start} -} - -func (a *SumData) equal(other AggregationData) bool { - a2, ok := other.(*SumData) - if !ok { - return false - } - return a.Start.Equal(a2.Start) && math.Pow(a.Value-a2.Value, 2) < epsilon -} - -func (a *SumData) toPoint(metricType metricdata.Type, t time.Time) metricdata.Point { - switch metricType { - case metricdata.TypeCumulativeInt64: - return metricdata.NewInt64Point(t, int64(a.Value)) - case metricdata.TypeCumulativeFloat64: - return metricdata.NewFloat64Point(t, a.Value) - default: - panic("unsupported metricdata.Type") - } -} - -// StartTime returns the start time of the data being aggregated by SumData. -func (a *SumData) StartTime() time.Time { - return a.Start -} - -// DistributionData is the aggregated data for the -// Distribution aggregation. -// -// Most users won't directly access distribution data. -// -// For a distribution with N bounds, the associated DistributionData will have -// N+1 buckets. -type DistributionData struct { - Count int64 // number of data points aggregated - Min float64 // minimum value in the distribution - Max float64 // max value in the distribution - Mean float64 // mean of the distribution - SumOfSquaredDev float64 // sum of the squared deviation from the mean - CountPerBucket []int64 // number of occurrences per bucket - // ExemplarsPerBucket is slice the same length as CountPerBucket containing - // an exemplar for the associated bucket, or nil. - ExemplarsPerBucket []*metricdata.Exemplar - bounds []float64 // histogram distribution of the values - Start time.Time -} - -func newDistributionData(agg *Aggregation, t time.Time) *DistributionData { - bucketCount := len(agg.Buckets) + 1 - return &DistributionData{ - CountPerBucket: make([]int64, bucketCount), - ExemplarsPerBucket: make([]*metricdata.Exemplar, bucketCount), - bounds: agg.Buckets, - Min: math.MaxFloat64, - Max: math.SmallestNonzeroFloat64, - Start: t, - } -} - -// Sum returns the sum of all samples collected. -func (a *DistributionData) Sum() float64 { return a.Mean * float64(a.Count) } - -func (a *DistributionData) variance() float64 { - if a.Count <= 1 { - return 0 - } - return a.SumOfSquaredDev / float64(a.Count-1) -} - -func (a *DistributionData) isAggregationData() bool { return true } - -// TODO(songy23): support exemplar attachments. -func (a *DistributionData) addSample(v float64, attachments map[string]interface{}, t time.Time) { - if v < a.Min { - a.Min = v - } - if v > a.Max { - a.Max = v - } - a.Count++ - a.addToBucket(v, attachments, t) - - if a.Count == 1 { - a.Mean = v - return - } - - oldMean := a.Mean - a.Mean = a.Mean + (v-a.Mean)/float64(a.Count) - a.SumOfSquaredDev = a.SumOfSquaredDev + (v-oldMean)*(v-a.Mean) -} - -func (a *DistributionData) addToBucket(v float64, attachments map[string]interface{}, t time.Time) { - var count *int64 - var i int - var b float64 - for i, b = range a.bounds { - if v < b { - count = &a.CountPerBucket[i] - break - } - } - if count == nil { // Last bucket. - i = len(a.bounds) - count = &a.CountPerBucket[i] - } - *count++ - if exemplar := getExemplar(v, attachments, t); exemplar != nil { - a.ExemplarsPerBucket[i] = exemplar - } -} - -func getExemplar(v float64, attachments map[string]interface{}, t time.Time) *metricdata.Exemplar { - if len(attachments) == 0 { - return nil - } - return &metricdata.Exemplar{ - Value: v, - Timestamp: t, - Attachments: attachments, - } -} - -func (a *DistributionData) clone() AggregationData { - c := *a - c.CountPerBucket = append([]int64(nil), a.CountPerBucket...) - c.ExemplarsPerBucket = append([]*metricdata.Exemplar(nil), a.ExemplarsPerBucket...) - return &c -} - -func (a *DistributionData) equal(other AggregationData) bool { - a2, ok := other.(*DistributionData) - if !ok { - return false - } - if a2 == nil { - return false - } - if len(a.CountPerBucket) != len(a2.CountPerBucket) { - return false - } - for i := range a.CountPerBucket { - if a.CountPerBucket[i] != a2.CountPerBucket[i] { - return false - } - } - return a.Start.Equal(a2.Start) && - a.Count == a2.Count && - a.Min == a2.Min && - a.Max == a2.Max && - math.Pow(a.Mean-a2.Mean, 2) < epsilon && math.Pow(a.variance()-a2.variance(), 2) < epsilon -} - -func (a *DistributionData) toPoint(metricType metricdata.Type, t time.Time) metricdata.Point { - switch metricType { - case metricdata.TypeCumulativeDistribution: - buckets := []metricdata.Bucket{} - for i := 0; i < len(a.CountPerBucket); i++ { - buckets = append(buckets, metricdata.Bucket{ - Count: a.CountPerBucket[i], - Exemplar: a.ExemplarsPerBucket[i], - }) - } - bucketOptions := &metricdata.BucketOptions{Bounds: a.bounds} - - val := &metricdata.Distribution{ - Count: a.Count, - Sum: a.Sum(), - SumOfSquaredDeviation: a.SumOfSquaredDev, - BucketOptions: bucketOptions, - Buckets: buckets, - } - return metricdata.NewDistributionPoint(t, val) - - default: - // TODO: [rghetia] when we have a use case for TypeGaugeDistribution. - panic("unsupported metricdata.Type") - } -} - -// StartTime returns the start time of the data being aggregated by DistributionData. -func (a *DistributionData) StartTime() time.Time { - return a.Start -} - -// LastValueData returns the last value recorded for LastValue aggregation. -type LastValueData struct { - Value float64 -} - -func (l *LastValueData) isAggregationData() bool { - return true -} - -func (l *LastValueData) addSample(v float64, _ map[string]interface{}, _ time.Time) { - l.Value = v -} - -func (l *LastValueData) clone() AggregationData { - return &LastValueData{l.Value} -} - -func (l *LastValueData) equal(other AggregationData) bool { - a2, ok := other.(*LastValueData) - if !ok { - return false - } - return l.Value == a2.Value -} - -func (l *LastValueData) toPoint(metricType metricdata.Type, t time.Time) metricdata.Point { - switch metricType { - case metricdata.TypeGaugeInt64: - return metricdata.NewInt64Point(t, int64(l.Value)) - case metricdata.TypeGaugeFloat64: - return metricdata.NewFloat64Point(t, l.Value) - default: - panic("unsupported metricdata.Type") - } -} - -// StartTime returns an empty time value as start time is not recorded when using last value -// aggregation. -func (l *LastValueData) StartTime() time.Time { - return time.Time{} -} - -// ClearStart clears the Start field from data if present. Useful for testing in cases where the -// start time will be nondeterministic. -func ClearStart(data AggregationData) { - switch data := data.(type) { - case *CountData: - data.Start = time.Time{} - case *SumData: - data.Start = time.Time{} - case *DistributionData: - data.Start = time.Time{} - } -} diff --git a/vendor/go.opencensus.io/stats/view/collector.go b/vendor/go.opencensus.io/stats/view/collector.go deleted file mode 100644 index bcd6e08c74..0000000000 --- a/vendor/go.opencensus.io/stats/view/collector.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package view - -import ( - "sort" - "time" - - "go.opencensus.io/internal/tagencoding" - "go.opencensus.io/tag" -) - -type collector struct { - // signatures holds the aggregations values for each unique tag signature - // (values for all keys) to its aggregator. - signatures map[string]AggregationData - // Aggregation is the description of the aggregation to perform for this - // view. - a *Aggregation -} - -func (c *collector) addSample(s string, v float64, attachments map[string]interface{}, t time.Time) { - aggregator, ok := c.signatures[s] - if !ok { - aggregator = c.a.newData(t) - c.signatures[s] = aggregator - } - aggregator.addSample(v, attachments, t) -} - -// collectRows returns a snapshot of the collected Row values. -func (c *collector) collectedRows(keys []tag.Key) []*Row { - rows := make([]*Row, 0, len(c.signatures)) - for sig, aggregator := range c.signatures { - tags := decodeTags([]byte(sig), keys) - row := &Row{Tags: tags, Data: aggregator.clone()} - rows = append(rows, row) - } - return rows -} - -func (c *collector) clearRows() { - c.signatures = make(map[string]AggregationData) -} - -// encodeWithKeys encodes the map by using values -// only associated with the keys provided. -func encodeWithKeys(m *tag.Map, keys []tag.Key) []byte { - // Compute the buffer length we will need ahead of time to avoid resizing later - reqLen := 0 - for _, k := range keys { - s, _ := m.Value(k) - // We will store each key + its length - reqLen += len(s) + 1 - } - vb := &tagencoding.Values{ - Buffer: make([]byte, reqLen), - } - for _, k := range keys { - v, _ := m.Value(k) - vb.WriteValue([]byte(v)) - } - return vb.Bytes() -} - -// decodeTags decodes tags from the buffer and -// orders them by the keys. -func decodeTags(buf []byte, keys []tag.Key) []tag.Tag { - vb := &tagencoding.Values{Buffer: buf} - var tags []tag.Tag - for _, k := range keys { - v := vb.ReadValue() - if v != nil { - tags = append(tags, tag.Tag{Key: k, Value: string(v)}) - } - } - vb.ReadIndex = 0 - sort.Slice(tags, func(i, j int) bool { return tags[i].Key.Name() < tags[j].Key.Name() }) - return tags -} diff --git a/vendor/go.opencensus.io/stats/view/doc.go b/vendor/go.opencensus.io/stats/view/doc.go deleted file mode 100644 index 60bf0e3925..0000000000 --- a/vendor/go.opencensus.io/stats/view/doc.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -// Package view contains support for collecting and exposing aggregates over stats. -// -// In order to collect measurements, views need to be defined and registered. -// A view allows recorded measurements to be filtered and aggregated. -// -// All recorded measurements can be grouped by a list of tags. -// -// OpenCensus provides several aggregation methods: Count, Distribution and Sum. -// -// Count only counts the number of measurement points recorded. -// Distribution provides statistical summary of the aggregated data by counting -// how many recorded measurements fall into each bucket. -// Sum adds up the measurement values. -// LastValue just keeps track of the most recently recorded measurement value. -// All aggregations are cumulative. -// -// Views can be registered and unregistered at any time during program execution. -// -// Libraries can define views but it is recommended that in most cases registering -// views be left up to applications. -// -// # Exporting -// -// Collected and aggregated data can be exported to a metric collection -// backend by registering its exporter. -// -// Multiple exporters can be registered to upload the data to various -// different back ends. -package view // import "go.opencensus.io/stats/view" - -// TODO(acetechnologist): Add a link to the language independent OpenCensus -// spec when it is available. diff --git a/vendor/go.opencensus.io/stats/view/export.go b/vendor/go.opencensus.io/stats/view/export.go deleted file mode 100644 index 73ba11f5b6..0000000000 --- a/vendor/go.opencensus.io/stats/view/export.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package view - -// Exporter exports the collected records as view data. -// -// The ExportView method should return quickly; if an -// Exporter takes a significant amount of time to -// process a Data, that work should be done on another goroutine. -// -// It is safe to assume that ExportView will not be called concurrently from -// multiple goroutines. -// -// The Data should not be modified. -type Exporter interface { - ExportView(viewData *Data) -} - -// RegisterExporter registers an exporter. -// Collected data will be reported via all the -// registered exporters. Once you no longer -// want data to be exported, invoke UnregisterExporter -// with the previously registered exporter. -// -// Binaries can register exporters, libraries shouldn't register exporters. -func RegisterExporter(e Exporter) { - defaultWorker.RegisterExporter(e) -} - -// UnregisterExporter unregisters an exporter. -func UnregisterExporter(e Exporter) { - defaultWorker.UnregisterExporter(e) -} diff --git a/vendor/go.opencensus.io/stats/view/view.go b/vendor/go.opencensus.io/stats/view/view.go deleted file mode 100644 index 293b54ecbe..0000000000 --- a/vendor/go.opencensus.io/stats/view/view.go +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package view - -import ( - "bytes" - "errors" - "fmt" - "reflect" - "sort" - "sync/atomic" - "time" - - "go.opencensus.io/metric/metricdata" - "go.opencensus.io/stats" - "go.opencensus.io/tag" -) - -// View allows users to aggregate the recorded stats.Measurements. -// Views need to be passed to the Register function before data will be -// collected and sent to Exporters. -type View struct { - Name string // Name of View. Must be unique. If unset, will default to the name of the Measure. - Description string // Description is a human-readable description for this view. - - // TagKeys are the tag keys describing the grouping of this view. - // A single Row will be produced for each combination of associated tag values. - TagKeys []tag.Key - - // Measure is a stats.Measure to aggregate in this view. - Measure stats.Measure - - // Aggregation is the aggregation function to apply to the set of Measurements. - Aggregation *Aggregation -} - -// WithName returns a copy of the View with a new name. This is useful for -// renaming views to cope with limitations placed on metric names by various -// backends. -func (v *View) WithName(name string) *View { - vNew := *v - vNew.Name = name - return &vNew -} - -// same compares two views and returns true if they represent the same aggregation. -func (v *View) same(other *View) bool { - if v == other { - return true - } - if v == nil { - return false - } - return reflect.DeepEqual(v.Aggregation, other.Aggregation) && - v.Measure.Name() == other.Measure.Name() -} - -// ErrNegativeBucketBounds error returned if histogram contains negative bounds. -// -// Deprecated: this should not be public. -var ErrNegativeBucketBounds = errors.New("negative bucket bounds not supported") - -// canonicalize canonicalizes v by setting explicit -// defaults for Name and Description and sorting the TagKeys -func (v *View) canonicalize() error { - if v.Measure == nil { - return fmt.Errorf("cannot register view %q: measure not set", v.Name) - } - if v.Aggregation == nil { - return fmt.Errorf("cannot register view %q: aggregation not set", v.Name) - } - if v.Name == "" { - v.Name = v.Measure.Name() - } - if v.Description == "" { - v.Description = v.Measure.Description() - } - if err := checkViewName(v.Name); err != nil { - return err - } - sort.Slice(v.TagKeys, func(i, j int) bool { - return v.TagKeys[i].Name() < v.TagKeys[j].Name() - }) - sort.Float64s(v.Aggregation.Buckets) - for _, b := range v.Aggregation.Buckets { - if b < 0 { - return ErrNegativeBucketBounds - } - } - // drop 0 bucket silently. - v.Aggregation.Buckets = dropZeroBounds(v.Aggregation.Buckets...) - - return nil -} - -func dropZeroBounds(bounds ...float64) []float64 { - for i, bound := range bounds { - if bound > 0 { - return bounds[i:] - } - } - return []float64{} -} - -// viewInternal is the internal representation of a View. -type viewInternal struct { - view *View // view is the canonicalized View definition associated with this view. - subscribed uint32 // 1 if someone is subscribed and data need to be exported, use atomic to access - collector *collector - metricDescriptor *metricdata.Descriptor -} - -func newViewInternal(v *View) (*viewInternal, error) { - return &viewInternal{ - view: v, - collector: &collector{make(map[string]AggregationData), v.Aggregation}, - metricDescriptor: viewToMetricDescriptor(v), - }, nil -} - -func (v *viewInternal) subscribe() { - atomic.StoreUint32(&v.subscribed, 1) -} - -func (v *viewInternal) unsubscribe() { - atomic.StoreUint32(&v.subscribed, 0) -} - -// isSubscribed returns true if the view is exporting -// data by subscription. -func (v *viewInternal) isSubscribed() bool { - return atomic.LoadUint32(&v.subscribed) == 1 -} - -func (v *viewInternal) clearRows() { - v.collector.clearRows() -} - -func (v *viewInternal) collectedRows() []*Row { - return v.collector.collectedRows(v.view.TagKeys) -} - -func (v *viewInternal) addSample(m *tag.Map, val float64, attachments map[string]interface{}, t time.Time) { - if !v.isSubscribed() { - return - } - sig := string(encodeWithKeys(m, v.view.TagKeys)) - v.collector.addSample(sig, val, attachments, t) -} - -// A Data is a set of rows about usage of the single measure associated -// with the given view. Each row is specific to a unique set of tags. -type Data struct { - View *View - Start, End time.Time - Rows []*Row -} - -// Row is the collected value for a specific set of key value pairs a.k.a tags. -type Row struct { - Tags []tag.Tag - Data AggregationData -} - -func (r *Row) String() string { - var buffer bytes.Buffer - buffer.WriteString("{ ") - buffer.WriteString("{ ") - for _, t := range r.Tags { - buffer.WriteString(fmt.Sprintf("{%v %v}", t.Key.Name(), t.Value)) - } - buffer.WriteString(" }") - buffer.WriteString(fmt.Sprintf("%v", r.Data)) - buffer.WriteString(" }") - return buffer.String() -} - -// Equal returns true if both rows are equal. Tags are expected to be ordered -// by the key name. Even if both rows have the same tags but the tags appear in -// different orders it will return false. -func (r *Row) Equal(other *Row) bool { - if r == other { - return true - } - return reflect.DeepEqual(r.Tags, other.Tags) && r.Data.equal(other.Data) -} - -const maxNameLength = 255 - -// Returns true if the given string contains only printable characters. -func isPrintable(str string) bool { - for _, r := range str { - if !(r >= ' ' && r <= '~') { - return false - } - } - return true -} - -func checkViewName(name string) error { - if len(name) > maxNameLength { - return fmt.Errorf("view name cannot be larger than %v", maxNameLength) - } - if !isPrintable(name) { - return fmt.Errorf("view name needs to be an ASCII string") - } - return nil -} diff --git a/vendor/go.opencensus.io/stats/view/view_to_metric.go b/vendor/go.opencensus.io/stats/view/view_to_metric.go deleted file mode 100644 index 57d615ec7e..0000000000 --- a/vendor/go.opencensus.io/stats/view/view_to_metric.go +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2019, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package view - -import ( - "time" - - "go.opencensus.io/resource" - - "go.opencensus.io/metric/metricdata" - "go.opencensus.io/stats" -) - -func getUnit(unit string) metricdata.Unit { - switch unit { - case "1": - return metricdata.UnitDimensionless - case "ms": - return metricdata.UnitMilliseconds - case "By": - return metricdata.UnitBytes - } - return metricdata.UnitDimensionless -} - -func getType(v *View) metricdata.Type { - m := v.Measure - agg := v.Aggregation - - switch agg.Type { - case AggTypeSum: - switch m.(type) { - case *stats.Int64Measure: - return metricdata.TypeCumulativeInt64 - case *stats.Float64Measure: - return metricdata.TypeCumulativeFloat64 - default: - panic("unexpected measure type") - } - case AggTypeDistribution: - return metricdata.TypeCumulativeDistribution - case AggTypeLastValue: - switch m.(type) { - case *stats.Int64Measure: - return metricdata.TypeGaugeInt64 - case *stats.Float64Measure: - return metricdata.TypeGaugeFloat64 - default: - panic("unexpected measure type") - } - case AggTypeCount: - switch m.(type) { - case *stats.Int64Measure: - return metricdata.TypeCumulativeInt64 - case *stats.Float64Measure: - return metricdata.TypeCumulativeInt64 - default: - panic("unexpected measure type") - } - default: - panic("unexpected aggregation type") - } -} - -func getLabelKeys(v *View) []metricdata.LabelKey { - labelKeys := []metricdata.LabelKey{} - for _, k := range v.TagKeys { - labelKeys = append(labelKeys, metricdata.LabelKey{Key: k.Name()}) - } - return labelKeys -} - -func viewToMetricDescriptor(v *View) *metricdata.Descriptor { - return &metricdata.Descriptor{ - Name: v.Name, - Description: v.Description, - Unit: convertUnit(v), - Type: getType(v), - LabelKeys: getLabelKeys(v), - } -} - -func convertUnit(v *View) metricdata.Unit { - switch v.Aggregation.Type { - case AggTypeCount: - return metricdata.UnitDimensionless - default: - return getUnit(v.Measure.Unit()) - } -} - -func toLabelValues(row *Row, expectedKeys []metricdata.LabelKey) []metricdata.LabelValue { - labelValues := []metricdata.LabelValue{} - tagMap := make(map[string]string) - for _, tag := range row.Tags { - tagMap[tag.Key.Name()] = tag.Value - } - - for _, key := range expectedKeys { - if val, ok := tagMap[key.Key]; ok { - labelValues = append(labelValues, metricdata.NewLabelValue(val)) - } else { - labelValues = append(labelValues, metricdata.LabelValue{}) - } - } - return labelValues -} - -func rowToTimeseries(v *viewInternal, row *Row, now time.Time) *metricdata.TimeSeries { - return &metricdata.TimeSeries{ - Points: []metricdata.Point{row.Data.toPoint(v.metricDescriptor.Type, now)}, - LabelValues: toLabelValues(row, v.metricDescriptor.LabelKeys), - StartTime: row.Data.StartTime(), - } -} - -func viewToMetric(v *viewInternal, r *resource.Resource, now time.Time) *metricdata.Metric { - rows := v.collectedRows() - if len(rows) == 0 { - return nil - } - - ts := []*metricdata.TimeSeries{} - for _, row := range rows { - ts = append(ts, rowToTimeseries(v, row, now)) - } - - m := &metricdata.Metric{ - Descriptor: *v.metricDescriptor, - TimeSeries: ts, - Resource: r, - } - return m -} diff --git a/vendor/go.opencensus.io/stats/view/worker.go b/vendor/go.opencensus.io/stats/view/worker.go deleted file mode 100644 index 6a79cd8a34..0000000000 --- a/vendor/go.opencensus.io/stats/view/worker.go +++ /dev/null @@ -1,424 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package view - -import ( - "fmt" - "sync" - "time" - - "go.opencensus.io/resource" - - "go.opencensus.io/metric/metricdata" - "go.opencensus.io/metric/metricproducer" - "go.opencensus.io/stats" - "go.opencensus.io/stats/internal" - "go.opencensus.io/tag" -) - -func init() { - defaultWorker = NewMeter().(*worker) - go defaultWorker.start() - internal.DefaultRecorder = record - internal.MeasurementRecorder = recordMeasurement -} - -type measureRef struct { - measure string - views map[*viewInternal]struct{} -} - -type worker struct { - measures map[string]*measureRef - views map[string]*viewInternal - viewStartTimes map[*viewInternal]time.Time - - timer *time.Ticker - c chan command - quit, done chan bool - mu sync.RWMutex - r *resource.Resource - - exportersMu sync.RWMutex - exporters map[Exporter]struct{} -} - -// Meter defines an interface which allows a single process to maintain -// multiple sets of metrics exports (intended for the advanced case where a -// single process wants to report metrics about multiple objects, such as -// multiple databases or HTTP services). -// -// Note that this is an advanced use case, and the static functions in this -// module should cover the common use cases. -type Meter interface { - stats.Recorder - // Find returns a registered view associated with this name. - // If no registered view is found, nil is returned. - Find(name string) *View - // Register begins collecting data for the given views. - // Once a view is registered, it reports data to the registered exporters. - Register(views ...*View) error - // Unregister the given views. Data will not longer be exported for these views - // after Unregister returns. - // It is not necessary to unregister from views you expect to collect for the - // duration of your program execution. - Unregister(views ...*View) - // SetReportingPeriod sets the interval between reporting aggregated views in - // the program. If duration is less than or equal to zero, it enables the - // default behavior. - // - // Note: each exporter makes different promises about what the lowest supported - // duration is. For example, the Stackdriver exporter recommends a value no - // lower than 1 minute. Consult each exporter per your needs. - SetReportingPeriod(time.Duration) - - // RegisterExporter registers an exporter. - // Collected data will be reported via all the - // registered exporters. Once you no longer - // want data to be exported, invoke UnregisterExporter - // with the previously registered exporter. - // - // Binaries can register exporters, libraries shouldn't register exporters. - RegisterExporter(Exporter) - // UnregisterExporter unregisters an exporter. - UnregisterExporter(Exporter) - // SetResource may be used to set the Resource associated with this registry. - // This is intended to be used in cases where a single process exports metrics - // for multiple Resources, typically in a multi-tenant situation. - SetResource(*resource.Resource) - - // Start causes the Meter to start processing Record calls and aggregating - // statistics as well as exporting data. - Start() - // Stop causes the Meter to stop processing calls and terminate data export. - Stop() - - // RetrieveData gets a snapshot of the data collected for the the view registered - // with the given name. It is intended for testing only. - RetrieveData(viewName string) ([]*Row, error) -} - -var _ Meter = (*worker)(nil) - -var defaultWorker *worker - -var defaultReportingDuration = 10 * time.Second - -// Find returns a registered view associated with this name. -// If no registered view is found, nil is returned. -func Find(name string) (v *View) { - return defaultWorker.Find(name) -} - -// Find returns a registered view associated with this name. -// If no registered view is found, nil is returned. -func (w *worker) Find(name string) (v *View) { - req := &getViewByNameReq{ - name: name, - c: make(chan *getViewByNameResp), - } - w.c <- req - resp := <-req.c - return resp.v -} - -// Register begins collecting data for the given views. -// Once a view is registered, it reports data to the registered exporters. -func Register(views ...*View) error { - return defaultWorker.Register(views...) -} - -// Register begins collecting data for the given views. -// Once a view is registered, it reports data to the registered exporters. -func (w *worker) Register(views ...*View) error { - req := ®isterViewReq{ - views: views, - err: make(chan error), - } - w.c <- req - return <-req.err -} - -// Unregister the given views. Data will not longer be exported for these views -// after Unregister returns. -// It is not necessary to unregister from views you expect to collect for the -// duration of your program execution. -func Unregister(views ...*View) { - defaultWorker.Unregister(views...) -} - -// Unregister the given views. Data will not longer be exported for these views -// after Unregister returns. -// It is not necessary to unregister from views you expect to collect for the -// duration of your program execution. -func (w *worker) Unregister(views ...*View) { - names := make([]string, len(views)) - for i := range views { - names[i] = views[i].Name - } - req := &unregisterFromViewReq{ - views: names, - done: make(chan struct{}), - } - w.c <- req - <-req.done -} - -// RetrieveData gets a snapshot of the data collected for the the view registered -// with the given name. It is intended for testing only. -func RetrieveData(viewName string) ([]*Row, error) { - return defaultWorker.RetrieveData(viewName) -} - -// RetrieveData gets a snapshot of the data collected for the the view registered -// with the given name. It is intended for testing only. -func (w *worker) RetrieveData(viewName string) ([]*Row, error) { - req := &retrieveDataReq{ - now: time.Now(), - v: viewName, - c: make(chan *retrieveDataResp), - } - w.c <- req - resp := <-req.c - return resp.rows, resp.err -} - -func record(tags *tag.Map, ms interface{}, attachments map[string]interface{}) { - defaultWorker.Record(tags, ms, attachments) -} - -func recordMeasurement(tags *tag.Map, ms []stats.Measurement, attachments map[string]interface{}) { - defaultWorker.recordMeasurement(tags, ms, attachments) -} - -// Record records a set of measurements ms associated with the given tags and attachments. -func (w *worker) Record(tags *tag.Map, ms interface{}, attachments map[string]interface{}) { - w.recordMeasurement(tags, ms.([]stats.Measurement), attachments) -} - -// recordMeasurement records a set of measurements ms associated with the given tags and attachments. -// This is the same as Record but without an interface{} type to avoid allocations -func (w *worker) recordMeasurement(tags *tag.Map, ms []stats.Measurement, attachments map[string]interface{}) { - req := &recordReq{ - tm: tags, - ms: ms, - attachments: attachments, - t: time.Now(), - } - w.c <- req -} - -// SetReportingPeriod sets the interval between reporting aggregated views in -// the program. If duration is less than or equal to zero, it enables the -// default behavior. -// -// Note: each exporter makes different promises about what the lowest supported -// duration is. For example, the Stackdriver exporter recommends a value no -// lower than 1 minute. Consult each exporter per your needs. -func SetReportingPeriod(d time.Duration) { - defaultWorker.SetReportingPeriod(d) -} - -// Stop stops the default worker. -func Stop() { - defaultWorker.Stop() -} - -// SetReportingPeriod sets the interval between reporting aggregated views in -// the program. If duration is less than or equal to zero, it enables the -// default behavior. -// -// Note: each exporter makes different promises about what the lowest supported -// duration is. For example, the Stackdriver exporter recommends a value no -// lower than 1 minute. Consult each exporter per your needs. -func (w *worker) SetReportingPeriod(d time.Duration) { - // TODO(acetechnologist): ensure that the duration d is more than a certain - // value. e.g. 1s - req := &setReportingPeriodReq{ - d: d, - c: make(chan bool), - } - w.c <- req - <-req.c // don't return until the timer is set to the new duration. -} - -// NewMeter constructs a Meter instance. You should only need to use this if -// you need to separate out Measurement recordings and View aggregations within -// a single process. -func NewMeter() Meter { - return &worker{ - measures: make(map[string]*measureRef), - views: make(map[string]*viewInternal), - viewStartTimes: make(map[*viewInternal]time.Time), - timer: time.NewTicker(defaultReportingDuration), - c: make(chan command, 1024), - quit: make(chan bool), - done: make(chan bool), - - exporters: make(map[Exporter]struct{}), - } -} - -// SetResource associates all data collected by this Meter with the specified -// resource. This resource is reported when using metricexport.ReadAndExport; -// it is not provided when used with ExportView/RegisterExporter, because that -// interface does not provide a means for reporting the Resource. -func (w *worker) SetResource(r *resource.Resource) { - w.r = r -} - -func (w *worker) Start() { - go w.start() -} - -func (w *worker) start() { - prodMgr := metricproducer.GlobalManager() - prodMgr.AddProducer(w) - - for { - select { - case cmd := <-w.c: - cmd.handleCommand(w) - case <-w.timer.C: - w.reportUsage() - case <-w.quit: - w.timer.Stop() - close(w.c) - close(w.done) - return - } - } -} - -func (w *worker) Stop() { - prodMgr := metricproducer.GlobalManager() - prodMgr.DeleteProducer(w) - select { - case <-w.quit: - default: - close(w.quit) - } - <-w.done -} - -func (w *worker) getMeasureRef(name string) *measureRef { - if mr, ok := w.measures[name]; ok { - return mr - } - mr := &measureRef{ - measure: name, - views: make(map[*viewInternal]struct{}), - } - w.measures[name] = mr - return mr -} - -func (w *worker) tryRegisterView(v *View) (*viewInternal, error) { - w.mu.Lock() - defer w.mu.Unlock() - vi, err := newViewInternal(v) - if err != nil { - return nil, err - } - if x, ok := w.views[vi.view.Name]; ok { - if !x.view.same(vi.view) { - return nil, fmt.Errorf("cannot register view %q; a different view with the same name is already registered", v.Name) - } - - // the view is already registered so there is nothing to do and the - // command is considered successful. - return x, nil - } - w.views[vi.view.Name] = vi - w.viewStartTimes[vi] = time.Now() - ref := w.getMeasureRef(vi.view.Measure.Name()) - ref.views[vi] = struct{}{} - return vi, nil -} - -func (w *worker) unregisterView(v *viewInternal) { - w.mu.Lock() - defer w.mu.Unlock() - delete(w.views, v.view.Name) - delete(w.viewStartTimes, v) - if measure := w.measures[v.view.Measure.Name()]; measure != nil { - delete(measure.views, v) - } -} - -func (w *worker) reportView(v *viewInternal) { - if !v.isSubscribed() { - return - } - rows := v.collectedRows() - viewData := &Data{ - View: v.view, - Start: w.viewStartTimes[v], - End: time.Now(), - Rows: rows, - } - w.exportersMu.Lock() - defer w.exportersMu.Unlock() - for e := range w.exporters { - e.ExportView(viewData) - } -} - -func (w *worker) reportUsage() { - w.mu.Lock() - defer w.mu.Unlock() - for _, v := range w.views { - w.reportView(v) - } -} - -func (w *worker) toMetric(v *viewInternal, now time.Time) *metricdata.Metric { - if !v.isSubscribed() { - return nil - } - - return viewToMetric(v, w.r, now) -} - -// Read reads all view data and returns them as metrics. -// It is typically invoked by metric reader to export stats in metric format. -func (w *worker) Read() []*metricdata.Metric { - w.mu.Lock() - defer w.mu.Unlock() - now := time.Now() - metrics := make([]*metricdata.Metric, 0, len(w.views)) - for _, v := range w.views { - metric := w.toMetric(v, now) - if metric != nil { - metrics = append(metrics, metric) - } - } - return metrics -} - -func (w *worker) RegisterExporter(e Exporter) { - w.exportersMu.Lock() - defer w.exportersMu.Unlock() - - w.exporters[e] = struct{}{} -} - -func (w *worker) UnregisterExporter(e Exporter) { - w.exportersMu.Lock() - defer w.exportersMu.Unlock() - - delete(w.exporters, e) -} diff --git a/vendor/go.opencensus.io/stats/view/worker_commands.go b/vendor/go.opencensus.io/stats/view/worker_commands.go deleted file mode 100644 index 9ac4cc0599..0000000000 --- a/vendor/go.opencensus.io/stats/view/worker_commands.go +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package view - -import ( - "errors" - "fmt" - "strings" - "time" - - "go.opencensus.io/stats" - "go.opencensus.io/stats/internal" - "go.opencensus.io/tag" -) - -type command interface { - handleCommand(w *worker) -} - -// getViewByNameReq is the command to get a view given its name. -type getViewByNameReq struct { - name string - c chan *getViewByNameResp -} - -type getViewByNameResp struct { - v *View -} - -func (cmd *getViewByNameReq) handleCommand(w *worker) { - v := w.views[cmd.name] - if v == nil { - cmd.c <- &getViewByNameResp{nil} - return - } - cmd.c <- &getViewByNameResp{v.view} -} - -// registerViewReq is the command to register a view. -type registerViewReq struct { - views []*View - err chan error -} - -func (cmd *registerViewReq) handleCommand(w *worker) { - for _, v := range cmd.views { - if err := v.canonicalize(); err != nil { - cmd.err <- err - return - } - } - var errstr []string - for _, view := range cmd.views { - vi, err := w.tryRegisterView(view) - if err != nil { - errstr = append(errstr, fmt.Sprintf("%s: %v", view.Name, err)) - continue - } - internal.SubscriptionReporter(view.Measure.Name()) - vi.subscribe() - } - if len(errstr) > 0 { - cmd.err <- errors.New(strings.Join(errstr, "\n")) - } else { - cmd.err <- nil - } -} - -// unregisterFromViewReq is the command to unregister to a view. Has no -// impact on the data collection for client that are pulling data from the -// library. -type unregisterFromViewReq struct { - views []string - done chan struct{} -} - -func (cmd *unregisterFromViewReq) handleCommand(w *worker) { - for _, name := range cmd.views { - vi, ok := w.views[name] - if !ok { - continue - } - - // Report pending data for this view before removing it. - w.reportView(vi) - - vi.unsubscribe() - if !vi.isSubscribed() { - // this was the last subscription and view is not collecting anymore. - // The collected data can be cleared. - vi.clearRows() - } - w.unregisterView(vi) - } - cmd.done <- struct{}{} -} - -// retrieveDataReq is the command to retrieve data for a view. -type retrieveDataReq struct { - now time.Time - v string - c chan *retrieveDataResp -} - -type retrieveDataResp struct { - rows []*Row - err error -} - -func (cmd *retrieveDataReq) handleCommand(w *worker) { - w.mu.Lock() - defer w.mu.Unlock() - vi, ok := w.views[cmd.v] - if !ok { - cmd.c <- &retrieveDataResp{ - nil, - fmt.Errorf("cannot retrieve data; view %q is not registered", cmd.v), - } - return - } - - if !vi.isSubscribed() { - cmd.c <- &retrieveDataResp{ - nil, - fmt.Errorf("cannot retrieve data; view %q has no subscriptions or collection is not forcibly started", cmd.v), - } - return - } - cmd.c <- &retrieveDataResp{ - vi.collectedRows(), - nil, - } -} - -// recordReq is the command to record data related to multiple measures -// at once. -type recordReq struct { - tm *tag.Map - ms []stats.Measurement - attachments map[string]interface{} - t time.Time -} - -func (cmd *recordReq) handleCommand(w *worker) { - w.mu.Lock() - defer w.mu.Unlock() - for _, m := range cmd.ms { - if (m == stats.Measurement{}) { // not registered - continue - } - ref := w.getMeasureRef(m.Measure().Name()) - for v := range ref.views { - v.addSample(cmd.tm, m.Value(), cmd.attachments, cmd.t) - } - } -} - -// setReportingPeriodReq is the command to modify the duration between -// reporting the collected data to the registered clients. -type setReportingPeriodReq struct { - d time.Duration - c chan bool -} - -func (cmd *setReportingPeriodReq) handleCommand(w *worker) { - w.timer.Stop() - if cmd.d <= 0 { - w.timer = time.NewTicker(defaultReportingDuration) - } else { - w.timer = time.NewTicker(cmd.d) - } - cmd.c <- true -} diff --git a/vendor/go.opencensus.io/tag/context.go b/vendor/go.opencensus.io/tag/context.go deleted file mode 100644 index b27d1b26b1..0000000000 --- a/vendor/go.opencensus.io/tag/context.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package tag - -import ( - "context" -) - -// FromContext returns the tag map stored in the context. -func FromContext(ctx context.Context) *Map { - // The returned tag map shouldn't be mutated. - ts := ctx.Value(mapCtxKey) - if ts == nil { - return nil - } - return ts.(*Map) -} - -// NewContext creates a new context with the given tag map. -// To propagate a tag map to downstream methods and downstream RPCs, add a tag map -// to the current context. NewContext will return a copy of the current context, -// and put the tag map into the returned one. -// If there is already a tag map in the current context, it will be replaced with m. -func NewContext(ctx context.Context, m *Map) context.Context { - return context.WithValue(ctx, mapCtxKey, m) -} - -type ctxKey struct{} - -var mapCtxKey = ctxKey{} diff --git a/vendor/go.opencensus.io/tag/doc.go b/vendor/go.opencensus.io/tag/doc.go deleted file mode 100644 index da16b74e4d..0000000000 --- a/vendor/go.opencensus.io/tag/doc.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/* -Package tag contains OpenCensus tags. - -Tags are key-value pairs. Tags provide additional cardinality to -the OpenCensus instrumentation data. - -Tags can be propagated on the wire and in the same -process via context.Context. Encode and Decode should be -used to represent tags into their binary propagation form. -*/ -package tag // import "go.opencensus.io/tag" diff --git a/vendor/go.opencensus.io/tag/key.go b/vendor/go.opencensus.io/tag/key.go deleted file mode 100644 index 71ec913657..0000000000 --- a/vendor/go.opencensus.io/tag/key.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package tag - -// Key represents a tag key. -type Key struct { - name string -} - -// NewKey creates or retrieves a string key identified by name. -// Calling NewKey more than once with the same name returns the same key. -func NewKey(name string) (Key, error) { - if !checkKeyName(name) { - return Key{}, errInvalidKeyName - } - return Key{name: name}, nil -} - -// MustNewKey returns a key with the given name, and panics if name is an invalid key name. -func MustNewKey(name string) Key { - k, err := NewKey(name) - if err != nil { - panic(err) - } - return k -} - -// Name returns the name of the key. -func (k Key) Name() string { - return k.name -} diff --git a/vendor/go.opencensus.io/tag/map.go b/vendor/go.opencensus.io/tag/map.go deleted file mode 100644 index 0272ef85a4..0000000000 --- a/vendor/go.opencensus.io/tag/map.go +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package tag - -import ( - "bytes" - "context" - "fmt" - "sort" -) - -// Tag is a key value pair that can be propagated on wire. -type Tag struct { - Key Key - Value string -} - -type tagContent struct { - value string - m metadatas -} - -// Map is a map of tags. Use New to create a context containing -// a new Map. -type Map struct { - m map[Key]tagContent -} - -// Value returns the value for the key if a value for the key exists. -func (m *Map) Value(k Key) (string, bool) { - if m == nil { - return "", false - } - v, ok := m.m[k] - return v.value, ok -} - -func (m *Map) String() string { - if m == nil { - return "nil" - } - keys := make([]Key, 0, len(m.m)) - for k := range m.m { - keys = append(keys, k) - } - sort.Slice(keys, func(i, j int) bool { return keys[i].Name() < keys[j].Name() }) - - var buffer bytes.Buffer - buffer.WriteString("{ ") - for _, k := range keys { - buffer.WriteString(fmt.Sprintf("{%v %v}", k.name, m.m[k])) - } - buffer.WriteString(" }") - return buffer.String() -} - -func (m *Map) insert(k Key, v string, md metadatas) { - if _, ok := m.m[k]; ok { - return - } - m.m[k] = tagContent{value: v, m: md} -} - -func (m *Map) update(k Key, v string, md metadatas) { - if _, ok := m.m[k]; ok { - m.m[k] = tagContent{value: v, m: md} - } -} - -func (m *Map) upsert(k Key, v string, md metadatas) { - m.m[k] = tagContent{value: v, m: md} -} - -func (m *Map) delete(k Key) { - delete(m.m, k) -} - -func newMap() *Map { - return &Map{m: make(map[Key]tagContent)} -} - -// Mutator modifies a tag map. -type Mutator interface { - Mutate(t *Map) (*Map, error) -} - -// Insert returns a mutator that inserts a -// value associated with k. If k already exists in the tag map, -// mutator doesn't update the value. -// Metadata applies metadata to the tag. It is optional. -// Metadatas are applied in the order in which it is provided. -// If more than one metadata updates the same attribute then -// the update from the last metadata prevails. -func Insert(k Key, v string, mds ...Metadata) Mutator { - return &mutator{ - fn: func(m *Map) (*Map, error) { - if !checkValue(v) { - return nil, errInvalidValue - } - m.insert(k, v, createMetadatas(mds...)) - return m, nil - }, - } -} - -// Update returns a mutator that updates the -// value of the tag associated with k with v. If k doesn't -// exists in the tag map, the mutator doesn't insert the value. -// Metadata applies metadata to the tag. It is optional. -// Metadatas are applied in the order in which it is provided. -// If more than one metadata updates the same attribute then -// the update from the last metadata prevails. -func Update(k Key, v string, mds ...Metadata) Mutator { - return &mutator{ - fn: func(m *Map) (*Map, error) { - if !checkValue(v) { - return nil, errInvalidValue - } - m.update(k, v, createMetadatas(mds...)) - return m, nil - }, - } -} - -// Upsert returns a mutator that upserts the -// value of the tag associated with k with v. It inserts the -// value if k doesn't exist already. It mutates the value -// if k already exists. -// Metadata applies metadata to the tag. It is optional. -// Metadatas are applied in the order in which it is provided. -// If more than one metadata updates the same attribute then -// the update from the last metadata prevails. -func Upsert(k Key, v string, mds ...Metadata) Mutator { - return &mutator{ - fn: func(m *Map) (*Map, error) { - if !checkValue(v) { - return nil, errInvalidValue - } - m.upsert(k, v, createMetadatas(mds...)) - return m, nil - }, - } -} - -func createMetadatas(mds ...Metadata) metadatas { - var metas metadatas - if len(mds) > 0 { - for _, md := range mds { - if md != nil { - md(&metas) - } - } - } else { - WithTTL(TTLUnlimitedPropagation)(&metas) - } - return metas - -} - -// Delete returns a mutator that deletes -// the value associated with k. -func Delete(k Key) Mutator { - return &mutator{ - fn: func(m *Map) (*Map, error) { - m.delete(k) - return m, nil - }, - } -} - -// New returns a new context that contains a tag map -// originated from the incoming context and modified -// with the provided mutators. -func New(ctx context.Context, mutator ...Mutator) (context.Context, error) { - m := newMap() - orig := FromContext(ctx) - if orig != nil { - for k, v := range orig.m { - if !checkKeyName(k.Name()) { - return ctx, fmt.Errorf("key:%q: %v", k, errInvalidKeyName) - } - if !checkValue(v.value) { - return ctx, fmt.Errorf("key:%q value:%q: %v", k.Name(), v, errInvalidValue) - } - m.insert(k, v.value, v.m) - } - } - var err error - for _, mod := range mutator { - m, err = mod.Mutate(m) - if err != nil { - return ctx, err - } - } - return NewContext(ctx, m), nil -} - -// Do is similar to pprof.Do: a convenience for installing the tags -// from the context as Go profiler labels. This allows you to -// correlated runtime profiling with stats. -// -// It converts the key/values from the given map to Go profiler labels -// and calls pprof.Do. -// -// Do is going to do nothing if your Go version is below 1.9. -func Do(ctx context.Context, f func(ctx context.Context)) { - do(ctx, f) -} - -type mutator struct { - fn func(t *Map) (*Map, error) -} - -func (m *mutator) Mutate(t *Map) (*Map, error) { - return m.fn(t) -} diff --git a/vendor/go.opencensus.io/tag/map_codec.go b/vendor/go.opencensus.io/tag/map_codec.go deleted file mode 100644 index c242e695c8..0000000000 --- a/vendor/go.opencensus.io/tag/map_codec.go +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package tag - -import ( - "encoding/binary" - "fmt" -) - -// KeyType defines the types of keys allowed. Currently only keyTypeString is -// supported. -type keyType byte - -const ( - keyTypeString keyType = iota - keyTypeInt64 - keyTypeTrue - keyTypeFalse - - tagsVersionID = byte(0) -) - -type encoderGRPC struct { - buf []byte - writeIdx, readIdx int -} - -// writeKeyString writes the fieldID '0' followed by the key string and value -// string. -func (eg *encoderGRPC) writeTagString(k, v string) { - eg.writeByte(byte(keyTypeString)) - eg.writeStringWithVarintLen(k) - eg.writeStringWithVarintLen(v) -} - -func (eg *encoderGRPC) writeTagUint64(k string, i uint64) { - eg.writeByte(byte(keyTypeInt64)) - eg.writeStringWithVarintLen(k) - eg.writeUint64(i) -} - -func (eg *encoderGRPC) writeTagTrue(k string) { - eg.writeByte(byte(keyTypeTrue)) - eg.writeStringWithVarintLen(k) -} - -func (eg *encoderGRPC) writeTagFalse(k string) { - eg.writeByte(byte(keyTypeFalse)) - eg.writeStringWithVarintLen(k) -} - -func (eg *encoderGRPC) writeBytesWithVarintLen(bytes []byte) { - length := len(bytes) - - eg.growIfRequired(binary.MaxVarintLen64 + length) - eg.writeIdx += binary.PutUvarint(eg.buf[eg.writeIdx:], uint64(length)) - copy(eg.buf[eg.writeIdx:], bytes) - eg.writeIdx += length -} - -func (eg *encoderGRPC) writeStringWithVarintLen(s string) { - length := len(s) - - eg.growIfRequired(binary.MaxVarintLen64 + length) - eg.writeIdx += binary.PutUvarint(eg.buf[eg.writeIdx:], uint64(length)) - copy(eg.buf[eg.writeIdx:], s) - eg.writeIdx += length -} - -func (eg *encoderGRPC) writeByte(v byte) { - eg.growIfRequired(1) - eg.buf[eg.writeIdx] = v - eg.writeIdx++ -} - -func (eg *encoderGRPC) writeUint32(i uint32) { - eg.growIfRequired(4) - binary.LittleEndian.PutUint32(eg.buf[eg.writeIdx:], i) - eg.writeIdx += 4 -} - -func (eg *encoderGRPC) writeUint64(i uint64) { - eg.growIfRequired(8) - binary.LittleEndian.PutUint64(eg.buf[eg.writeIdx:], i) - eg.writeIdx += 8 -} - -func (eg *encoderGRPC) readByte() byte { - b := eg.buf[eg.readIdx] - eg.readIdx++ - return b -} - -func (eg *encoderGRPC) readUint32() uint32 { - i := binary.LittleEndian.Uint32(eg.buf[eg.readIdx:]) - eg.readIdx += 4 - return i -} - -func (eg *encoderGRPC) readUint64() uint64 { - i := binary.LittleEndian.Uint64(eg.buf[eg.readIdx:]) - eg.readIdx += 8 - return i -} - -func (eg *encoderGRPC) readBytesWithVarintLen() ([]byte, error) { - if eg.readEnded() { - return nil, fmt.Errorf("unexpected end while readBytesWithVarintLen '%x' starting at idx '%v'", eg.buf, eg.readIdx) - } - length, valueStart := binary.Uvarint(eg.buf[eg.readIdx:]) - if valueStart <= 0 { - return nil, fmt.Errorf("unexpected end while readBytesWithVarintLen '%x' starting at idx '%v'", eg.buf, eg.readIdx) - } - - valueStart += eg.readIdx - valueEnd := valueStart + int(length) - if valueEnd > len(eg.buf) { - return nil, fmt.Errorf("malformed encoding: length:%v, upper:%v, maxLength:%v", length, valueEnd, len(eg.buf)) - } - - eg.readIdx = valueEnd - return eg.buf[valueStart:valueEnd], nil -} - -func (eg *encoderGRPC) readStringWithVarintLen() (string, error) { - bytes, err := eg.readBytesWithVarintLen() - if err != nil { - return "", err - } - return string(bytes), nil -} - -func (eg *encoderGRPC) growIfRequired(expected int) { - if len(eg.buf)-eg.writeIdx < expected { - tmp := make([]byte, 2*(len(eg.buf)+1)+expected) - copy(tmp, eg.buf) - eg.buf = tmp - } -} - -func (eg *encoderGRPC) readEnded() bool { - return eg.readIdx >= len(eg.buf) -} - -func (eg *encoderGRPC) bytes() []byte { - return eg.buf[:eg.writeIdx] -} - -// Encode encodes the tag map into a []byte. It is useful to propagate -// the tag maps on wire in binary format. -func Encode(m *Map) []byte { - if m == nil { - return nil - } - eg := &encoderGRPC{ - buf: make([]byte, len(m.m)), - } - eg.writeByte(tagsVersionID) - for k, v := range m.m { - if v.m.ttl.ttl == valueTTLUnlimitedPropagation { - eg.writeByte(byte(keyTypeString)) - eg.writeStringWithVarintLen(k.name) - eg.writeBytesWithVarintLen([]byte(v.value)) - } - } - return eg.bytes() -} - -// Decode decodes the given []byte into a tag map. -func Decode(bytes []byte) (*Map, error) { - ts := newMap() - err := DecodeEach(bytes, ts.upsert) - if err != nil { - // no partial failures - return nil, err - } - return ts, nil -} - -// DecodeEach decodes the given serialized tag map, calling handler for each -// tag key and value decoded. -func DecodeEach(bytes []byte, fn func(key Key, val string, md metadatas)) error { - eg := &encoderGRPC{ - buf: bytes, - } - if len(eg.buf) == 0 { - return nil - } - - version := eg.readByte() - if version > tagsVersionID { - return fmt.Errorf("cannot decode: unsupported version: %q; supports only up to: %q", version, tagsVersionID) - } - - for !eg.readEnded() { - typ := keyType(eg.readByte()) - - if typ != keyTypeString { - return fmt.Errorf("cannot decode: invalid key type: %q", typ) - } - - k, err := eg.readBytesWithVarintLen() - if err != nil { - return err - } - - v, err := eg.readBytesWithVarintLen() - if err != nil { - return err - } - - key, err := NewKey(string(k)) - if err != nil { - return err - } - val := string(v) - if !checkValue(val) { - return errInvalidValue - } - fn(key, val, createMetadatas(WithTTL(TTLUnlimitedPropagation))) - if err != nil { - return err - } - } - return nil -} diff --git a/vendor/go.opencensus.io/tag/metadata.go b/vendor/go.opencensus.io/tag/metadata.go deleted file mode 100644 index 6571a583ea..0000000000 --- a/vendor/go.opencensus.io/tag/metadata.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package tag - -const ( - // valueTTLNoPropagation prevents tag from propagating. - valueTTLNoPropagation = 0 - - // valueTTLUnlimitedPropagation allows tag to propagate without any limits on number of hops. - valueTTLUnlimitedPropagation = -1 -) - -// TTL is metadata that specifies number of hops a tag can propagate. -// Details about TTL metadata is specified at https://github.com/census-instrumentation/opencensus-specs/blob/master/tags/TagMap.md#tagmetadata -type TTL struct { - ttl int -} - -var ( - // TTLUnlimitedPropagation is TTL metadata that allows tag to propagate without any limits on number of hops. - TTLUnlimitedPropagation = TTL{ttl: valueTTLUnlimitedPropagation} - - // TTLNoPropagation is TTL metadata that prevents tag from propagating. - TTLNoPropagation = TTL{ttl: valueTTLNoPropagation} -) - -type metadatas struct { - ttl TTL -} - -// Metadata applies metadatas specified by the function. -type Metadata func(*metadatas) - -// WithTTL applies metadata with provided ttl. -func WithTTL(ttl TTL) Metadata { - return func(m *metadatas) { - m.ttl = ttl - } -} diff --git a/vendor/go.opencensus.io/tag/profile_19.go b/vendor/go.opencensus.io/tag/profile_19.go deleted file mode 100644 index 8fb17226fe..0000000000 --- a/vendor/go.opencensus.io/tag/profile_19.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build go1.9 -// +build go1.9 - -package tag - -import ( - "context" - "runtime/pprof" -) - -func do(ctx context.Context, f func(ctx context.Context)) { - m := FromContext(ctx) - keyvals := make([]string, 0, 2*len(m.m)) - for k, v := range m.m { - keyvals = append(keyvals, k.Name(), v.value) - } - pprof.Do(ctx, pprof.Labels(keyvals...), f) -} diff --git a/vendor/go.opencensus.io/tag/profile_not19.go b/vendor/go.opencensus.io/tag/profile_not19.go deleted file mode 100644 index e28cf13cde..0000000000 --- a/vendor/go.opencensus.io/tag/profile_not19.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !go1.9 -// +build !go1.9 - -package tag - -import "context" - -func do(ctx context.Context, f func(ctx context.Context)) { - f(ctx) -} diff --git a/vendor/go.opencensus.io/tag/validate.go b/vendor/go.opencensus.io/tag/validate.go deleted file mode 100644 index 0939fc6748..0000000000 --- a/vendor/go.opencensus.io/tag/validate.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tag - -import "errors" - -const ( - maxKeyLength = 255 - - // valid are restricted to US-ASCII subset (range 0x20 (' ') to 0x7e ('~')). - validKeyValueMin = 32 - validKeyValueMax = 126 -) - -var ( - errInvalidKeyName = errors.New("invalid key name: only ASCII characters accepted; max length must be 255 characters") - errInvalidValue = errors.New("invalid value: only ASCII characters accepted; max length must be 255 characters") -) - -func checkKeyName(name string) bool { - if len(name) == 0 { - return false - } - if len(name) > maxKeyLength { - return false - } - return isASCII(name) -} - -func isASCII(s string) bool { - for _, c := range s { - if (c < validKeyValueMin) || (c > validKeyValueMax) { - return false - } - } - return true -} - -func checkValue(v string) bool { - if len(v) > maxKeyLength { - return false - } - return isASCII(v) -} diff --git a/vendor/go.opencensus.io/trace/basetypes.go b/vendor/go.opencensus.io/trace/basetypes.go deleted file mode 100644 index c8e26ed635..0000000000 --- a/vendor/go.opencensus.io/trace/basetypes.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "fmt" - "time" -) - -type ( - // TraceID is a 16-byte identifier for a set of spans. - TraceID [16]byte - - // SpanID is an 8-byte identifier for a single span. - SpanID [8]byte -) - -func (t TraceID) String() string { - return fmt.Sprintf("%02x", t[:]) -} - -func (s SpanID) String() string { - return fmt.Sprintf("%02x", s[:]) -} - -// Annotation represents a text annotation with a set of attributes and a timestamp. -type Annotation struct { - Time time.Time - Message string - Attributes map[string]interface{} -} - -// Attribute represents a key-value pair on a span, link or annotation. -// Construct with one of: BoolAttribute, Int64Attribute, or StringAttribute. -type Attribute struct { - key string - value interface{} -} - -// Key returns the attribute's key -func (a *Attribute) Key() string { - return a.key -} - -// Value returns the attribute's value -func (a *Attribute) Value() interface{} { - return a.value -} - -// BoolAttribute returns a bool-valued attribute. -func BoolAttribute(key string, value bool) Attribute { - return Attribute{key: key, value: value} -} - -// Int64Attribute returns an int64-valued attribute. -func Int64Attribute(key string, value int64) Attribute { - return Attribute{key: key, value: value} -} - -// Float64Attribute returns a float64-valued attribute. -func Float64Attribute(key string, value float64) Attribute { - return Attribute{key: key, value: value} -} - -// StringAttribute returns a string-valued attribute. -func StringAttribute(key string, value string) Attribute { - return Attribute{key: key, value: value} -} - -// LinkType specifies the relationship between the span that had the link -// added, and the linked span. -type LinkType int32 - -// LinkType values. -const ( - LinkTypeUnspecified LinkType = iota // The relationship of the two spans is unknown. - LinkTypeChild // The linked span is a child of the current span. - LinkTypeParent // The linked span is the parent of the current span. -) - -// Link represents a reference from one span to another span. -type Link struct { - TraceID TraceID - SpanID SpanID - Type LinkType - // Attributes is a set of attributes on the link. - Attributes map[string]interface{} -} - -// MessageEventType specifies the type of message event. -type MessageEventType int32 - -// MessageEventType values. -const ( - MessageEventTypeUnspecified MessageEventType = iota // Unknown event type. - MessageEventTypeSent // Indicates a sent RPC message. - MessageEventTypeRecv // Indicates a received RPC message. -) - -// MessageEvent represents an event describing a message sent or received on the network. -type MessageEvent struct { - Time time.Time - EventType MessageEventType - MessageID int64 - UncompressedByteSize int64 - CompressedByteSize int64 -} - -// Status is the status of a Span. -type Status struct { - // Code is a status code. Zero indicates success. - // - // If Code will be propagated to Google APIs, it ideally should be a value from - // https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto . - Code int32 - Message string -} diff --git a/vendor/go.opencensus.io/trace/config.go b/vendor/go.opencensus.io/trace/config.go deleted file mode 100644 index 775f8274fa..0000000000 --- a/vendor/go.opencensus.io/trace/config.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "sync" - - "go.opencensus.io/trace/internal" -) - -// Config represents the global tracing configuration. -type Config struct { - // DefaultSampler is the default sampler used when creating new spans. - DefaultSampler Sampler - - // IDGenerator is for internal use only. - IDGenerator internal.IDGenerator - - // MaxAnnotationEventsPerSpan is max number of annotation events per span - MaxAnnotationEventsPerSpan int - - // MaxMessageEventsPerSpan is max number of message events per span - MaxMessageEventsPerSpan int - - // MaxAnnotationEventsPerSpan is max number of attributes per span - MaxAttributesPerSpan int - - // MaxLinksPerSpan is max number of links per span - MaxLinksPerSpan int -} - -var configWriteMu sync.Mutex - -const ( - // DefaultMaxAnnotationEventsPerSpan is default max number of annotation events per span - DefaultMaxAnnotationEventsPerSpan = 32 - - // DefaultMaxMessageEventsPerSpan is default max number of message events per span - DefaultMaxMessageEventsPerSpan = 128 - - // DefaultMaxAttributesPerSpan is default max number of attributes per span - DefaultMaxAttributesPerSpan = 32 - - // DefaultMaxLinksPerSpan is default max number of links per span - DefaultMaxLinksPerSpan = 32 -) - -// ApplyConfig applies changes to the global tracing configuration. -// -// Fields not provided in the given config are going to be preserved. -func ApplyConfig(cfg Config) { - configWriteMu.Lock() - defer configWriteMu.Unlock() - c := *config.Load().(*Config) - if cfg.DefaultSampler != nil { - c.DefaultSampler = cfg.DefaultSampler - } - if cfg.IDGenerator != nil { - c.IDGenerator = cfg.IDGenerator - } - if cfg.MaxAnnotationEventsPerSpan > 0 { - c.MaxAnnotationEventsPerSpan = cfg.MaxAnnotationEventsPerSpan - } - if cfg.MaxMessageEventsPerSpan > 0 { - c.MaxMessageEventsPerSpan = cfg.MaxMessageEventsPerSpan - } - if cfg.MaxAttributesPerSpan > 0 { - c.MaxAttributesPerSpan = cfg.MaxAttributesPerSpan - } - if cfg.MaxLinksPerSpan > 0 { - c.MaxLinksPerSpan = cfg.MaxLinksPerSpan - } - config.Store(&c) -} diff --git a/vendor/go.opencensus.io/trace/doc.go b/vendor/go.opencensus.io/trace/doc.go deleted file mode 100644 index 7a1616a55c..0000000000 --- a/vendor/go.opencensus.io/trace/doc.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package trace contains support for OpenCensus distributed tracing. - -The following assumes a basic familiarity with OpenCensus concepts. -See http://opencensus.io - -# Exporting Traces - -To export collected tracing data, register at least one exporter. You can use -one of the provided exporters or write your own. - - trace.RegisterExporter(exporter) - -By default, traces will be sampled relatively rarely. To change the sampling -frequency for your entire program, call ApplyConfig. Use a ProbabilitySampler -to sample a subset of traces, or use AlwaysSample to collect a trace on every run: - - trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) - -Be careful about using trace.AlwaysSample in a production application with -significant traffic: a new trace will be started and exported for every request. - -# Adding Spans to a Trace - -A trace consists of a tree of spans. In Go, the current span is carried in a -context.Context. - -It is common to want to capture all the activity of a function call in a span. For -this to work, the function must take a context.Context as a parameter. Add these two -lines to the top of the function: - - ctx, span := trace.StartSpan(ctx, "example.com/Run") - defer span.End() - -StartSpan will create a new top-level span if the context -doesn't contain another span, otherwise it will create a child span. -*/ -package trace // import "go.opencensus.io/trace" diff --git a/vendor/go.opencensus.io/trace/evictedqueue.go b/vendor/go.opencensus.io/trace/evictedqueue.go deleted file mode 100644 index ffc264f23d..0000000000 --- a/vendor/go.opencensus.io/trace/evictedqueue.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2019, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -type evictedQueue struct { - queue []interface{} - capacity int - droppedCount int -} - -func newEvictedQueue(capacity int) *evictedQueue { - eq := &evictedQueue{ - capacity: capacity, - queue: make([]interface{}, 0), - } - - return eq -} - -func (eq *evictedQueue) add(value interface{}) { - if len(eq.queue) == eq.capacity { - eq.queue = eq.queue[1:] - eq.droppedCount++ - } - eq.queue = append(eq.queue, value) -} diff --git a/vendor/go.opencensus.io/trace/export.go b/vendor/go.opencensus.io/trace/export.go deleted file mode 100644 index e0d9a4b99e..0000000000 --- a/vendor/go.opencensus.io/trace/export.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "sync" - "sync/atomic" - "time" -) - -// Exporter is a type for functions that receive sampled trace spans. -// -// The ExportSpan method should be safe for concurrent use and should return -// quickly; if an Exporter takes a significant amount of time to process a -// SpanData, that work should be done on another goroutine. -// -// The SpanData should not be modified, but a pointer to it can be kept. -type Exporter interface { - ExportSpan(s *SpanData) -} - -type exportersMap map[Exporter]struct{} - -var ( - exporterMu sync.Mutex - exporters atomic.Value -) - -// RegisterExporter adds to the list of Exporters that will receive sampled -// trace spans. -// -// Binaries can register exporters, libraries shouldn't register exporters. -func RegisterExporter(e Exporter) { - exporterMu.Lock() - new := make(exportersMap) - if old, ok := exporters.Load().(exportersMap); ok { - for k, v := range old { - new[k] = v - } - } - new[e] = struct{}{} - exporters.Store(new) - exporterMu.Unlock() -} - -// UnregisterExporter removes from the list of Exporters the Exporter that was -// registered with the given name. -func UnregisterExporter(e Exporter) { - exporterMu.Lock() - new := make(exportersMap) - if old, ok := exporters.Load().(exportersMap); ok { - for k, v := range old { - new[k] = v - } - } - delete(new, e) - exporters.Store(new) - exporterMu.Unlock() -} - -// SpanData contains all the information collected by a Span. -type SpanData struct { - SpanContext - ParentSpanID SpanID - SpanKind int - Name string - StartTime time.Time - // The wall clock time of EndTime will be adjusted to always be offset - // from StartTime by the duration of the span. - EndTime time.Time - // The values of Attributes each have type string, bool, or int64. - Attributes map[string]interface{} - Annotations []Annotation - MessageEvents []MessageEvent - Status - Links []Link - HasRemoteParent bool - DroppedAttributeCount int - DroppedAnnotationCount int - DroppedMessageEventCount int - DroppedLinkCount int - - // ChildSpanCount holds the number of child span created for this span. - ChildSpanCount int -} diff --git a/vendor/go.opencensus.io/trace/internal/internal.go b/vendor/go.opencensus.io/trace/internal/internal.go deleted file mode 100644 index 7e808d8f30..0000000000 --- a/vendor/go.opencensus.io/trace/internal/internal.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package internal provides trace internals. -package internal - -// IDGenerator allows custom generators for TraceId and SpanId. -type IDGenerator interface { - NewTraceID() [16]byte - NewSpanID() [8]byte -} diff --git a/vendor/go.opencensus.io/trace/lrumap.go b/vendor/go.opencensus.io/trace/lrumap.go deleted file mode 100644 index 80095a5f6c..0000000000 --- a/vendor/go.opencensus.io/trace/lrumap.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2019, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "github.com/golang/groupcache/lru" -) - -// A simple lru.Cache wrapper that tracks the keys of the current contents and -// the cumulative number of evicted items. -type lruMap struct { - cacheKeys map[lru.Key]bool - cache *lru.Cache - droppedCount int -} - -func newLruMap(size int) *lruMap { - lm := &lruMap{ - cacheKeys: make(map[lru.Key]bool), - cache: lru.New(size), - droppedCount: 0, - } - lm.cache.OnEvicted = func(key lru.Key, value interface{}) { - delete(lm.cacheKeys, key) - lm.droppedCount++ - } - return lm -} - -func (lm lruMap) len() int { - return lm.cache.Len() -} - -func (lm lruMap) keys() []interface{} { - keys := make([]interface{}, 0, len(lm.cacheKeys)) - for k := range lm.cacheKeys { - keys = append(keys, k) - } - return keys -} - -func (lm *lruMap) add(key, value interface{}) { - lm.cacheKeys[lru.Key(key)] = true - lm.cache.Add(lru.Key(key), value) -} - -func (lm *lruMap) get(key interface{}) (interface{}, bool) { - return lm.cache.Get(key) -} diff --git a/vendor/go.opencensus.io/trace/propagation/propagation.go b/vendor/go.opencensus.io/trace/propagation/propagation.go deleted file mode 100644 index 1eb190a96a..0000000000 --- a/vendor/go.opencensus.io/trace/propagation/propagation.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package propagation implements the binary trace context format. -package propagation // import "go.opencensus.io/trace/propagation" - -// TODO: link to external spec document. - -// BinaryFormat format: -// -// Binary value: -// version_id: 1 byte representing the version id. -// -// For version_id = 0: -// -// version_format: -// field_format: -// -// Fields: -// -// TraceId: (field_id = 0, len = 16, default = "0000000000000000") - 16-byte array representing the trace_id. -// SpanId: (field_id = 1, len = 8, default = "00000000") - 8-byte array representing the span_id. -// TraceOptions: (field_id = 2, len = 1, default = "0") - 1-byte array representing the trace_options. -// -// Fields MUST be encoded using the field id order (smaller to higher). -// -// Valid value example: -// -// {0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, -// 98, 99, 100, 101, 102, 103, 104, 2, 1} -// -// version_id = 0; -// trace_id = {64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79} -// span_id = {97, 98, 99, 100, 101, 102, 103, 104}; -// trace_options = {1}; - -import ( - "net/http" - - "go.opencensus.io/trace" -) - -// Binary returns the binary format representation of a SpanContext. -// -// If sc is the zero value, Binary returns nil. -func Binary(sc trace.SpanContext) []byte { - if sc == (trace.SpanContext{}) { - return nil - } - var b [29]byte - copy(b[2:18], sc.TraceID[:]) - b[18] = 1 - copy(b[19:27], sc.SpanID[:]) - b[27] = 2 - b[28] = uint8(sc.TraceOptions) - return b[:] -} - -// FromBinary returns the SpanContext represented by b. -// -// If b has an unsupported version ID or contains no TraceID, FromBinary -// returns with ok==false. -func FromBinary(b []byte) (sc trace.SpanContext, ok bool) { - if len(b) == 0 || b[0] != 0 { - return trace.SpanContext{}, false - } - b = b[1:] - if len(b) >= 17 && b[0] == 0 { - copy(sc.TraceID[:], b[1:17]) - b = b[17:] - } else { - return trace.SpanContext{}, false - } - if len(b) >= 9 && b[0] == 1 { - copy(sc.SpanID[:], b[1:9]) - b = b[9:] - } - if len(b) >= 2 && b[0] == 2 { - sc.TraceOptions = trace.TraceOptions(b[1]) - } - return sc, true -} - -// HTTPFormat implementations propagate span contexts -// in HTTP requests. -// -// SpanContextFromRequest extracts a span context from incoming -// requests. -// -// SpanContextToRequest modifies the given request to include the given -// span context. -type HTTPFormat interface { - SpanContextFromRequest(req *http.Request) (sc trace.SpanContext, ok bool) - SpanContextToRequest(sc trace.SpanContext, req *http.Request) -} - -// TODO(jbd): Find a more representative but short name for HTTPFormat. diff --git a/vendor/go.opencensus.io/trace/sampling.go b/vendor/go.opencensus.io/trace/sampling.go deleted file mode 100644 index 71c10f9e3b..0000000000 --- a/vendor/go.opencensus.io/trace/sampling.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "encoding/binary" -) - -const defaultSamplingProbability = 1e-4 - -// Sampler decides whether a trace should be sampled and exported. -type Sampler func(SamplingParameters) SamplingDecision - -// SamplingParameters contains the values passed to a Sampler. -type SamplingParameters struct { - ParentContext SpanContext - TraceID TraceID - SpanID SpanID - Name string - HasRemoteParent bool -} - -// SamplingDecision is the value returned by a Sampler. -type SamplingDecision struct { - Sample bool -} - -// ProbabilitySampler returns a Sampler that samples a given fraction of traces. -// -// It also samples spans whose parents are sampled. -func ProbabilitySampler(fraction float64) Sampler { - if !(fraction >= 0) { - fraction = 0 - } else if fraction >= 1 { - return AlwaysSample() - } - - traceIDUpperBound := uint64(fraction * (1 << 63)) - return Sampler(func(p SamplingParameters) SamplingDecision { - if p.ParentContext.IsSampled() { - return SamplingDecision{Sample: true} - } - x := binary.BigEndian.Uint64(p.TraceID[0:8]) >> 1 - return SamplingDecision{Sample: x < traceIDUpperBound} - }) -} - -// AlwaysSample returns a Sampler that samples every trace. -// Be careful about using this sampler in a production application with -// significant traffic: a new trace will be started and exported for every -// request. -func AlwaysSample() Sampler { - return func(p SamplingParameters) SamplingDecision { - return SamplingDecision{Sample: true} - } -} - -// NeverSample returns a Sampler that samples no traces. -func NeverSample() Sampler { - return func(p SamplingParameters) SamplingDecision { - return SamplingDecision{Sample: false} - } -} diff --git a/vendor/go.opencensus.io/trace/spanbucket.go b/vendor/go.opencensus.io/trace/spanbucket.go deleted file mode 100644 index fbabad34c0..0000000000 --- a/vendor/go.opencensus.io/trace/spanbucket.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "time" -) - -// samplePeriod is the minimum time between accepting spans in a single bucket. -const samplePeriod = time.Second - -// defaultLatencies contains the default latency bucket bounds. -// TODO: consider defaults, make configurable -var defaultLatencies = [...]time.Duration{ - 10 * time.Microsecond, - 100 * time.Microsecond, - time.Millisecond, - 10 * time.Millisecond, - 100 * time.Millisecond, - time.Second, - 10 * time.Second, - time.Minute, -} - -// bucket is a container for a set of spans for a particular error code or latency range. -type bucket struct { - nextTime time.Time // next time we can accept a span - buffer []*SpanData // circular buffer of spans - nextIndex int // location next SpanData should be placed in buffer - overflow bool // whether the circular buffer has wrapped around -} - -func makeBucket(bufferSize int) bucket { - return bucket{ - buffer: make([]*SpanData, bufferSize), - } -} - -// add adds a span to the bucket, if nextTime has been reached. -func (b *bucket) add(s *SpanData) { - if s.EndTime.Before(b.nextTime) { - return - } - if len(b.buffer) == 0 { - return - } - b.nextTime = s.EndTime.Add(samplePeriod) - b.buffer[b.nextIndex] = s - b.nextIndex++ - if b.nextIndex == len(b.buffer) { - b.nextIndex = 0 - b.overflow = true - } -} - -// size returns the number of spans in the bucket. -func (b *bucket) size() int { - if b.overflow { - return len(b.buffer) - } - return b.nextIndex -} - -// span returns the ith span in the bucket. -func (b *bucket) span(i int) *SpanData { - if !b.overflow { - return b.buffer[i] - } - if i < len(b.buffer)-b.nextIndex { - return b.buffer[b.nextIndex+i] - } - return b.buffer[b.nextIndex+i-len(b.buffer)] -} - -// resize changes the size of the bucket to n, keeping up to n existing spans. -func (b *bucket) resize(n int) { - cur := b.size() - newBuffer := make([]*SpanData, n) - if cur < n { - for i := 0; i < cur; i++ { - newBuffer[i] = b.span(i) - } - b.buffer = newBuffer - b.nextIndex = cur - b.overflow = false - return - } - for i := 0; i < n; i++ { - newBuffer[i] = b.span(i + cur - n) - } - b.buffer = newBuffer - b.nextIndex = 0 - b.overflow = true -} - -// latencyBucket returns the appropriate bucket number for a given latency. -func latencyBucket(latency time.Duration) int { - i := 0 - for i < len(defaultLatencies) && latency >= defaultLatencies[i] { - i++ - } - return i -} - -// latencyBucketBounds returns the lower and upper bounds for a latency bucket -// number. -// -// The lower bound is inclusive, the upper bound is exclusive (except for the -// last bucket.) -func latencyBucketBounds(index int) (lower time.Duration, upper time.Duration) { - if index == 0 { - return 0, defaultLatencies[index] - } - if index == len(defaultLatencies) { - return defaultLatencies[index-1], 1<<63 - 1 - } - return defaultLatencies[index-1], defaultLatencies[index] -} diff --git a/vendor/go.opencensus.io/trace/spanstore.go b/vendor/go.opencensus.io/trace/spanstore.go deleted file mode 100644 index e601f76f2c..0000000000 --- a/vendor/go.opencensus.io/trace/spanstore.go +++ /dev/null @@ -1,308 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "sync" - "time" - - "go.opencensus.io/internal" -) - -const ( - maxBucketSize = 100000 - defaultBucketSize = 10 -) - -var ( - ssmu sync.RWMutex // protects spanStores - spanStores = make(map[string]*spanStore) -) - -// This exists purely to avoid exposing internal methods used by z-Pages externally. -type internalOnly struct{} - -func init() { - //TODO(#412): remove - internal.Trace = &internalOnly{} -} - -// ReportActiveSpans returns the active spans for the given name. -func (i internalOnly) ReportActiveSpans(name string) []*SpanData { - s := spanStoreForName(name) - if s == nil { - return nil - } - var out []*SpanData - s.mu.Lock() - defer s.mu.Unlock() - for activeSpan := range s.active { - if s, ok := activeSpan.(*span); ok { - out = append(out, s.makeSpanData()) - } - } - return out -} - -// ReportSpansByError returns a sample of error spans. -// -// If code is nonzero, only spans with that status code are returned. -func (i internalOnly) ReportSpansByError(name string, code int32) []*SpanData { - s := spanStoreForName(name) - if s == nil { - return nil - } - var out []*SpanData - s.mu.Lock() - defer s.mu.Unlock() - if code != 0 { - if b, ok := s.errors[code]; ok { - for _, sd := range b.buffer { - if sd == nil { - break - } - out = append(out, sd) - } - } - } else { - for _, b := range s.errors { - for _, sd := range b.buffer { - if sd == nil { - break - } - out = append(out, sd) - } - } - } - return out -} - -// ConfigureBucketSizes sets the number of spans to keep per latency and error -// bucket for different span names. -func (i internalOnly) ConfigureBucketSizes(bcs []internal.BucketConfiguration) { - for _, bc := range bcs { - latencyBucketSize := bc.MaxRequestsSucceeded - if latencyBucketSize < 0 { - latencyBucketSize = 0 - } - if latencyBucketSize > maxBucketSize { - latencyBucketSize = maxBucketSize - } - errorBucketSize := bc.MaxRequestsErrors - if errorBucketSize < 0 { - errorBucketSize = 0 - } - if errorBucketSize > maxBucketSize { - errorBucketSize = maxBucketSize - } - spanStoreSetSize(bc.Name, latencyBucketSize, errorBucketSize) - } -} - -// ReportSpansPerMethod returns a summary of what spans are being stored for each span name. -func (i internalOnly) ReportSpansPerMethod() map[string]internal.PerMethodSummary { - out := make(map[string]internal.PerMethodSummary) - ssmu.RLock() - defer ssmu.RUnlock() - for name, s := range spanStores { - s.mu.Lock() - p := internal.PerMethodSummary{ - Active: len(s.active), - } - for code, b := range s.errors { - p.ErrorBuckets = append(p.ErrorBuckets, internal.ErrorBucketSummary{ - ErrorCode: code, - Size: b.size(), - }) - } - for i, b := range s.latency { - min, max := latencyBucketBounds(i) - p.LatencyBuckets = append(p.LatencyBuckets, internal.LatencyBucketSummary{ - MinLatency: min, - MaxLatency: max, - Size: b.size(), - }) - } - s.mu.Unlock() - out[name] = p - } - return out -} - -// ReportSpansByLatency returns a sample of successful spans. -// -// minLatency is the minimum latency of spans to be returned. -// maxLatency, if nonzero, is the maximum latency of spans to be returned. -func (i internalOnly) ReportSpansByLatency(name string, minLatency, maxLatency time.Duration) []*SpanData { - s := spanStoreForName(name) - if s == nil { - return nil - } - var out []*SpanData - s.mu.Lock() - defer s.mu.Unlock() - for i, b := range s.latency { - min, max := latencyBucketBounds(i) - if i+1 != len(s.latency) && max <= minLatency { - continue - } - if maxLatency != 0 && maxLatency < min { - continue - } - for _, sd := range b.buffer { - if sd == nil { - break - } - if minLatency != 0 || maxLatency != 0 { - d := sd.EndTime.Sub(sd.StartTime) - if d < minLatency { - continue - } - if maxLatency != 0 && d > maxLatency { - continue - } - } - out = append(out, sd) - } - } - return out -} - -// spanStore keeps track of spans stored for a particular span name. -// -// It contains all active spans; a sample of spans for failed requests, -// categorized by error code; and a sample of spans for successful requests, -// bucketed by latency. -type spanStore struct { - mu sync.Mutex // protects everything below. - active map[SpanInterface]struct{} - errors map[int32]*bucket - latency []bucket - maxSpansPerErrorBucket int -} - -// newSpanStore creates a span store. -func newSpanStore(name string, latencyBucketSize int, errorBucketSize int) *spanStore { - s := &spanStore{ - active: make(map[SpanInterface]struct{}), - latency: make([]bucket, len(defaultLatencies)+1), - maxSpansPerErrorBucket: errorBucketSize, - } - for i := range s.latency { - s.latency[i] = makeBucket(latencyBucketSize) - } - return s -} - -// spanStoreForName returns the spanStore for the given name. -// -// It returns nil if it doesn't exist. -func spanStoreForName(name string) *spanStore { - var s *spanStore - ssmu.RLock() - s, _ = spanStores[name] - ssmu.RUnlock() - return s -} - -// spanStoreForNameCreateIfNew returns the spanStore for the given name. -// -// It creates it if it didn't exist. -func spanStoreForNameCreateIfNew(name string) *spanStore { - ssmu.RLock() - s, ok := spanStores[name] - ssmu.RUnlock() - if ok { - return s - } - ssmu.Lock() - defer ssmu.Unlock() - s, ok = spanStores[name] - if ok { - return s - } - s = newSpanStore(name, defaultBucketSize, defaultBucketSize) - spanStores[name] = s - return s -} - -// spanStoreSetSize resizes the spanStore for the given name. -// -// It creates it if it didn't exist. -func spanStoreSetSize(name string, latencyBucketSize int, errorBucketSize int) { - ssmu.RLock() - s, ok := spanStores[name] - ssmu.RUnlock() - if ok { - s.resize(latencyBucketSize, errorBucketSize) - return - } - ssmu.Lock() - defer ssmu.Unlock() - s, ok = spanStores[name] - if ok { - s.resize(latencyBucketSize, errorBucketSize) - return - } - s = newSpanStore(name, latencyBucketSize, errorBucketSize) - spanStores[name] = s -} - -func (s *spanStore) resize(latencyBucketSize int, errorBucketSize int) { - s.mu.Lock() - for i := range s.latency { - s.latency[i].resize(latencyBucketSize) - } - for _, b := range s.errors { - b.resize(errorBucketSize) - } - s.maxSpansPerErrorBucket = errorBucketSize - s.mu.Unlock() -} - -// add adds a span to the active bucket of the spanStore. -func (s *spanStore) add(span SpanInterface) { - s.mu.Lock() - s.active[span] = struct{}{} - s.mu.Unlock() -} - -// finished removes a span from the active set, and adds a corresponding -// SpanData to a latency or error bucket. -func (s *spanStore) finished(span SpanInterface, sd *SpanData) { - latency := sd.EndTime.Sub(sd.StartTime) - if latency < 0 { - latency = 0 - } - code := sd.Status.Code - - s.mu.Lock() - delete(s.active, span) - if code == 0 { - s.latency[latencyBucket(latency)].add(sd) - } else { - if s.errors == nil { - s.errors = make(map[int32]*bucket) - } - if b := s.errors[code]; b != nil { - b.add(sd) - } else { - b := makeBucket(s.maxSpansPerErrorBucket) - s.errors[code] = &b - b.add(sd) - } - } - s.mu.Unlock() -} diff --git a/vendor/go.opencensus.io/trace/status_codes.go b/vendor/go.opencensus.io/trace/status_codes.go deleted file mode 100644 index ec60effd10..0000000000 --- a/vendor/go.opencensus.io/trace/status_codes.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -// Status codes for use with Span.SetStatus. These correspond to the status -// codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto -const ( - StatusCodeOK = 0 - StatusCodeCancelled = 1 - StatusCodeUnknown = 2 - StatusCodeInvalidArgument = 3 - StatusCodeDeadlineExceeded = 4 - StatusCodeNotFound = 5 - StatusCodeAlreadyExists = 6 - StatusCodePermissionDenied = 7 - StatusCodeResourceExhausted = 8 - StatusCodeFailedPrecondition = 9 - StatusCodeAborted = 10 - StatusCodeOutOfRange = 11 - StatusCodeUnimplemented = 12 - StatusCodeInternal = 13 - StatusCodeUnavailable = 14 - StatusCodeDataLoss = 15 - StatusCodeUnauthenticated = 16 -) diff --git a/vendor/go.opencensus.io/trace/trace.go b/vendor/go.opencensus.io/trace/trace.go deleted file mode 100644 index 861df9d391..0000000000 --- a/vendor/go.opencensus.io/trace/trace.go +++ /dev/null @@ -1,595 +0,0 @@ -// Copyright 2017, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "context" - crand "crypto/rand" - "encoding/binary" - "fmt" - "math/rand" - "sync" - "sync/atomic" - "time" - - "go.opencensus.io/internal" - "go.opencensus.io/trace/tracestate" -) - -type tracer struct{} - -var _ Tracer = &tracer{} - -// Span represents a span of a trace. It has an associated SpanContext, and -// stores data accumulated while the span is active. -// -// Ideally users should interact with Spans by calling the functions in this -// package that take a Context parameter. -type span struct { - // data contains information recorded about the span. - // - // It will be non-nil if we are exporting the span or recording events for it. - // Otherwise, data is nil, and the Span is simply a carrier for the - // SpanContext, so that the trace ID is propagated. - data *SpanData - mu sync.Mutex // protects the contents of *data (but not the pointer value.) - spanContext SpanContext - - // lruAttributes are capped at configured limit. When the capacity is reached an oldest entry - // is removed to create room for a new entry. - lruAttributes *lruMap - - // annotations are stored in FIFO queue capped by configured limit. - annotations *evictedQueue - - // messageEvents are stored in FIFO queue capped by configured limit. - messageEvents *evictedQueue - - // links are stored in FIFO queue capped by configured limit. - links *evictedQueue - - // spanStore is the spanStore this span belongs to, if any, otherwise it is nil. - *spanStore - endOnce sync.Once - - executionTracerTaskEnd func() // ends the execution tracer span -} - -// IsRecordingEvents returns true if events are being recorded for this span. -// Use this check to avoid computing expensive annotations when they will never -// be used. -func (s *span) IsRecordingEvents() bool { - if s == nil { - return false - } - return s.data != nil -} - -// TraceOptions contains options associated with a trace span. -type TraceOptions uint32 - -// IsSampled returns true if the span will be exported. -func (sc SpanContext) IsSampled() bool { - return sc.TraceOptions.IsSampled() -} - -// setIsSampled sets the TraceOptions bit that determines whether the span will be exported. -func (sc *SpanContext) setIsSampled(sampled bool) { - if sampled { - sc.TraceOptions |= 1 - } else { - sc.TraceOptions &= ^TraceOptions(1) - } -} - -// IsSampled returns true if the span will be exported. -func (t TraceOptions) IsSampled() bool { - return t&1 == 1 -} - -// SpanContext contains the state that must propagate across process boundaries. -// -// SpanContext is not an implementation of context.Context. -// TODO: add reference to external Census docs for SpanContext. -type SpanContext struct { - TraceID TraceID - SpanID SpanID - TraceOptions TraceOptions - Tracestate *tracestate.Tracestate -} - -type contextKey struct{} - -// FromContext returns the Span stored in a context, or nil if there isn't one. -func (t *tracer) FromContext(ctx context.Context) *Span { - s, _ := ctx.Value(contextKey{}).(*Span) - return s -} - -// NewContext returns a new context with the given Span attached. -func (t *tracer) NewContext(parent context.Context, s *Span) context.Context { - return context.WithValue(parent, contextKey{}, s) -} - -// All available span kinds. Span kind must be either one of these values. -const ( - SpanKindUnspecified = iota - SpanKindServer - SpanKindClient -) - -// StartOptions contains options concerning how a span is started. -type StartOptions struct { - // Sampler to consult for this Span. If provided, it is always consulted. - // - // If not provided, then the behavior differs based on whether - // the parent of this Span is remote, local, or there is no parent. - // In the case of a remote parent or no parent, the - // default sampler (see Config) will be consulted. Otherwise, - // when there is a non-remote parent, no new sampling decision will be made: - // we will preserve the sampling of the parent. - Sampler Sampler - - // SpanKind represents the kind of a span. If none is set, - // SpanKindUnspecified is used. - SpanKind int -} - -// StartOption apply changes to StartOptions. -type StartOption func(*StartOptions) - -// WithSpanKind makes new spans to be created with the given kind. -func WithSpanKind(spanKind int) StartOption { - return func(o *StartOptions) { - o.SpanKind = spanKind - } -} - -// WithSampler makes new spans to be be created with a custom sampler. -// Otherwise, the global sampler is used. -func WithSampler(sampler Sampler) StartOption { - return func(o *StartOptions) { - o.Sampler = sampler - } -} - -// StartSpan starts a new child span of the current span in the context. If -// there is no span in the context, creates a new trace and span. -// -// Returned context contains the newly created span. You can use it to -// propagate the returned span in process. -func (t *tracer) StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span) { - var opts StartOptions - var parent SpanContext - if p := t.FromContext(ctx); p != nil { - if ps, ok := p.internal.(*span); ok { - ps.addChild() - } - parent = p.SpanContext() - } - for _, op := range o { - op(&opts) - } - span := startSpanInternal(name, parent != SpanContext{}, parent, false, opts) - - ctx, end := startExecutionTracerTask(ctx, name) - span.executionTracerTaskEnd = end - extSpan := NewSpan(span) - return t.NewContext(ctx, extSpan), extSpan -} - -// StartSpanWithRemoteParent starts a new child span of the span from the given parent. -// -// If the incoming context contains a parent, it ignores. StartSpanWithRemoteParent is -// preferred for cases where the parent is propagated via an incoming request. -// -// Returned context contains the newly created span. You can use it to -// propagate the returned span in process. -func (t *tracer) StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span) { - var opts StartOptions - for _, op := range o { - op(&opts) - } - span := startSpanInternal(name, parent != SpanContext{}, parent, true, opts) - ctx, end := startExecutionTracerTask(ctx, name) - span.executionTracerTaskEnd = end - extSpan := NewSpan(span) - return t.NewContext(ctx, extSpan), extSpan -} - -func startSpanInternal(name string, hasParent bool, parent SpanContext, remoteParent bool, o StartOptions) *span { - s := &span{} - s.spanContext = parent - - cfg := config.Load().(*Config) - if gen, ok := cfg.IDGenerator.(*defaultIDGenerator); ok { - // lazy initialization - gen.init() - } - - if !hasParent { - s.spanContext.TraceID = cfg.IDGenerator.NewTraceID() - } - s.spanContext.SpanID = cfg.IDGenerator.NewSpanID() - sampler := cfg.DefaultSampler - - if !hasParent || remoteParent || o.Sampler != nil { - // If this span is the child of a local span and no Sampler is set in the - // options, keep the parent's TraceOptions. - // - // Otherwise, consult the Sampler in the options if it is non-nil, otherwise - // the default sampler. - if o.Sampler != nil { - sampler = o.Sampler - } - s.spanContext.setIsSampled(sampler(SamplingParameters{ - ParentContext: parent, - TraceID: s.spanContext.TraceID, - SpanID: s.spanContext.SpanID, - Name: name, - HasRemoteParent: remoteParent}).Sample) - } - - if !internal.LocalSpanStoreEnabled && !s.spanContext.IsSampled() { - return s - } - - s.data = &SpanData{ - SpanContext: s.spanContext, - StartTime: time.Now(), - SpanKind: o.SpanKind, - Name: name, - HasRemoteParent: remoteParent, - } - s.lruAttributes = newLruMap(cfg.MaxAttributesPerSpan) - s.annotations = newEvictedQueue(cfg.MaxAnnotationEventsPerSpan) - s.messageEvents = newEvictedQueue(cfg.MaxMessageEventsPerSpan) - s.links = newEvictedQueue(cfg.MaxLinksPerSpan) - - if hasParent { - s.data.ParentSpanID = parent.SpanID - } - if internal.LocalSpanStoreEnabled { - var ss *spanStore - ss = spanStoreForNameCreateIfNew(name) - if ss != nil { - s.spanStore = ss - ss.add(s) - } - } - - return s -} - -// End ends the span. -func (s *span) End() { - if s == nil { - return - } - if s.executionTracerTaskEnd != nil { - s.executionTracerTaskEnd() - } - if !s.IsRecordingEvents() { - return - } - s.endOnce.Do(func() { - exp, _ := exporters.Load().(exportersMap) - mustExport := s.spanContext.IsSampled() && len(exp) > 0 - if s.spanStore != nil || mustExport { - sd := s.makeSpanData() - sd.EndTime = internal.MonotonicEndTime(sd.StartTime) - if s.spanStore != nil { - s.spanStore.finished(s, sd) - } - if mustExport { - for e := range exp { - e.ExportSpan(sd) - } - } - } - }) -} - -// makeSpanData produces a SpanData representing the current state of the Span. -// It requires that s.data is non-nil. -func (s *span) makeSpanData() *SpanData { - var sd SpanData - s.mu.Lock() - sd = *s.data - if s.lruAttributes.len() > 0 { - sd.Attributes = s.lruAttributesToAttributeMap() - sd.DroppedAttributeCount = s.lruAttributes.droppedCount - } - if len(s.annotations.queue) > 0 { - sd.Annotations = s.interfaceArrayToAnnotationArray() - sd.DroppedAnnotationCount = s.annotations.droppedCount - } - if len(s.messageEvents.queue) > 0 { - sd.MessageEvents = s.interfaceArrayToMessageEventArray() - sd.DroppedMessageEventCount = s.messageEvents.droppedCount - } - if len(s.links.queue) > 0 { - sd.Links = s.interfaceArrayToLinksArray() - sd.DroppedLinkCount = s.links.droppedCount - } - s.mu.Unlock() - return &sd -} - -// SpanContext returns the SpanContext of the span. -func (s *span) SpanContext() SpanContext { - if s == nil { - return SpanContext{} - } - return s.spanContext -} - -// SetName sets the name of the span, if it is recording events. -func (s *span) SetName(name string) { - if !s.IsRecordingEvents() { - return - } - s.mu.Lock() - s.data.Name = name - s.mu.Unlock() -} - -// SetStatus sets the status of the span, if it is recording events. -func (s *span) SetStatus(status Status) { - if !s.IsRecordingEvents() { - return - } - s.mu.Lock() - s.data.Status = status - s.mu.Unlock() -} - -func (s *span) interfaceArrayToLinksArray() []Link { - linksArr := make([]Link, 0, len(s.links.queue)) - for _, value := range s.links.queue { - linksArr = append(linksArr, value.(Link)) - } - return linksArr -} - -func (s *span) interfaceArrayToMessageEventArray() []MessageEvent { - messageEventArr := make([]MessageEvent, 0, len(s.messageEvents.queue)) - for _, value := range s.messageEvents.queue { - messageEventArr = append(messageEventArr, value.(MessageEvent)) - } - return messageEventArr -} - -func (s *span) interfaceArrayToAnnotationArray() []Annotation { - annotationArr := make([]Annotation, 0, len(s.annotations.queue)) - for _, value := range s.annotations.queue { - annotationArr = append(annotationArr, value.(Annotation)) - } - return annotationArr -} - -func (s *span) lruAttributesToAttributeMap() map[string]interface{} { - attributes := make(map[string]interface{}, s.lruAttributes.len()) - for _, key := range s.lruAttributes.keys() { - value, ok := s.lruAttributes.get(key) - if ok { - keyStr := key.(string) - attributes[keyStr] = value - } - } - return attributes -} - -func (s *span) copyToCappedAttributes(attributes []Attribute) { - for _, a := range attributes { - s.lruAttributes.add(a.key, a.value) - } -} - -func (s *span) addChild() { - if !s.IsRecordingEvents() { - return - } - s.mu.Lock() - s.data.ChildSpanCount++ - s.mu.Unlock() -} - -// AddAttributes sets attributes in the span. -// -// Existing attributes whose keys appear in the attributes parameter are overwritten. -func (s *span) AddAttributes(attributes ...Attribute) { - if !s.IsRecordingEvents() { - return - } - s.mu.Lock() - s.copyToCappedAttributes(attributes) - s.mu.Unlock() -} - -func (s *span) printStringInternal(attributes []Attribute, str string) { - now := time.Now() - var am map[string]interface{} - if len(attributes) != 0 { - am = make(map[string]interface{}, len(attributes)) - for _, attr := range attributes { - am[attr.key] = attr.value - } - } - s.mu.Lock() - s.annotations.add(Annotation{ - Time: now, - Message: str, - Attributes: am, - }) - s.mu.Unlock() -} - -// Annotate adds an annotation with attributes. -// Attributes can be nil. -func (s *span) Annotate(attributes []Attribute, str string) { - if !s.IsRecordingEvents() { - return - } - s.printStringInternal(attributes, str) -} - -// Annotatef adds an annotation with attributes. -func (s *span) Annotatef(attributes []Attribute, format string, a ...interface{}) { - if !s.IsRecordingEvents() { - return - } - s.printStringInternal(attributes, fmt.Sprintf(format, a...)) -} - -// AddMessageSendEvent adds a message send event to the span. -// -// messageID is an identifier for the message, which is recommended to be -// unique in this span and the same between the send event and the receive -// event (this allows to identify a message between the sender and receiver). -// For example, this could be a sequence id. -func (s *span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) { - if !s.IsRecordingEvents() { - return - } - now := time.Now() - s.mu.Lock() - s.messageEvents.add(MessageEvent{ - Time: now, - EventType: MessageEventTypeSent, - MessageID: messageID, - UncompressedByteSize: uncompressedByteSize, - CompressedByteSize: compressedByteSize, - }) - s.mu.Unlock() -} - -// AddMessageReceiveEvent adds a message receive event to the span. -// -// messageID is an identifier for the message, which is recommended to be -// unique in this span and the same between the send event and the receive -// event (this allows to identify a message between the sender and receiver). -// For example, this could be a sequence id. -func (s *span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) { - if !s.IsRecordingEvents() { - return - } - now := time.Now() - s.mu.Lock() - s.messageEvents.add(MessageEvent{ - Time: now, - EventType: MessageEventTypeRecv, - MessageID: messageID, - UncompressedByteSize: uncompressedByteSize, - CompressedByteSize: compressedByteSize, - }) - s.mu.Unlock() -} - -// AddLink adds a link to the span. -func (s *span) AddLink(l Link) { - if !s.IsRecordingEvents() { - return - } - s.mu.Lock() - s.links.add(l) - s.mu.Unlock() -} - -func (s *span) String() string { - if s == nil { - return "" - } - if s.data == nil { - return fmt.Sprintf("span %s", s.spanContext.SpanID) - } - s.mu.Lock() - str := fmt.Sprintf("span %s %q", s.spanContext.SpanID, s.data.Name) - s.mu.Unlock() - return str -} - -var config atomic.Value // access atomically - -func init() { - config.Store(&Config{ - DefaultSampler: ProbabilitySampler(defaultSamplingProbability), - IDGenerator: &defaultIDGenerator{}, - MaxAttributesPerSpan: DefaultMaxAttributesPerSpan, - MaxAnnotationEventsPerSpan: DefaultMaxAnnotationEventsPerSpan, - MaxMessageEventsPerSpan: DefaultMaxMessageEventsPerSpan, - MaxLinksPerSpan: DefaultMaxLinksPerSpan, - }) -} - -type defaultIDGenerator struct { - sync.Mutex - - // Please keep these as the first fields - // so that these 8 byte fields will be aligned on addresses - // divisible by 8, on both 32-bit and 64-bit machines when - // performing atomic increments and accesses. - // See: - // * https://github.com/census-instrumentation/opencensus-go/issues/587 - // * https://github.com/census-instrumentation/opencensus-go/issues/865 - // * https://golang.org/pkg/sync/atomic/#pkg-note-BUG - nextSpanID uint64 - spanIDInc uint64 - - traceIDAdd [2]uint64 - traceIDRand *rand.Rand - - initOnce sync.Once -} - -// init initializes the generator on the first call to avoid consuming entropy -// unnecessarily. -func (gen *defaultIDGenerator) init() { - gen.initOnce.Do(func() { - // initialize traceID and spanID generators. - var rngSeed int64 - for _, p := range []interface{}{ - &rngSeed, &gen.traceIDAdd, &gen.nextSpanID, &gen.spanIDInc, - } { - binary.Read(crand.Reader, binary.LittleEndian, p) - } - gen.traceIDRand = rand.New(rand.NewSource(rngSeed)) - gen.spanIDInc |= 1 - }) -} - -// NewSpanID returns a non-zero span ID from a randomly-chosen sequence. -func (gen *defaultIDGenerator) NewSpanID() [8]byte { - var id uint64 - for id == 0 { - id = atomic.AddUint64(&gen.nextSpanID, gen.spanIDInc) - } - var sid [8]byte - binary.LittleEndian.PutUint64(sid[:], id) - return sid -} - -// NewTraceID returns a non-zero trace ID from a randomly-chosen sequence. -// mu should be held while this function is called. -func (gen *defaultIDGenerator) NewTraceID() [16]byte { - var tid [16]byte - // Construct the trace ID from two outputs of traceIDRand, with a constant - // added to each half for additional entropy. - gen.Lock() - binary.LittleEndian.PutUint64(tid[0:8], gen.traceIDRand.Uint64()+gen.traceIDAdd[0]) - binary.LittleEndian.PutUint64(tid[8:16], gen.traceIDRand.Uint64()+gen.traceIDAdd[1]) - gen.Unlock() - return tid -} diff --git a/vendor/go.opencensus.io/trace/trace_api.go b/vendor/go.opencensus.io/trace/trace_api.go deleted file mode 100644 index 9e2c3a9992..0000000000 --- a/vendor/go.opencensus.io/trace/trace_api.go +++ /dev/null @@ -1,265 +0,0 @@ -// Copyright 2020, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "context" -) - -// DefaultTracer is the tracer used when package-level exported functions are invoked. -var DefaultTracer Tracer = &tracer{} - -// Tracer can start spans and access context functions. -type Tracer interface { - - // StartSpan starts a new child span of the current span in the context. If - // there is no span in the context, creates a new trace and span. - // - // Returned context contains the newly created span. You can use it to - // propagate the returned span in process. - StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span) - - // StartSpanWithRemoteParent starts a new child span of the span from the given parent. - // - // If the incoming context contains a parent, it ignores. StartSpanWithRemoteParent is - // preferred for cases where the parent is propagated via an incoming request. - // - // Returned context contains the newly created span. You can use it to - // propagate the returned span in process. - StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span) - - // FromContext returns the Span stored in a context, or nil if there isn't one. - FromContext(ctx context.Context) *Span - - // NewContext returns a new context with the given Span attached. - NewContext(parent context.Context, s *Span) context.Context -} - -// StartSpan starts a new child span of the current span in the context. If -// there is no span in the context, creates a new trace and span. -// -// Returned context contains the newly created span. You can use it to -// propagate the returned span in process. -func StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span) { - return DefaultTracer.StartSpan(ctx, name, o...) -} - -// StartSpanWithRemoteParent starts a new child span of the span from the given parent. -// -// If the incoming context contains a parent, it ignores. StartSpanWithRemoteParent is -// preferred for cases where the parent is propagated via an incoming request. -// -// Returned context contains the newly created span. You can use it to -// propagate the returned span in process. -func StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span) { - return DefaultTracer.StartSpanWithRemoteParent(ctx, name, parent, o...) -} - -// FromContext returns the Span stored in a context, or a Span that is not -// recording events if there isn't one. -func FromContext(ctx context.Context) *Span { - return DefaultTracer.FromContext(ctx) -} - -// NewContext returns a new context with the given Span attached. -func NewContext(parent context.Context, s *Span) context.Context { - return DefaultTracer.NewContext(parent, s) -} - -// SpanInterface represents a span of a trace. It has an associated SpanContext, and -// stores data accumulated while the span is active. -// -// Ideally users should interact with Spans by calling the functions in this -// package that take a Context parameter. -type SpanInterface interface { - - // IsRecordingEvents returns true if events are being recorded for this span. - // Use this check to avoid computing expensive annotations when they will never - // be used. - IsRecordingEvents() bool - - // End ends the span. - End() - - // SpanContext returns the SpanContext of the span. - SpanContext() SpanContext - - // SetName sets the name of the span, if it is recording events. - SetName(name string) - - // SetStatus sets the status of the span, if it is recording events. - SetStatus(status Status) - - // AddAttributes sets attributes in the span. - // - // Existing attributes whose keys appear in the attributes parameter are overwritten. - AddAttributes(attributes ...Attribute) - - // Annotate adds an annotation with attributes. - // Attributes can be nil. - Annotate(attributes []Attribute, str string) - - // Annotatef adds an annotation with attributes. - Annotatef(attributes []Attribute, format string, a ...interface{}) - - // AddMessageSendEvent adds a message send event to the span. - // - // messageID is an identifier for the message, which is recommended to be - // unique in this span and the same between the send event and the receive - // event (this allows to identify a message between the sender and receiver). - // For example, this could be a sequence id. - AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) - - // AddMessageReceiveEvent adds a message receive event to the span. - // - // messageID is an identifier for the message, which is recommended to be - // unique in this span and the same between the send event and the receive - // event (this allows to identify a message between the sender and receiver). - // For example, this could be a sequence id. - AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) - - // AddLink adds a link to the span. - AddLink(l Link) - - // String prints a string representation of a span. - String() string -} - -// NewSpan is a convenience function for creating a *Span out of a *span -func NewSpan(s SpanInterface) *Span { - return &Span{internal: s} -} - -// Span is a struct wrapper around the SpanInt interface, which allows correctly handling -// nil spans, while also allowing the SpanInterface implementation to be swapped out. -type Span struct { - internal SpanInterface -} - -// Internal returns the underlying implementation of the Span -func (s *Span) Internal() SpanInterface { - return s.internal -} - -// IsRecordingEvents returns true if events are being recorded for this span. -// Use this check to avoid computing expensive annotations when they will never -// be used. -func (s *Span) IsRecordingEvents() bool { - if s == nil { - return false - } - return s.internal.IsRecordingEvents() -} - -// End ends the span. -func (s *Span) End() { - if s == nil { - return - } - s.internal.End() -} - -// SpanContext returns the SpanContext of the span. -func (s *Span) SpanContext() SpanContext { - if s == nil { - return SpanContext{} - } - return s.internal.SpanContext() -} - -// SetName sets the name of the span, if it is recording events. -func (s *Span) SetName(name string) { - if !s.IsRecordingEvents() { - return - } - s.internal.SetName(name) -} - -// SetStatus sets the status of the span, if it is recording events. -func (s *Span) SetStatus(status Status) { - if !s.IsRecordingEvents() { - return - } - s.internal.SetStatus(status) -} - -// AddAttributes sets attributes in the span. -// -// Existing attributes whose keys appear in the attributes parameter are overwritten. -func (s *Span) AddAttributes(attributes ...Attribute) { - if !s.IsRecordingEvents() { - return - } - s.internal.AddAttributes(attributes...) -} - -// Annotate adds an annotation with attributes. -// Attributes can be nil. -func (s *Span) Annotate(attributes []Attribute, str string) { - if !s.IsRecordingEvents() { - return - } - s.internal.Annotate(attributes, str) -} - -// Annotatef adds an annotation with attributes. -func (s *Span) Annotatef(attributes []Attribute, format string, a ...interface{}) { - if !s.IsRecordingEvents() { - return - } - s.internal.Annotatef(attributes, format, a...) -} - -// AddMessageSendEvent adds a message send event to the span. -// -// messageID is an identifier for the message, which is recommended to be -// unique in this span and the same between the send event and the receive -// event (this allows to identify a message between the sender and receiver). -// For example, this could be a sequence id. -func (s *Span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) { - if !s.IsRecordingEvents() { - return - } - s.internal.AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize) -} - -// AddMessageReceiveEvent adds a message receive event to the span. -// -// messageID is an identifier for the message, which is recommended to be -// unique in this span and the same between the send event and the receive -// event (this allows to identify a message between the sender and receiver). -// For example, this could be a sequence id. -func (s *Span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) { - if !s.IsRecordingEvents() { - return - } - s.internal.AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize) -} - -// AddLink adds a link to the span. -func (s *Span) AddLink(l Link) { - if !s.IsRecordingEvents() { - return - } - s.internal.AddLink(l) -} - -// String prints a string representation of a span. -func (s *Span) String() string { - if s == nil { - return "" - } - return s.internal.String() -} diff --git a/vendor/go.opencensus.io/trace/trace_go11.go b/vendor/go.opencensus.io/trace/trace_go11.go deleted file mode 100644 index b8fc1e495a..0000000000 --- a/vendor/go.opencensus.io/trace/trace_go11.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build go1.11 -// +build go1.11 - -package trace - -import ( - "context" - t "runtime/trace" -) - -func startExecutionTracerTask(ctx context.Context, name string) (context.Context, func()) { - if !t.IsEnabled() { - // Avoid additional overhead if - // runtime/trace is not enabled. - return ctx, func() {} - } - nctx, task := t.NewTask(ctx, name) - return nctx, task.End -} diff --git a/vendor/go.opencensus.io/trace/trace_nongo11.go b/vendor/go.opencensus.io/trace/trace_nongo11.go deleted file mode 100644 index da488fc874..0000000000 --- a/vendor/go.opencensus.io/trace/trace_nongo11.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !go1.11 -// +build !go1.11 - -package trace - -import ( - "context" -) - -func startExecutionTracerTask(ctx context.Context, name string) (context.Context, func()) { - return ctx, func() {} -} diff --git a/vendor/go.opencensus.io/trace/tracestate/tracestate.go b/vendor/go.opencensus.io/trace/tracestate/tracestate.go deleted file mode 100644 index 2d6c713eb3..0000000000 --- a/vendor/go.opencensus.io/trace/tracestate/tracestate.go +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2018, OpenCensus Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package tracestate implements support for the Tracestate header of the -// W3C TraceContext propagation format. -package tracestate - -import ( - "fmt" - "regexp" -) - -const ( - keyMaxSize = 256 - valueMaxSize = 256 - maxKeyValuePairs = 32 -) - -const ( - keyWithoutVendorFormat = `[a-z][_0-9a-z\-\*\/]{0,255}` - keyWithVendorFormat = `[a-z][_0-9a-z\-\*\/]{0,240}@[a-z][_0-9a-z\-\*\/]{0,13}` - keyFormat = `(` + keyWithoutVendorFormat + `)|(` + keyWithVendorFormat + `)` - valueFormat = `[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]` -) - -var keyValidationRegExp = regexp.MustCompile(`^(` + keyFormat + `)$`) -var valueValidationRegExp = regexp.MustCompile(`^(` + valueFormat + `)$`) - -// Tracestate represents tracing-system specific context in a list of key-value pairs. Tracestate allows different -// vendors propagate additional information and inter-operate with their legacy Id formats. -type Tracestate struct { - entries []Entry -} - -// Entry represents one key-value pair in a list of key-value pair of Tracestate. -type Entry struct { - // Key is an opaque string up to 256 characters printable. It MUST begin with a lowercase letter, - // and can only contain lowercase letters a-z, digits 0-9, underscores _, dashes -, asterisks *, and - // forward slashes /. - Key string - - // Value is an opaque string up to 256 characters printable ASCII RFC0020 characters (i.e., the - // range 0x20 to 0x7E) except comma , and =. - Value string -} - -// Entries returns a slice of Entry. -func (ts *Tracestate) Entries() []Entry { - if ts == nil { - return nil - } - return ts.entries -} - -func (ts *Tracestate) remove(key string) *Entry { - for index, entry := range ts.entries { - if entry.Key == key { - ts.entries = append(ts.entries[:index], ts.entries[index+1:]...) - return &entry - } - } - return nil -} - -func (ts *Tracestate) add(entries []Entry) error { - for _, entry := range entries { - ts.remove(entry.Key) - } - if len(ts.entries)+len(entries) > maxKeyValuePairs { - return fmt.Errorf("adding %d key-value pairs to current %d pairs exceeds the limit of %d", - len(entries), len(ts.entries), maxKeyValuePairs) - } - ts.entries = append(entries, ts.entries...) - return nil -} - -func isValid(entry Entry) bool { - return keyValidationRegExp.MatchString(entry.Key) && - valueValidationRegExp.MatchString(entry.Value) -} - -func containsDuplicateKey(entries ...Entry) (string, bool) { - keyMap := make(map[string]int) - for _, entry := range entries { - if _, ok := keyMap[entry.Key]; ok { - return entry.Key, true - } - keyMap[entry.Key] = 1 - } - return "", false -} - -func areEntriesValid(entries ...Entry) (*Entry, bool) { - for _, entry := range entries { - if !isValid(entry) { - return &entry, false - } - } - return nil, true -} - -// New creates a Tracestate object from a parent and/or entries (key-value pair). -// Entries from the parent are copied if present. The entries passed to this function -// are inserted in front of those copied from the parent. If an entry copied from the -// parent contains the same key as one of the entry in entries then the entry copied -// from the parent is removed. See add func. -// -// An error is returned with nil Tracestate if -// 1. one or more entry in entries is invalid. -// 2. two or more entries in the input entries have the same key. -// 3. the number of entries combined from the parent and the input entries exceeds maxKeyValuePairs. -// (duplicate entry is counted only once). -func New(parent *Tracestate, entries ...Entry) (*Tracestate, error) { - if parent == nil && len(entries) == 0 { - return nil, nil - } - if entry, ok := areEntriesValid(entries...); !ok { - return nil, fmt.Errorf("key-value pair {%s, %s} is invalid", entry.Key, entry.Value) - } - - if key, duplicate := containsDuplicateKey(entries...); duplicate { - return nil, fmt.Errorf("contains duplicate keys (%s)", key) - } - - tracestate := Tracestate{} - - if parent != nil && len(parent.entries) > 0 { - tracestate.entries = append([]Entry{}, parent.entries...) - } - - err := tracestate.add(entries) - if err != nil { - return nil, err - } - return &tracestate, nil -} diff --git a/vendor/go.opencensus.io/LICENSE b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/LICENSE similarity index 99% rename from vendor/go.opencensus.io/LICENSE rename to vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/LICENSE index 7a4a3ea242..261eeb9e9f 100644 --- a/vendor/go.opencensus.io/LICENSE +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/LICENSE @@ -1,4 +1,3 @@ - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -199,4 +198,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/config.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/config.go new file mode 100644 index 0000000000..d9b91a24b1 --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/config.go @@ -0,0 +1,187 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + +import ( + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/propagation" + semconv "go.opentelemetry.io/otel/semconv/v1.17.0" + "go.opentelemetry.io/otel/trace" +) + +const ( + // instrumentationName is the name of this instrumentation package. + instrumentationName = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + // GRPCStatusCodeKey is convention for numeric status code of a gRPC request. + GRPCStatusCodeKey = attribute.Key("rpc.grpc.status_code") +) + +// Filter is a predicate used to determine whether a given request in +// interceptor info should be traced. A Filter must return true if +// the request should be traced. +type Filter func(*InterceptorInfo) bool + +// config is a group of options for this instrumentation. +type config struct { + Filter Filter + Propagators propagation.TextMapPropagator + TracerProvider trace.TracerProvider + MeterProvider metric.MeterProvider + SpanStartOptions []trace.SpanStartOption + + ReceivedEvent bool + SentEvent bool + + meter metric.Meter + rpcServerDuration metric.Int64Histogram +} + +// Option applies an option value for a config. +type Option interface { + apply(*config) +} + +// newConfig returns a config configured with all the passed Options. +func newConfig(opts []Option) *config { + c := &config{ + Propagators: otel.GetTextMapPropagator(), + TracerProvider: otel.GetTracerProvider(), + MeterProvider: otel.GetMeterProvider(), + } + for _, o := range opts { + o.apply(c) + } + + c.meter = c.MeterProvider.Meter( + instrumentationName, + metric.WithInstrumentationVersion(Version()), + metric.WithSchemaURL(semconv.SchemaURL), + ) + var err error + c.rpcServerDuration, err = c.meter.Int64Histogram("rpc.server.duration", + metric.WithDescription("Measures the duration of inbound RPC."), + metric.WithUnit("ms")) + if err != nil { + otel.Handle(err) + } + + return c +} + +type propagatorsOption struct{ p propagation.TextMapPropagator } + +func (o propagatorsOption) apply(c *config) { + if o.p != nil { + c.Propagators = o.p + } +} + +// WithPropagators returns an Option to use the Propagators when extracting +// and injecting trace context from requests. +func WithPropagators(p propagation.TextMapPropagator) Option { + return propagatorsOption{p: p} +} + +type tracerProviderOption struct{ tp trace.TracerProvider } + +func (o tracerProviderOption) apply(c *config) { + if o.tp != nil { + c.TracerProvider = o.tp + } +} + +// WithInterceptorFilter returns an Option to use the request filter. +func WithInterceptorFilter(f Filter) Option { + return interceptorFilterOption{f: f} +} + +type interceptorFilterOption struct { + f Filter +} + +func (o interceptorFilterOption) apply(c *config) { + if o.f != nil { + c.Filter = o.f + } +} + +// WithTracerProvider returns an Option to use the TracerProvider when +// creating a Tracer. +func WithTracerProvider(tp trace.TracerProvider) Option { + return tracerProviderOption{tp: tp} +} + +type meterProviderOption struct{ mp metric.MeterProvider } + +func (o meterProviderOption) apply(c *config) { + if o.mp != nil { + c.MeterProvider = o.mp + } +} + +// WithMeterProvider returns an Option to use the MeterProvider when +// creating a Meter. If this option is not provide the global MeterProvider will be used. +func WithMeterProvider(mp metric.MeterProvider) Option { + return meterProviderOption{mp: mp} +} + +// Event type that can be recorded, see WithMessageEvents. +type Event int + +// Different types of events that can be recorded, see WithMessageEvents. +const ( + ReceivedEvents Event = iota + SentEvents +) + +type messageEventsProviderOption struct { + events []Event +} + +func (m messageEventsProviderOption) apply(c *config) { + for _, e := range m.events { + switch e { + case ReceivedEvents: + c.ReceivedEvent = true + case SentEvents: + c.SentEvent = true + } + } +} + +// WithMessageEvents configures the Handler to record the specified events +// (span.AddEvent) on spans. By default only summary attributes are added at the +// end of the request. +// +// Valid events are: +// - ReceivedEvents: Record the number of bytes read after every gRPC read operation. +// - SentEvents: Record the number of bytes written after every gRPC write operation. +func WithMessageEvents(events ...Event) Option { + return messageEventsProviderOption{events: events} +} + +type spanStartOption struct{ opts []trace.SpanStartOption } + +func (o spanStartOption) apply(c *config) { + c.SpanStartOptions = append(c.SpanStartOptions, o.opts...) +} + +// WithSpanOptions configures an additional set of +// trace.SpanOptions, which are applied to each new span. +func WithSpanOptions(opts ...trace.SpanStartOption) Option { + return spanStartOption{opts} +} diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/doc.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/doc.go new file mode 100644 index 0000000000..a993e0fc92 --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/doc.go @@ -0,0 +1,45 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/* +Package otelgrpc is the instrumentation library for [google.golang.org/grpc] + +For now you can instrument your program which use [google.golang.org/grpc] in two ways: + + - by [grpc.UnaryClientInterceptor], [grpc.UnaryServerInterceptor], [grpc.StreamClientInterceptor], [grpc.StreamServerInterceptor] + - by [stats.Handler] + +Notice: Do not use both interceptors and [stats.Handler] at the same time! If so, you will get duplicated spans and the parent/child relationships between spans will also be broken. + +We strongly still recommand you to use [stats.Handler], mainly for two reasons: + +Functional advantages: [stats.Handler] has more information for user to build more flexible and granular metric, for example + + - multiple different types of represent "data length": In [stats.InPayload], there exists "Length", "CompressedLength", "WireLength" to denote the size of uncompressed, compressed payload data, with or without framing data. But in interceptors, we can only got uncompressed data, and this feature is also removed due to performance problem. + + - more accurate timestamp: [stats.InPayload]'s "RecvTime" and [stats.OutPayload]'s "SentTime" records more accurate timestamp that server got and sent the message, the timestamp recorded by interceptors depends on the location of this interceptors in the total interceptor chain. + + - some other use cases: for example, catch failure of decoding message. + +Performance advantages: If too many interceptors are registered in a service, the interceptor chain can become too long, which increases the latency and processing time of the entire RPC call. + +[stats.Handler]: https://pkg.go.dev/google.golang.org/grpc/stats#Handler +[grpc.UnaryClientInterceptor]: https://pkg.go.dev/google.golang.org/grpc#UnaryClientInterceptor +[grpc.UnaryServerInterceptor]: https://pkg.go.dev/google.golang.org/grpc#UnaryServerInterceptor +[grpc.StreamClientInterceptor]: https://pkg.go.dev/google.golang.org/grpc#StreamClientInterceptor +[grpc.StreamServerInterceptor]: https://pkg.go.dev/google.golang.org/grpc#StreamServerInterceptor +[stats.OutPayload]: https://pkg.go.dev/google.golang.org/grpc/stats#OutPayload +[stats.InPayload]: https://pkg.go.dev/google.golang.org/grpc/stats#InPayload +*/ +package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go new file mode 100644 index 0000000000..561154061f --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go @@ -0,0 +1,580 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + +// gRPC tracing middleware +// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md +import ( + "context" + "io" + "net" + "strconv" + "time" + + "google.golang.org/grpc" + grpc_codes "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" + + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/metric" + semconv "go.opentelemetry.io/otel/semconv/v1.17.0" + "go.opentelemetry.io/otel/trace" +) + +type messageType attribute.KeyValue + +// Event adds an event of the messageType to the span associated with the +// passed context with a message id. +func (m messageType) Event(ctx context.Context, id int, _ interface{}) { + span := trace.SpanFromContext(ctx) + if !span.IsRecording() { + return + } + span.AddEvent("message", trace.WithAttributes( + attribute.KeyValue(m), + RPCMessageIDKey.Int(id), + )) +} + +var ( + messageSent = messageType(RPCMessageTypeSent) + messageReceived = messageType(RPCMessageTypeReceived) +) + +// UnaryClientInterceptor returns a grpc.UnaryClientInterceptor suitable +// for use in a grpc.Dial call. +func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor { + cfg := newConfig(opts) + tracer := cfg.TracerProvider.Tracer( + instrumentationName, + trace.WithInstrumentationVersion(Version()), + ) + + return func( + ctx context.Context, + method string, + req, reply interface{}, + cc *grpc.ClientConn, + invoker grpc.UnaryInvoker, + callOpts ...grpc.CallOption, + ) error { + i := &InterceptorInfo{ + Method: method, + Type: UnaryClient, + } + if cfg.Filter != nil && !cfg.Filter(i) { + return invoker(ctx, method, req, reply, cc, callOpts...) + } + + name, attr := spanInfo(method, cc.Target()) + + startOpts := append([]trace.SpanStartOption{ + trace.WithSpanKind(trace.SpanKindClient), + trace.WithAttributes(attr...)}, + cfg.SpanStartOptions..., + ) + + ctx, span := tracer.Start( + ctx, + name, + startOpts..., + ) + defer span.End() + + ctx = inject(ctx, cfg.Propagators) + + if cfg.SentEvent { + messageSent.Event(ctx, 1, req) + } + + err := invoker(ctx, method, req, reply, cc, callOpts...) + + if cfg.ReceivedEvent { + messageReceived.Event(ctx, 1, reply) + } + + if err != nil { + s, _ := status.FromError(err) + span.SetStatus(codes.Error, s.Message()) + span.SetAttributes(statusCodeAttr(s.Code())) + } else { + span.SetAttributes(statusCodeAttr(grpc_codes.OK)) + } + + return err + } +} + +type streamEventType int + +type streamEvent struct { + Type streamEventType + Err error +} + +const ( + receiveEndEvent streamEventType = iota + errorEvent +) + +// clientStream wraps around the embedded grpc.ClientStream, and intercepts the RecvMsg and +// SendMsg method call. +type clientStream struct { + grpc.ClientStream + + desc *grpc.StreamDesc + events chan streamEvent + eventsDone chan struct{} + finished chan error + + receivedEvent bool + sentEvent bool + + receivedMessageID int + sentMessageID int +} + +var _ = proto.Marshal + +func (w *clientStream) RecvMsg(m interface{}) error { + err := w.ClientStream.RecvMsg(m) + + if err == nil && !w.desc.ServerStreams { + w.sendStreamEvent(receiveEndEvent, nil) + } else if err == io.EOF { + w.sendStreamEvent(receiveEndEvent, nil) + } else if err != nil { + w.sendStreamEvent(errorEvent, err) + } else { + w.receivedMessageID++ + + if w.receivedEvent { + messageReceived.Event(w.Context(), w.receivedMessageID, m) + } + } + + return err +} + +func (w *clientStream) SendMsg(m interface{}) error { + err := w.ClientStream.SendMsg(m) + + w.sentMessageID++ + + if w.sentEvent { + messageSent.Event(w.Context(), w.sentMessageID, m) + } + + if err != nil { + w.sendStreamEvent(errorEvent, err) + } + + return err +} + +func (w *clientStream) Header() (metadata.MD, error) { + md, err := w.ClientStream.Header() + + if err != nil { + w.sendStreamEvent(errorEvent, err) + } + + return md, err +} + +func (w *clientStream) CloseSend() error { + err := w.ClientStream.CloseSend() + + if err != nil { + w.sendStreamEvent(errorEvent, err) + } + + return err +} + +func wrapClientStream(ctx context.Context, s grpc.ClientStream, desc *grpc.StreamDesc, cfg *config) *clientStream { + events := make(chan streamEvent) + eventsDone := make(chan struct{}) + finished := make(chan error) + + go func() { + defer close(eventsDone) + + for { + select { + case event := <-events: + switch event.Type { + case receiveEndEvent: + finished <- nil + return + case errorEvent: + finished <- event.Err + return + } + case <-ctx.Done(): + finished <- ctx.Err() + return + } + } + }() + + return &clientStream{ + ClientStream: s, + desc: desc, + events: events, + eventsDone: eventsDone, + finished: finished, + receivedEvent: cfg.ReceivedEvent, + sentEvent: cfg.SentEvent, + } +} + +func (w *clientStream) sendStreamEvent(eventType streamEventType, err error) { + select { + case <-w.eventsDone: + case w.events <- streamEvent{Type: eventType, Err: err}: + } +} + +// StreamClientInterceptor returns a grpc.StreamClientInterceptor suitable +// for use in a grpc.Dial call. +func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor { + cfg := newConfig(opts) + tracer := cfg.TracerProvider.Tracer( + instrumentationName, + trace.WithInstrumentationVersion(Version()), + ) + + return func( + ctx context.Context, + desc *grpc.StreamDesc, + cc *grpc.ClientConn, + method string, + streamer grpc.Streamer, + callOpts ...grpc.CallOption, + ) (grpc.ClientStream, error) { + i := &InterceptorInfo{ + Method: method, + Type: StreamClient, + } + if cfg.Filter != nil && !cfg.Filter(i) { + return streamer(ctx, desc, cc, method, callOpts...) + } + + name, attr := spanInfo(method, cc.Target()) + + startOpts := append([]trace.SpanStartOption{ + trace.WithSpanKind(trace.SpanKindClient), + trace.WithAttributes(attr...)}, + cfg.SpanStartOptions..., + ) + + ctx, span := tracer.Start( + ctx, + name, + startOpts..., + ) + + ctx = inject(ctx, cfg.Propagators) + + s, err := streamer(ctx, desc, cc, method, callOpts...) + if err != nil { + grpcStatus, _ := status.FromError(err) + span.SetStatus(codes.Error, grpcStatus.Message()) + span.SetAttributes(statusCodeAttr(grpcStatus.Code())) + span.End() + return s, err + } + stream := wrapClientStream(ctx, s, desc, cfg) + + go func() { + err := <-stream.finished + + if err != nil { + s, _ := status.FromError(err) + span.SetStatus(codes.Error, s.Message()) + span.SetAttributes(statusCodeAttr(s.Code())) + } else { + span.SetAttributes(statusCodeAttr(grpc_codes.OK)) + } + + span.End() + }() + + return stream, nil + } +} + +// UnaryServerInterceptor returns a grpc.UnaryServerInterceptor suitable +// for use in a grpc.NewServer call. +func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor { + cfg := newConfig(opts) + tracer := cfg.TracerProvider.Tracer( + instrumentationName, + trace.WithInstrumentationVersion(Version()), + ) + + return func( + ctx context.Context, + req interface{}, + info *grpc.UnaryServerInfo, + handler grpc.UnaryHandler, + ) (interface{}, error) { + i := &InterceptorInfo{ + UnaryServerInfo: info, + Type: UnaryServer, + } + if cfg.Filter != nil && !cfg.Filter(i) { + return handler(ctx, req) + } + + ctx = extract(ctx, cfg.Propagators) + name, attr := spanInfo(info.FullMethod, peerFromCtx(ctx)) + + startOpts := append([]trace.SpanStartOption{ + trace.WithSpanKind(trace.SpanKindServer), + trace.WithAttributes(attr...)}, + cfg.SpanStartOptions..., + ) + + ctx, span := tracer.Start( + trace.ContextWithRemoteSpanContext(ctx, trace.SpanContextFromContext(ctx)), + name, + startOpts..., + ) + defer span.End() + + if cfg.ReceivedEvent { + messageReceived.Event(ctx, 1, req) + } + + var statusCode grpc_codes.Code + defer func(t time.Time) { + elapsedTime := time.Since(t) / time.Millisecond + attr = append(attr, semconv.RPCGRPCStatusCodeKey.Int64(int64(statusCode))) + o := metric.WithAttributes(attr...) + cfg.rpcServerDuration.Record(ctx, int64(elapsedTime), o) + }(time.Now()) + + resp, err := handler(ctx, req) + if err != nil { + s, _ := status.FromError(err) + statusCode, msg := serverStatus(s) + span.SetStatus(statusCode, msg) + span.SetAttributes(statusCodeAttr(s.Code())) + if cfg.SentEvent { + messageSent.Event(ctx, 1, s.Proto()) + } + } else { + statusCode = grpc_codes.OK + span.SetAttributes(statusCodeAttr(grpc_codes.OK)) + if cfg.SentEvent { + messageSent.Event(ctx, 1, resp) + } + } + + return resp, err + } +} + +// serverStream wraps around the embedded grpc.ServerStream, and intercepts the RecvMsg and +// SendMsg method call. +type serverStream struct { + grpc.ServerStream + ctx context.Context + + receivedMessageID int + sentMessageID int + + receivedEvent bool + sentEvent bool +} + +func (w *serverStream) Context() context.Context { + return w.ctx +} + +func (w *serverStream) RecvMsg(m interface{}) error { + err := w.ServerStream.RecvMsg(m) + + if err == nil { + w.receivedMessageID++ + if w.receivedEvent { + messageReceived.Event(w.Context(), w.receivedMessageID, m) + } + } + + return err +} + +func (w *serverStream) SendMsg(m interface{}) error { + err := w.ServerStream.SendMsg(m) + + w.sentMessageID++ + if w.sentEvent { + messageSent.Event(w.Context(), w.sentMessageID, m) + } + + return err +} + +func wrapServerStream(ctx context.Context, ss grpc.ServerStream, cfg *config) *serverStream { + return &serverStream{ + ServerStream: ss, + ctx: ctx, + receivedEvent: cfg.ReceivedEvent, + sentEvent: cfg.SentEvent, + } +} + +// StreamServerInterceptor returns a grpc.StreamServerInterceptor suitable +// for use in a grpc.NewServer call. +func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor { + cfg := newConfig(opts) + tracer := cfg.TracerProvider.Tracer( + instrumentationName, + trace.WithInstrumentationVersion(Version()), + ) + + return func( + srv interface{}, + ss grpc.ServerStream, + info *grpc.StreamServerInfo, + handler grpc.StreamHandler, + ) error { + ctx := ss.Context() + i := &InterceptorInfo{ + StreamServerInfo: info, + Type: StreamServer, + } + if cfg.Filter != nil && !cfg.Filter(i) { + return handler(srv, wrapServerStream(ctx, ss, cfg)) + } + + ctx = extract(ctx, cfg.Propagators) + name, attr := spanInfo(info.FullMethod, peerFromCtx(ctx)) + + startOpts := append([]trace.SpanStartOption{ + trace.WithSpanKind(trace.SpanKindServer), + trace.WithAttributes(attr...)}, + cfg.SpanStartOptions..., + ) + + ctx, span := tracer.Start( + trace.ContextWithRemoteSpanContext(ctx, trace.SpanContextFromContext(ctx)), + name, + startOpts..., + ) + defer span.End() + + err := handler(srv, wrapServerStream(ctx, ss, cfg)) + if err != nil { + s, _ := status.FromError(err) + statusCode, msg := serverStatus(s) + span.SetStatus(statusCode, msg) + span.SetAttributes(statusCodeAttr(s.Code())) + } else { + span.SetAttributes(statusCodeAttr(grpc_codes.OK)) + } + + return err + } +} + +// spanInfo returns a span name and all appropriate attributes from the gRPC +// method and peer address. +func spanInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue) { + name, mAttrs := internal.ParseFullMethod(fullMethod) + peerAttrs := peerAttr(peerAddress) + + attrs := make([]attribute.KeyValue, 0, 1+len(mAttrs)+len(peerAttrs)) + attrs = append(attrs, RPCSystemGRPC) + attrs = append(attrs, mAttrs...) + attrs = append(attrs, peerAttrs...) + return name, attrs +} + +// peerAttr returns attributes about the peer address. +func peerAttr(addr string) []attribute.KeyValue { + host, p, err := net.SplitHostPort(addr) + if err != nil { + return nil + } + + if host == "" { + host = "127.0.0.1" + } + port, err := strconv.Atoi(p) + if err != nil { + return nil + } + + var attr []attribute.KeyValue + if ip := net.ParseIP(host); ip != nil { + attr = []attribute.KeyValue{ + semconv.NetSockPeerAddr(host), + semconv.NetSockPeerPort(port), + } + } else { + attr = []attribute.KeyValue{ + semconv.NetPeerName(host), + semconv.NetPeerPort(port), + } + } + + return attr +} + +// peerFromCtx returns a peer address from a context, if one exists. +func peerFromCtx(ctx context.Context) string { + p, ok := peer.FromContext(ctx) + if !ok { + return "" + } + return p.Addr.String() +} + +// statusCodeAttr returns status code attribute based on given gRPC code. +func statusCodeAttr(c grpc_codes.Code) attribute.KeyValue { + return GRPCStatusCodeKey.Int64(int64(c)) +} + +// serverStatus returns a span status code and message for a given gRPC +// status code. It maps specific gRPC status codes to a corresponding span +// status code and message. This function is intended for use on the server +// side of a gRPC connection. +// +// If the gRPC status code is Unknown, DeadlineExceeded, Unimplemented, +// Internal, Unavailable, or DataLoss, it returns a span status code of Error +// and the message from the gRPC status. Otherwise, it returns a span status +// code of Unset and an empty message. +func serverStatus(grpcStatus *status.Status) (codes.Code, string) { + switch grpcStatus.Code() { + case grpc_codes.Unknown, + grpc_codes.DeadlineExceeded, + grpc_codes.Unimplemented, + grpc_codes.Internal, + grpc_codes.Unavailable, + grpc_codes.DataLoss: + return codes.Error, grpcStatus.Message() + default: + return codes.Unset, "" + } +} diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go new file mode 100644 index 0000000000..f6116946bf --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go @@ -0,0 +1,50 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + +import ( + "google.golang.org/grpc" +) + +// InterceptorType is the flag to define which gRPC interceptor +// the InterceptorInfo object is. +type InterceptorType uint8 + +const ( + // UndefinedInterceptor is the type for the interceptor information that is not + // well initialized or categorized to other types. + UndefinedInterceptor InterceptorType = iota + // UnaryClient is the type for grpc.UnaryClient interceptor. + UnaryClient + // StreamClient is the type for grpc.StreamClient interceptor. + StreamClient + // UnaryServer is the type for grpc.UnaryServer interceptor. + UnaryServer + // StreamServer is the type for grpc.StreamServer interceptor. + StreamServer +) + +// InterceptorInfo is the union of some arguments to four types of +// gRPC interceptors. +type InterceptorInfo struct { + // Method is method name registered to UnaryClient and StreamClient + Method string + // UnaryServerInfo is the metadata for UnaryServer + UnaryServerInfo *grpc.UnaryServerInfo + // StreamServerInfo if the metadata for StreamServer + StreamServerInfo *grpc.StreamServerInfo + // Type is the type for interceptor + Type InterceptorType +} diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal/parse.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal/parse.go new file mode 100644 index 0000000000..cf32a9e978 --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal/parse.go @@ -0,0 +1,51 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package internal // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal" + +import ( + "strings" + + "go.opentelemetry.io/otel/attribute" + semconv "go.opentelemetry.io/otel/semconv/v1.17.0" +) + +// ParseFullMethod returns a span name following the OpenTelemetry semantic +// conventions as well as all applicable span attribute.KeyValue attributes based +// on a gRPC's FullMethod. +// +// Parsing is consistent with grpc-go implementation: +// https://github.com/grpc/grpc-go/blob/v1.57.0/internal/grpcutil/method.go#L26-L39 +func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue) { + if !strings.HasPrefix(fullMethod, "/") { + // Invalid format, does not follow `/package.service/method`. + return fullMethod, nil + } + name := fullMethod[1:] + pos := strings.LastIndex(name, "/") + if pos < 0 { + // Invalid format, does not follow `/package.service/method`. + return name, nil + } + service, method := name[:pos], name[pos+1:] + + var attrs []attribute.KeyValue + if service != "" { + attrs = append(attrs, semconv.RPCService(service)) + } + if method != "" { + attrs = append(attrs, semconv.RPCMethod(method)) + } + return name, attrs +} diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/metadata_supplier.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/metadata_supplier.go new file mode 100644 index 0000000000..d91c6df237 --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/metadata_supplier.go @@ -0,0 +1,98 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + +import ( + "context" + + "google.golang.org/grpc/metadata" + + "go.opentelemetry.io/otel/baggage" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" +) + +type metadataSupplier struct { + metadata *metadata.MD +} + +// assert that metadataSupplier implements the TextMapCarrier interface. +var _ propagation.TextMapCarrier = &metadataSupplier{} + +func (s *metadataSupplier) Get(key string) string { + values := s.metadata.Get(key) + if len(values) == 0 { + return "" + } + return values[0] +} + +func (s *metadataSupplier) Set(key string, value string) { + s.metadata.Set(key, value) +} + +func (s *metadataSupplier) Keys() []string { + out := make([]string, 0, len(*s.metadata)) + for key := range *s.metadata { + out = append(out, key) + } + return out +} + +// Inject injects correlation context and span context into the gRPC +// metadata object. This function is meant to be used on outgoing +// requests. +// Deprecated: Unnecessary public func. +func Inject(ctx context.Context, md *metadata.MD, opts ...Option) { + c := newConfig(opts) + c.Propagators.Inject(ctx, &metadataSupplier{ + metadata: md, + }) +} + +func inject(ctx context.Context, propagators propagation.TextMapPropagator) context.Context { + md, ok := metadata.FromOutgoingContext(ctx) + if !ok { + md = metadata.MD{} + } + propagators.Inject(ctx, &metadataSupplier{ + metadata: &md, + }) + return metadata.NewOutgoingContext(ctx, md) +} + +// Extract returns the correlation context and span context that +// another service encoded in the gRPC metadata object with Inject. +// This function is meant to be used on incoming requests. +// Deprecated: Unnecessary public func. +func Extract(ctx context.Context, md *metadata.MD, opts ...Option) (baggage.Baggage, trace.SpanContext) { + c := newConfig(opts) + ctx = c.Propagators.Extract(ctx, &metadataSupplier{ + metadata: md, + }) + + return baggage.FromContext(ctx), trace.SpanContextFromContext(ctx) +} + +func extract(ctx context.Context, propagators propagation.TextMapPropagator) context.Context { + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + md = metadata.MD{} + } + + return propagators.Extract(ctx, &metadataSupplier{ + metadata: &md, + }) +} diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/semconv.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/semconv.go new file mode 100644 index 0000000000..b65fab308f --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/semconv.go @@ -0,0 +1,52 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + +import ( + "go.opentelemetry.io/otel/attribute" + semconv "go.opentelemetry.io/otel/semconv/v1.17.0" +) + +// Semantic conventions for attribute keys for gRPC. +const ( + // Name of message transmitted or received. + RPCNameKey = attribute.Key("name") + + // Type of message transmitted or received. + RPCMessageTypeKey = attribute.Key("message.type") + + // Identifier of message transmitted or received. + RPCMessageIDKey = attribute.Key("message.id") + + // The compressed size of the message transmitted or received in bytes. + RPCMessageCompressedSizeKey = attribute.Key("message.compressed_size") + + // The uncompressed size of the message transmitted or received in + // bytes. + RPCMessageUncompressedSizeKey = attribute.Key("message.uncompressed_size") +) + +// Semantic conventions for common RPC attributes. +var ( + // Semantic convention for gRPC as the remoting system. + RPCSystemGRPC = semconv.RPCSystemGRPC + + // Semantic convention for a message named message. + RPCNameMessage = RPCNameKey.String("message") + + // Semantic conventions for RPC message types. + RPCMessageTypeSent = RPCMessageTypeKey.String("SENT") + RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED") +) diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go new file mode 100644 index 0000000000..c64a53443b --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go @@ -0,0 +1,187 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + +import ( + "context" + "sync/atomic" + + grpc_codes "google.golang.org/grpc/codes" + "google.golang.org/grpc/stats" + "google.golang.org/grpc/status" + + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal" + "go.opentelemetry.io/otel/codes" + semconv "go.opentelemetry.io/otel/semconv/v1.17.0" + "go.opentelemetry.io/otel/trace" +) + +type gRPCContextKey struct{} + +type gRPCContext struct { + messagesReceived int64 + messagesSent int64 +} + +// NewServerHandler creates a stats.Handler for gRPC server. +func NewServerHandler(opts ...Option) stats.Handler { + h := &serverHandler{ + config: newConfig(opts), + } + + h.tracer = h.config.TracerProvider.Tracer( + instrumentationName, + trace.WithInstrumentationVersion(SemVersion()), + ) + return h +} + +type serverHandler struct { + *config + tracer trace.Tracer +} + +// TagRPC can attach some information to the given context. +func (h *serverHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context { + ctx = extract(ctx, h.config.Propagators) + + name, attrs := internal.ParseFullMethod(info.FullMethodName) + attrs = append(attrs, RPCSystemGRPC) + ctx, _ = h.tracer.Start( + trace.ContextWithRemoteSpanContext(ctx, trace.SpanContextFromContext(ctx)), + name, + trace.WithSpanKind(trace.SpanKindServer), + trace.WithAttributes(attrs...), + ) + + gctx := gRPCContext{} + return context.WithValue(ctx, gRPCContextKey{}, &gctx) +} + +// HandleRPC processes the RPC stats. +func (h *serverHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) { + handleRPC(ctx, rs) +} + +// TagConn can attach some information to the given context. +func (h *serverHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context { + span := trace.SpanFromContext(ctx) + attrs := peerAttr(peerFromCtx(ctx)) + span.SetAttributes(attrs...) + return ctx +} + +// HandleConn processes the Conn stats. +func (h *serverHandler) HandleConn(ctx context.Context, info stats.ConnStats) { +} + +// NewClientHandler creates a stats.Handler for gRPC client. +func NewClientHandler(opts ...Option) stats.Handler { + h := &clientHandler{ + config: newConfig(opts), + } + + h.tracer = h.config.TracerProvider.Tracer( + instrumentationName, + trace.WithInstrumentationVersion(SemVersion()), + ) + + return h +} + +type clientHandler struct { + *config + tracer trace.Tracer +} + +// TagRPC can attach some information to the given context. +func (h *clientHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context { + name, attrs := internal.ParseFullMethod(info.FullMethodName) + attrs = append(attrs, RPCSystemGRPC) + ctx, _ = h.tracer.Start( + ctx, + name, + trace.WithSpanKind(trace.SpanKindClient), + trace.WithAttributes(attrs...), + ) + + gctx := gRPCContext{} + + return inject(context.WithValue(ctx, gRPCContextKey{}, &gctx), h.config.Propagators) +} + +// HandleRPC processes the RPC stats. +func (h *clientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) { + handleRPC(ctx, rs) +} + +// TagConn can attach some information to the given context. +func (h *clientHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context { + span := trace.SpanFromContext(ctx) + attrs := peerAttr(cti.RemoteAddr.String()) + span.SetAttributes(attrs...) + return ctx +} + +// HandleConn processes the Conn stats. +func (h *clientHandler) HandleConn(context.Context, stats.ConnStats) { + // no-op +} + +func handleRPC(ctx context.Context, rs stats.RPCStats) { + span := trace.SpanFromContext(ctx) + gctx, _ := ctx.Value(gRPCContextKey{}).(*gRPCContext) + var messageId int64 + + switch rs := rs.(type) { + case *stats.Begin: + case *stats.InPayload: + if gctx != nil { + messageId = atomic.AddInt64(&gctx.messagesReceived, 1) + } + span.AddEvent("message", + trace.WithAttributes( + semconv.MessageTypeReceived, + semconv.MessageIDKey.Int64(messageId), + semconv.MessageCompressedSizeKey.Int(rs.CompressedLength), + semconv.MessageUncompressedSizeKey.Int(rs.Length), + ), + ) + case *stats.OutPayload: + if gctx != nil { + messageId = atomic.AddInt64(&gctx.messagesSent, 1) + } + + span.AddEvent("message", + trace.WithAttributes( + semconv.MessageTypeSent, + semconv.MessageIDKey.Int64(messageId), + semconv.MessageCompressedSizeKey.Int(rs.CompressedLength), + semconv.MessageUncompressedSizeKey.Int(rs.Length), + ), + ) + case *stats.End: + if rs.Error != nil { + s, _ := status.FromError(rs.Error) + span.SetStatus(codes.Error, s.Message()) + span.SetAttributes(statusCodeAttr(s.Code())) + } else { + span.SetAttributes(statusCodeAttr(grpc_codes.OK)) + } + span.End() + default: + return + } +} diff --git a/vendor/go.opencensus.io/opencensus.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go similarity index 55% rename from vendor/go.opencensus.io/opencensus.go rename to vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go index 11e31f421c..7a8ecebf04 100644 --- a/vendor/go.opencensus.io/opencensus.go +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go @@ -1,4 +1,4 @@ -// Copyright 2017, OpenCensus Authors +// Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,10 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package opencensus contains Go support for OpenCensus. -package opencensus // import "go.opencensus.io" +package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" -// Version is the current release version of OpenCensus in use. +// Version is the current release version of the gRPC instrumentation. func Version() string { - return "0.24.0" + return "0.45.0" + // This string is updated by the pre_release.sh script during release +} + +// SemVersion is the semantic version to be supplied to tracer/meter creation. +// +// Deprecated: Use [Version] instead. +func SemVersion() string { + return Version() } diff --git a/vendor/modules.txt b/vendor/modules.txt index 0eb1a6cc4d..29db9adb70 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -218,9 +218,6 @@ github.com/godbus/dbus/v5 # github.com/gogo/protobuf v1.3.2 ## explicit; go 1.15 github.com/gogo/protobuf/proto -# github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da -## explicit -github.com/golang/groupcache/lru # github.com/golang/protobuf v1.5.4 ## explicit; go 1.17 github.com/golang/protobuf/proto @@ -489,23 +486,10 @@ github.com/yashtewari/glob-intersection # go.etcd.io/bbolt v1.3.9 ## explicit; go 1.17 go.etcd.io/bbolt -# go.opencensus.io v0.24.0 -## explicit; go 1.13 -go.opencensus.io -go.opencensus.io/internal -go.opencensus.io/internal/tagencoding -go.opencensus.io/metric/metricdata -go.opencensus.io/metric/metricproducer -go.opencensus.io/plugin/ocgrpc -go.opencensus.io/resource -go.opencensus.io/stats -go.opencensus.io/stats/internal -go.opencensus.io/stats/view -go.opencensus.io/tag -go.opencensus.io/trace -go.opencensus.io/trace/internal -go.opencensus.io/trace/propagation -go.opencensus.io/trace/tracestate +# go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 +## explicit; go 1.19 +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal # go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 ## explicit; go 1.20 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp From 136345a0677b1f06beb43b43eed8e34a82a5ed3f Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Fri, 3 May 2024 18:37:21 +0200 Subject: [PATCH 2/2] Add missing span.End() Previous commit made clear that `(*externalProcess).Wait()` was missing a call to `span.End()`. Signed-off-by: Albin Kerouanton --- internal/guest/runtime/hcsv2/process.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/guest/runtime/hcsv2/process.go b/internal/guest/runtime/hcsv2/process.go index de84cbc1bf..4859e3b709 100644 --- a/internal/guest/runtime/hcsv2/process.go +++ b/internal/guest/runtime/hcsv2/process.go @@ -286,7 +286,7 @@ func (ep *externalProcess) ResizeConsole(_ context.Context, height, width uint16 } func (ep *externalProcess) Wait() (<-chan int, chan<- bool) { - otelutil.StartSpan(context.Background(), "opengcs::externalProcess::Wait", trace.WithAttributes( + _, span := otelutil.StartSpan(context.Background(), "opengcs::externalProcess::Wait", trace.WithAttributes( attribute.Int64("pid", int64(ep.cmd.Process.Pid)))) exitCodeChan := make(chan int, 1) @@ -305,8 +305,10 @@ func (ep *externalProcess) Wait() (<-chan int, chan<- bool) { ep.removeOnce.Do(func() { ep.remove(ep.cmd.Process.Pid) }) + span.End() case <-doneChan: // Caller closed early, do nothing. + span.End() } }() return exitCodeChan, doneChan