From 4b9fb4fbcf15b7b0d6fde4f0bc84957a01ecc9eb Mon Sep 17 00:00:00 2001 From: laojianzi Date: Fri, 3 Sep 2021 10:19:18 +0800 Subject: [PATCH 1/7] fix: utils.NewConfig returns a file not found error in windows os --- .github/workflows/ci.yml | 4 +--- exporters/metric/cortex/utils/config_utils_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52033131ebf..2967dc2afec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,9 +108,7 @@ jobs: strategy: matrix: go-version: [1.16, 1.15] - # TODO: support all of these. - #os: [ubuntu-latest, macos-latest, windows-latest] - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] # GitHub Actions does not support arm* architectures on default # runners. It is possible to acomplish this with a self-hosted runner # if we want to add this in the future: diff --git a/exporters/metric/cortex/utils/config_utils_test.go b/exporters/metric/cortex/utils/config_utils_test.go index da89a2e7665..7b288708519 100644 --- a/exporters/metric/cortex/utils/config_utils_test.go +++ b/exporters/metric/cortex/utils/config_utils_test.go @@ -32,6 +32,17 @@ func initYAML(yamlBytes []byte, path string) (afero.Fs, error) { // Create an in-memory file system. fs := afero.NewMemMapFs() + // https://github.com/spf13/viper/blob/v1.8.1/viper.go#L480 + // absPathify uses filepath.Clean, so here you also need to use filepath.Clean + if filepath.IsAbs(path) { + path = filepath.Clean(path) + } else { + p, err := filepath.Abs(path) + if err == nil { + path = filepath.Clean(p) + } + } + // Retrieve the directory path. dirPath := filepath.Dir(path) From bac423173d0fd293bea78378d8a1e0ea8af3460f Mon Sep 17 00:00:00 2001 From: laojianzi Date: Sun, 5 Sep 2021 14:35:56 +0800 Subject: [PATCH 2/7] Fix: set `service.name` so that `Output` does not fail due to system environment --- exporters/metric/datadog/example_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exporters/metric/datadog/example_test.go b/exporters/metric/datadog/example_test.go index 2b741f2cacd..9e80c26f9f0 100644 --- a/exporters/metric/datadog/example_test.go +++ b/exporters/metric/datadog/example_test.go @@ -31,6 +31,7 @@ import ( controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" "go.opentelemetry.io/otel/sdk/metric/processor/basic" "go.opentelemetry.io/otel/sdk/metric/selector/simple" + semconv "go.opentelemetry.io/otel/semconv/v1.4.0" ) type TestUDPServer struct { @@ -67,7 +68,7 @@ func ExampleExporter() { global.SetMeterProvider(pusher.MeterProvider()) meter := global.Meter("marwandist") m := metric.Must(meter).NewInt64Histogram("myrecorder") - meter.RecordBatch(context.Background(), []attribute.KeyValue{attribute.Int("l", 1)}, + meter.RecordBatch(context.Background(), []attribute.KeyValue{attribute.Int("l", 1), semconv.ServiceNameKey.String("ExampleExporter")}, m.Measurement(1), m.Measurement(50), m.Measurement(100)) }() @@ -98,7 +99,7 @@ func ExampleExporter() { } // Output: - // myrecorder.max:100|g|#env:dev,l:1,service.name:unknown_service:datadog.test,telemetry.sdk.language:go,telemetry.sdk.name:opentelemetry,telemetry.sdk.version:1.0.0-RC3 + // myrecorder.max:100|g|#env:dev,l:1,service.name:ExampleExporter,telemetry.sdk.language:go,telemetry.sdk.name:opentelemetry,telemetry.sdk.version:1.0.0-RC3 // } From 5fbe2c8d0b5a431582d59ae7d48ce7d9a380d03a Mon Sep 17 00:00:00 2001 From: laojianzi Date: Tue, 14 Sep 2021 21:00:57 +0800 Subject: [PATCH 3/7] fix: golang.org/x/sys version mismatch --- instrumentation/host/example/go.sum | 2 +- instrumentation/host/go.mod | 2 +- instrumentation/host/go.sum | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/instrumentation/host/example/go.sum b/instrumentation/host/example/go.sum index 2a9bd9838ab..4915241c2bc 100644 --- a/instrumentation/host/example/go.sum +++ b/instrumentation/host/example/go.sum @@ -31,7 +31,7 @@ go.opentelemetry.io/otel/sdk/metric v0.23.0 h1:xlZhPbiue1+jjSFEth94q9QCmX8Q24mOt go.opentelemetry.io/otel/sdk/metric v0.23.0/go.mod h1:wa0sKK13eeIFW+0OFjcC3S1i7FTRRiLAXe1kjBVbhwg= go.opentelemetry.io/otel/trace v1.0.0-RC3 h1:9F0ayEvlxv8BmNmPbU005WK7hC+7KbOazCPZjNa1yME= go.opentelemetry.io/otel/trace v1.0.0-RC3/go.mod h1:VUt2TUYd8S2/ZRX09ZDFZQwn2RqfMB5MzO17jBojGxo= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/instrumentation/host/go.mod b/instrumentation/host/go.mod index 239ce59bb8a..0e9fe3ed8ca 100644 --- a/instrumentation/host/go.mod +++ b/instrumentation/host/go.mod @@ -12,5 +12,5 @@ require ( go.opentelemetry.io/contrib v0.23.0 go.opentelemetry.io/otel v1.0.0-RC3 go.opentelemetry.io/otel/metric v0.23.0 - golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a // indirect + golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 // indirect ) diff --git a/instrumentation/host/go.sum b/instrumentation/host/go.sum index e31ff9b4ab3..79f580f96b9 100644 --- a/instrumentation/host/go.sum +++ b/instrumentation/host/go.sum @@ -21,8 +21,8 @@ go.opentelemetry.io/otel/metric v0.23.0 h1:mYCcDxi60P4T27/0jchIDFa1WHEfQeU3zH9UE go.opentelemetry.io/otel/metric v0.23.0/go.mod h1:G/Nn9InyNnIv7J6YVkQfpc0JCfKBNJaERBGw08nqmVQ= go.opentelemetry.io/otel/trace v1.0.0-RC3 h1:9F0ayEvlxv8BmNmPbU005WK7hC+7KbOazCPZjNa1yME= go.opentelemetry.io/otel/trace v1.0.0-RC3/go.mod h1:VUt2TUYd8S2/ZRX09ZDFZQwn2RqfMB5MzO17jBojGxo= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= From 072939cc77ac49c2b2bf5678edc98f5c01e3349e Mon Sep 17 00:00:00 2001 From: laojianzi Date: Tue, 14 Sep 2021 21:03:11 +0800 Subject: [PATCH 4/7] chore: use `WithResource` in the `ExampleExporter` to change `service.name` --- exporters/metric/datadog/example_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exporters/metric/datadog/example_test.go b/exporters/metric/datadog/example_test.go index 9e80c26f9f0..c97430cf8c6 100644 --- a/exporters/metric/datadog/example_test.go +++ b/exporters/metric/datadog/example_test.go @@ -31,6 +31,7 @@ import ( controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" "go.opentelemetry.io/otel/sdk/metric/processor/basic" "go.opentelemetry.io/otel/sdk/metric/selector/simple" + "go.opentelemetry.io/otel/sdk/resource" semconv "go.opentelemetry.io/otel/semconv/v1.4.0" ) @@ -58,17 +59,20 @@ func ExampleExporter() { go func() { defer exp.Close() processor := basic.New(selector, exp) - pusher := controller.New(processor, controller.WithExporter(exp), controller.WithCollectPeriod(time.Second*10)) + pusher := controller.New(processor, controller.WithExporter(exp), controller.WithCollectPeriod(time.Second*10), + controller.WithResource(resource.Default()), + controller.WithResource(resource.NewSchemaless(semconv.ServiceNameKey.String("ExampleExporter")))) ctx := context.Background() err := pusher.Start(ctx) if err != nil { panic(err) } + defer func() { handleErr(pusher.Stop(ctx)) }() global.SetMeterProvider(pusher.MeterProvider()) meter := global.Meter("marwandist") m := metric.Must(meter).NewInt64Histogram("myrecorder") - meter.RecordBatch(context.Background(), []attribute.KeyValue{attribute.Int("l", 1), semconv.ServiceNameKey.String("ExampleExporter")}, + meter.RecordBatch(context.Background(), []attribute.KeyValue{attribute.Int("l", 1)}, m.Measurement(1), m.Measurement(50), m.Measurement(100)) }() From 3c59acfd25919a914bb4be26ebaf992d536174ff Mon Sep 17 00:00:00 2001 From: laojianzi Date: Wed, 15 Sep 2021 11:33:04 +0800 Subject: [PATCH 5/7] fix: `TestTransportErrorStatus` connection refused assert on Windows machines --- .../net/http/otelhttp/test/transport_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/instrumentation/net/http/otelhttp/test/transport_test.go b/instrumentation/net/http/otelhttp/test/transport_test.go index 000e6c76383..78769572364 100644 --- a/instrumentation/net/http/otelhttp/test/transport_test.go +++ b/instrumentation/net/http/otelhttp/test/transport_test.go @@ -17,6 +17,7 @@ package test import ( "net/http" "net/http/httptest" + "runtime" "strings" "testing" @@ -112,7 +113,15 @@ func TestTransportErrorStatus(t *testing.T) { t.Errorf("expected error status code on span; got: %q", got) } - if got := span.Status().Description; !strings.Contains(got, "connect: connection refused") { + errSubstr := "connect: connection refused" + if runtime.GOOS == "windows" { + // tls.Dial returns an error that does not contain the substring "connection refused" + // on Windows machines + // + // ref: "dial tcp 127.0.0.1:50115: connectex: No connection could be made because the target machine actively refused it." + errSubstr = "No connection could be made because the target machine actively refused it" + } + if got := span.Status().Description; !strings.Contains(got, errSubstr) { t.Errorf("expected error status message on span; got: %q", got) } } From f7764b4aa5914dfff779259eee18e2b96e5d3d0c Mon Sep 17 00:00:00 2001 From: laojianzi Date: Fri, 24 Sep 2021 20:53:39 +0800 Subject: [PATCH 6/7] test: TestHostNetwork Wait for results until go test times out --- instrumentation/host/host_test.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/instrumentation/host/host_test.go b/instrumentation/host/host_test.go index 72b0aa5edfb..08b792ac1d3 100644 --- a/instrumentation/host/host_test.go +++ b/instrumentation/host/host_test.go @@ -28,9 +28,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/contrib/instrumentation/host" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric/metrictest" + + "go.opentelemetry.io/contrib/instrumentation/host" ) func getMetric(impl *metrictest.MeterImpl, name string, lbl attribute.KeyValue) float64 { @@ -220,20 +221,18 @@ func TestHostNetwork(t *testing.T) { require.NoError(t, err) // As we are going to read the /proc file system for this info, sleep a while: - time.Sleep(time.Second) - - impl.RunAsyncInstruments() + require.Eventually(t, func() bool { + hostAfter, err := net.IOCountersWithContext(ctx, false) + require.NoError(t, err) - hostAfter, err := net.IOCountersWithContext(ctx, false) - require.NoError(t, err) + return uint64(howMuch) <= hostAfter[0].BytesSent-hostBefore[0].BytesSent && + uint64(howMuch) <= hostAfter[0].BytesRecv-hostBefore[0].BytesRecv + }, 30*time.Second, time.Second/2) + impl.RunAsyncInstruments() hostTransmit := getMetric(impl, "system.network.io", host.AttributeNetworkTransmit[0]) hostReceive := getMetric(impl, "system.network.io", host.AttributeNetworkReceive[0]) - // Check that the network transmit/receive used is greater than before: - require.LessOrEqual(t, uint64(howMuch), hostAfter[0].BytesSent-hostBefore[0].BytesSent) - require.LessOrEqual(t, uint64(howMuch), hostAfter[0].BytesRecv-hostBefore[0].BytesRecv) - // Check that the recorded measurements reflect the same change: require.LessOrEqual(t, uint64(howMuch), uint64(hostTransmit)-hostBefore[0].BytesSent) require.LessOrEqual(t, uint64(howMuch), uint64(hostReceive)-hostBefore[0].BytesRecv) From ca6b0a36235af7bce418dc13a46fa398bf64d86f Mon Sep 17 00:00:00 2001 From: laojianzi Date: Thu, 2 Dec 2021 23:00:35 +0800 Subject: [PATCH 7/7] fix: windows net listen failed --- .../otellambda/xrayconfig/xrayconfig_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go b/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go index a0a3ea74c77..b0dae0aa977 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go @@ -18,6 +18,7 @@ import ( "context" "os" "reflect" + "runtime" "testing" "time" @@ -67,6 +68,12 @@ func setEnvVars() { _ = os.Setenv("AWS_REGION", "us-texas-1") _ = os.Setenv("AWS_LAMBDA_FUNCTION_VERSION", "$LATEST") _ = os.Setenv("_X_AMZN_TRACE_ID", "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1") + + // fix issue: "The requested service provider could not be loaded or initialized." + // Guess: The env for Windows in GitHub action is incomplete + if runtime.GOOS == "windows" && os.Getenv("SYSTEMROOT") == "" { + _ = os.Setenv("SYSTEMROOT", `C:\Windows`) + } } // Vars for end to end testing @@ -161,7 +168,7 @@ func TestWrapEndToEnd(t *testing.T) { customerHandler := func() (string, error) { return "hello world", nil } - mockCollector := runMockCollectorAtEndpoint(t, "localhost:4317") + mockCollector := runMockCollectorAtEndpoint(t, ":4317") defer func() { _ = mockCollector.Stop() }()