From 5476951d36f08da48cbcd8e50070ed72ca95cb21 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Wed, 13 Mar 2024 09:52:52 -0400 Subject: [PATCH] Create client on Start instead of Creation (#817) * move client creation to Start --- Makefile | 1 + exporter/collector/go.mod | 24 +++++- exporter/collector/go.sum | 48 +++++++++-- exporter/collector/integrationtest/go.mod | 2 +- exporter/collector/integrationtest/go.sum | 4 +- .../integrationtest/inmemoryocexporter.go | 8 ++ .../integrationtest/logs_integration_test.go | 5 +- .../metrics_integration_test.go | 3 + .../traces_integration_test.go | 3 + exporter/collector/logs.go | 48 +++++++---- exporter/collector/metrics.go | 83 ++++++++++--------- exporter/collector/metrics_test.go | 1 + exporter/collector/traces.go | 35 +++++--- exporter/collector/traces_test.go | 3 + 14 files changed, 189 insertions(+), 79 deletions(-) diff --git a/Makefile b/Makefile index 0c9885ff2..5ef85d7c9 100644 --- a/Makefile +++ b/Makefile @@ -217,6 +217,7 @@ update-otel: $(MAKE) update-dep MODULE=go.opentelemetry.io/contrib/detectors/gcp VERSION=$(STABLE_CONTRIB_OTEL_VERSION) $(MAKE) update-dep MODULE=go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp VERSION=$(UNSTABLE_CONTRIB_OTEL_VERSION) $(MAKE) update-dep MODULE=go.opentelemetry.io/collector VERSION=$(UNSTABLE_COLLECTOR_VERSION) + $(MAKE) update-dep MODULE=go.opentelemetry.io/collector/component VERSION=$(UNSTABLE_COLLECTOR_VERSION) $(MAKE) update-dep MODULE=go.opentelemetry.io/collector/semconv VERSION=$(UNSTABLE_COLLECTOR_VERSION) $(MAKE) update-dep MODULE=go.opentelemetry.io/collector/otelcol VERSION=$(UNSTABLE_COLLECTOR_VERSION) $(MAKE) update-dep MODULE=go.opentelemetry.io/collector/extension/auth VERSION=$(UNSTABLE_COLLECTOR_VERSION) diff --git a/exporter/collector/go.mod b/exporter/collector/go.mod index 320a7df03..b998ca74c 100644 --- a/exporter/collector/go.mod +++ b/exporter/collector/go.mod @@ -15,6 +15,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tidwall/wal v1.1.7 go.opencensus.io v0.24.0 + go.opentelemetry.io/collector/component v0.94.0 go.opentelemetry.io/collector/pdata v1.1.0 go.opentelemetry.io/collector/semconv v0.94.0 go.opentelemetry.io/otel v1.23.1 @@ -22,7 +23,7 @@ require ( go.opentelemetry.io/otel/trace v1.23.1 go.uber.org/atomic v1.10.0 go.uber.org/zap v1.26.0 - golang.org/x/oauth2 v0.14.0 + golang.org/x/oauth2 v0.16.0 google.golang.org/api v0.149.0 google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 @@ -35,26 +36,43 @@ require ( cloud.google.com/go/compute v1.23.3 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/longrunning v0.5.4 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // 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.3 // indirect github.com/google/s2a-go v0.1.7 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/knadh/koanf/maps v0.1.1 // indirect + github.com/knadh/koanf/providers/confmap v0.1.0 // indirect + github.com/knadh/koanf/v2 v2.0.2 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_golang v1.18.0 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.46.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/tidwall/gjson v1.10.2 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect github.com/tidwall/tinylru v1.1.0 // indirect + go.opentelemetry.io/collector/config/configtelemetry v0.94.0 // indirect + go.opentelemetry.io/collector/confmap v0.94.0 // indirect + go.opentelemetry.io/otel/exporters/prometheus v0.45.1 // indirect go.opentelemetry.io/otel/metric v1.23.1 // indirect + go.opentelemetry.io/otel/sdk/metric v1.23.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/net v0.18.0 // indirect + golang.org/x/crypto v0.18.0 // indirect + golang.org/x/net v0.20.0 // indirect golang.org/x/sync v0.5.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/exporter/collector/go.sum b/exporter/collector/go.sum index e631b5e5a..51d55da58 100644 --- a/exporter/collector/go.sum +++ b/exporter/collector/go.sum @@ -15,9 +15,13 @@ cloud.google.com/go/monitoring v1.16.3/go.mod h1:KwSsX5+8PnXv5NJnICZzW2R8pWTis8y cloud.google.com/go/trace v1.10.4 h1:2qOAuAzNezwW3QN+t41BtkDJOG42HywL73q8x/f6fnM= cloud.google.com/go/trace v1.10.4/go.mod h1:Nso99EDIK8Mj5/zmB+iGr9dosS/bzWCJ8wGmE6TXNWY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= +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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -34,6 +38,8 @@ github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c= +github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= 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= @@ -76,8 +82,20 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs= +github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI= +github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU= +github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU= +github.com/knadh/koanf/v2 v2.0.2 h1:sEZzPW2rVWSahcYILNq/syJdEyRafZIG0l9aWwL86HA= +github.com/knadh/koanf/v2 v2.0.2/go.mod h1:HN9uZ+qFAejH1e4G41gnoffIanINWQuONLXiV7kir6k= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c h1:cqn374mizHuIWj+OSJCajGr/phAmuMug9qIX3l9CflE= +github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -85,7 +103,15 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +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.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqScV0Y= +github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= @@ -111,16 +137,26 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= +go.opentelemetry.io/collector/component v0.94.0 h1:8sdxk0D0XNhm0Mtz8+Wv9GKrjKDAURBpsfRzHKeEufU= +go.opentelemetry.io/collector/component v0.94.0/go.mod h1:T+sQFhMJuy0Cr0f/EWeQxheTkccM+DaZH88scdh0c1o= +go.opentelemetry.io/collector/config/configtelemetry v0.94.0 h1:snznflNDx8RhhDtl7iXQJZ+GfhhHStCm7nxo6Yti7wQ= +go.opentelemetry.io/collector/config/configtelemetry v0.94.0/go.mod h1:2XLhyR/GVpWeZ2K044vCmrvH/d4Ewt0aD/y46avZyMU= +go.opentelemetry.io/collector/confmap v0.94.0 h1:yjzdGPHCeae7VooJkgeOWO2Y3XFKwOI19ejhBYx8CCM= +go.opentelemetry.io/collector/confmap v0.94.0/go.mod h1:pCT5UtcHaHVJ5BIILv1Z2VQyjZzmT9uTdBmC9+Z0AgA= go.opentelemetry.io/collector/pdata v1.1.0 h1:cE6Al1rQieUjMHro6p6cKwcu3sjHXGG59BZ3kRVUvsM= go.opentelemetry.io/collector/pdata v1.1.0/go.mod h1:IDkDj+B4Fp4wWOclBELN97zcb98HugJ8Q2gA4ZFsN8Q= go.opentelemetry.io/collector/semconv v0.94.0 h1:54qLYBnztS/ysJYqDkisRBpd72rQ7mJxViPagDE58ag= go.opentelemetry.io/collector/semconv v0.94.0/go.mod h1:gZ0uzkXsN+J5NpiRcdp9xOhNGQDDui8Y62p15sKrlzo= go.opentelemetry.io/otel v1.23.1 h1:Za4UzOqJYS+MUczKI320AtqZHZb7EqxO00jAHE0jmQY= go.opentelemetry.io/otel v1.23.1/go.mod h1:Td0134eafDLcTS4y+zQ26GE8u3dEuRBiBCTUIRHaikA= +go.opentelemetry.io/otel/exporters/prometheus v0.45.1 h1:R/bW3afad6q6VGU+MFYpnEdo0stEARMCdhWu6+JI6aI= +go.opentelemetry.io/otel/exporters/prometheus v0.45.1/go.mod h1:wnHAfKRav5Dfp4iZhyWZ7SzQfT+rDZpEpYG7To+qJ1k= go.opentelemetry.io/otel/metric v1.23.1 h1:PQJmqJ9u2QaJLBOELl1cxIdPcpbwzbkjfEyelTl2rlo= go.opentelemetry.io/otel/metric v1.23.1/go.mod h1:mpG2QPlAfnK8yNhNJAxDZruU9Y1/HubbC+KyH8FaCWI= go.opentelemetry.io/otel/sdk v1.23.1 h1:O7JmZw0h76if63LQdsBMKQDWNb5oEcOThG9IrxscV+E= go.opentelemetry.io/otel/sdk v1.23.1/go.mod h1:LzdEVR5am1uKOOwfBWFef2DCi1nu3SA8XQxx2IerWFk= +go.opentelemetry.io/otel/sdk/metric v1.23.0 h1:u81lMvmK6GMgN4Fty7K7S6cSKOZhMKJMK2TB+KaTs0I= +go.opentelemetry.io/otel/sdk/metric v1.23.0/go.mod h1:2LUOToN/FdX6wtfpHybOnCZjoZ6ViYajJYMiJ1LKDtQ= go.opentelemetry.io/otel/trace v1.23.1 h1:4LrmmEd8AU2rFvU1zegmvqW7+kWarxtNOPyeL6HmYY8= go.opentelemetry.io/otel/trace v1.23.1/go.mod h1:4IpnpJFwr1mo/6HL8XIPJaE9y0+u1KcVmuW7dwFSVrI= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= @@ -134,8 +170,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -154,11 +190,11 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY 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.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= -golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= -golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= +golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= +golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= 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= diff --git a/exporter/collector/integrationtest/go.mod b/exporter/collector/integrationtest/go.mod index bc634ac2a..7239fd3bd 100644 --- a/exporter/collector/integrationtest/go.mod +++ b/exporter/collector/integrationtest/go.mod @@ -61,7 +61,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/knadh/koanf/maps v0.1.1 // indirect github.com/knadh/koanf/providers/confmap v0.1.0 // indirect - github.com/knadh/koanf/v2 v2.0.2 // indirect + github.com/knadh/koanf/v2 v2.1.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect diff --git a/exporter/collector/integrationtest/go.sum b/exporter/collector/integrationtest/go.sum index 98de1ead4..798f40357 100644 --- a/exporter/collector/integrationtest/go.sum +++ b/exporter/collector/integrationtest/go.sum @@ -107,8 +107,8 @@ github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NI github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI= github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU= github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU= -github.com/knadh/koanf/v2 v2.0.2 h1:sEZzPW2rVWSahcYILNq/syJdEyRafZIG0l9aWwL86HA= -github.com/knadh/koanf/v2 v2.0.2/go.mod h1:HN9uZ+qFAejH1e4G41gnoffIanINWQuONLXiV7kir6k= +github.com/knadh/koanf/v2 v2.1.0 h1:eh4QmHHBuU8BybfIJ8mB8K8gsGCD/AUQTdwGq/GzId8= +github.com/knadh/koanf/v2 v2.1.0/go.mod h1:4mnTRbZCK+ALuBXHZMjDfG9y714L7TykVnZkXbMU3Es= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= diff --git a/exporter/collector/integrationtest/inmemoryocexporter.go b/exporter/collector/integrationtest/inmemoryocexporter.go index a46d85e65..ee2a71e8c 100644 --- a/exporter/collector/integrationtest/inmemoryocexporter.go +++ b/exporter/collector/integrationtest/inmemoryocexporter.go @@ -24,6 +24,7 @@ import ( "go.opencensus.io/metric/metricexport" "go.opencensus.io/plugin/ocgrpc" "go.opencensus.io/stats/view" + "go.opentelemetry.io/collector/component/componenttest" "go.uber.org/zap" "google.golang.org/api/option" "google.golang.org/grpc" @@ -143,6 +144,8 @@ func NewTraceTestExporter( collector.DefaultTimeout, ) require.NoError(t, err) + err = exporter.Start(ctx, componenttest.NewNopHost()) + require.NoError(t, err) t.Logf("Collector TracesTestServer exporter started, pointing at %v", cfg.TraceConfig.ClientConfig.Endpoint) return exporter } @@ -166,6 +169,8 @@ func NewMetricTestExporter( collector.DefaultTimeout, ) require.NoError(t, err) + err = exporter.Start(ctx, componenttest.NewNopHost()) + require.NoError(t, err) t.Logf("Collector MetricsTestServer exporter started, pointing at %v", cfg.MetricConfig.ClientConfig.Endpoint) return exporter } @@ -192,6 +197,9 @@ func NewLogTestExporter( ) require.NoError(t, err) + err = exporter.Start(ctx, componenttest.NewNopHost()) + require.NoError(t, err) + exporter.ConfigureExporter(extraConfig) t.Logf("Collector LogsTestServer exporter started, pointing at %v", cfg.LogConfig.ClientConfig.Endpoint) return exporter diff --git a/exporter/collector/integrationtest/logs_integration_test.go b/exporter/collector/integrationtest/logs_integration_test.go index eeddd213d..179d5490e 100644 --- a/exporter/collector/integrationtest/logs_integration_test.go +++ b/exporter/collector/integrationtest/logs_integration_test.go @@ -26,6 +26,7 @@ import ( "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/integrationtest/testcases" "github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/plog" "go.uber.org/zap" @@ -47,8 +48,10 @@ func createLogsExporter( logger, "latest", ) - exporter.ConfigureExporter(test.ConfigureLogsExporter) require.NoError(t, err) + err = exporter.Start(ctx, componenttest.NewNopHost()) + require.NoError(t, err) + exporter.ConfigureExporter(test.ConfigureLogsExporter) t.Log("Collector logs exporter started") return exporter } diff --git a/exporter/collector/integrationtest/metrics_integration_test.go b/exporter/collector/integrationtest/metrics_integration_test.go index dfc7bc69e..413d5e2dc 100644 --- a/exporter/collector/integrationtest/metrics_integration_test.go +++ b/exporter/collector/integrationtest/metrics_integration_test.go @@ -26,6 +26,7 @@ import ( "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/integrationtest/testcases" "github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" @@ -50,6 +51,8 @@ func createMetricsExporter( collector.DefaultTimeout, ) require.NoError(t, err) + err = exporter.Start(ctx, componenttest.NewNopHost()) + require.NoError(t, err) t.Log("Collector metrics exporter started") return exporter } diff --git a/exporter/collector/integrationtest/traces_integration_test.go b/exporter/collector/integrationtest/traces_integration_test.go index bab28fda1..368da0839 100644 --- a/exporter/collector/integrationtest/traces_integration_test.go +++ b/exporter/collector/integrationtest/traces_integration_test.go @@ -26,6 +26,7 @@ import ( "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector" "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/integrationtest/testcases" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" ) func createTracesExporter( @@ -42,6 +43,8 @@ func createTracesExporter( collector.DefaultTimeout, ) require.NoError(t, err) + err = exporter.Start(ctx, componenttest.NewNopHost()) + require.NoError(t, err) t.Log("Collector traces exporter started") return exporter } diff --git a/exporter/collector/logs.go b/exporter/collector/logs.go index 959143d1c..d0982c873 100644 --- a/exporter/collector/logs.go +++ b/exporter/collector/logs.go @@ -41,6 +41,7 @@ import ( "google.golang.org/protobuf/types/known/structpb" "google.golang.org/protobuf/types/known/timestamppb" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/plog" @@ -162,21 +163,6 @@ func NewGoogleCloudLogsExporter( version string, ) (*LogsExporter, error) { setVersionInUserAgent(&cfg, version) - clientOpts, err := generateClientOptions(ctx, &cfg.LogConfig.ClientConfig, &cfg, loggingv2.DefaultAuthScopes()) - if err != nil { - return nil, err - } - - loggingClient, err := loggingv2.NewClient(ctx, clientOpts...) - if err != nil { - return nil, err - } - - if cfg.LogConfig.ClientConfig.Compression == gzip.Name { - loggingClient.CallOptions.WriteLogEntries = append(loggingClient.CallOptions.WriteLogEntries, - gax.WithGRPCOptions(grpc.UseCompressor(gzip.Name))) - } - obs := selfObservability{ log: log, } @@ -190,8 +176,6 @@ func NewGoogleCloudLogsExporter( maxEntrySize: defaultMaxEntrySize, maxRequestSize: defaultMaxRequestSize, }, - - loggingClient: loggingClient, }, nil } @@ -208,11 +192,39 @@ func (l *LogsExporter) ConfigureExporter(config *logsutil.ExporterConfig) { } } +func (l *LogsExporter) Start(ctx context.Context, _ component.Host) error { + clientOpts, err := generateClientOptions(ctx, &l.cfg.LogConfig.ClientConfig, &l.cfg, loggingv2.DefaultAuthScopes()) + if err != nil { + return err + } + + loggingClient, err := loggingv2.NewClient(ctx, clientOpts...) + if err != nil { + return err + } + + if l.cfg.LogConfig.ClientConfig.Compression == gzip.Name { + loggingClient.CallOptions.WriteLogEntries = append(loggingClient.CallOptions.WriteLogEntries, + gax.WithGRPCOptions(grpc.UseCompressor(gzip.Name))) + } + l.loggingClient = loggingClient + // We might have modified the config when we generated options above. + // Make sure changes to the config are synced to the mapper. + l.mapper.cfg = l.cfg + return nil +} + func (l *LogsExporter) Shutdown(ctx context.Context) error { - return l.loggingClient.Close() + if l.loggingClient != nil { + return l.loggingClient.Close() + } + return nil } func (l *LogsExporter) PushLogs(ctx context.Context, ld plog.Logs) error { + if l.loggingClient == nil { + return errors.New("not started") + } projectEntries, err := l.mapper.createEntries(ld) if err != nil { return err diff --git a/exporter/collector/metrics.go b/exporter/collector/metrics.go index 4dd816ad4..bede6813a 100644 --- a/exporter/collector/metrics.go +++ b/exporter/collector/metrics.go @@ -51,6 +51,7 @@ import ( "go.opencensus.io/plugin/ocgrpc" "go.opencensus.io/stats/view" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" @@ -161,7 +162,10 @@ func (me *MetricsExporter) Shutdown(ctx context.Context) error { me.obs.log.Error("Error waiting for async tasks to finish.", zap.Error(ctx.Err())) case <-c: } - return me.client.Close() + if me.client != nil { + return me.client.Close() + } + return nil } func NewGoogleCloudMetricsExporter( @@ -178,35 +182,11 @@ func NewGoogleCloudMetricsExporter( view.Register(ocgrpc.DefaultClientViews...) setVersionInUserAgent(&cfg, version) - clientOpts, err := generateClientOptions(ctx, &cfg.MetricConfig.ClientConfig, &cfg, monitoring.DefaultAuthScopes()) - if err != nil { - return nil, err - } - - client, err := monitoring.NewMetricClient(ctx, clientOpts...) - if err != nil { - return nil, err - } - - if cfg.MetricConfig.ClientConfig.Compression == gzip.Name { - client.CallOptions.CreateMetricDescriptor = append(client.CallOptions.CreateMetricDescriptor, - gax.WithGRPCOptions(grpc.UseCompressor(gzip.Name))) - client.CallOptions.CreateTimeSeries = append(client.CallOptions.CreateTimeSeries, - gax.WithGRPCOptions(grpc.UseCompressor(gzip.Name))) - client.CallOptions.CreateServiceTimeSeries = append(client.CallOptions.CreateServiceTimeSeries, - gax.WithGRPCOptions(grpc.UseCompressor(gzip.Name))) - } - obs := selfObservability{log: log} - shutdown := make(chan struct{}) normalizer := normalization.NewDisabledNormalizer() - if cfg.MetricConfig.CumulativeNormalization { - normalizer = normalization.NewStandardNormalizer(shutdown, log) - } mExp := &MetricsExporter{ - cfg: cfg, - client: client, - obs: obs, + cfg: cfg, + obs: obs, mapper: metricMapper{ obs: obs, cfg: cfg, @@ -218,7 +198,7 @@ func NewGoogleCloudMetricsExporter( // to drop / conserve resources for sending timeseries. metricDescriptorC: make(chan *monitoringpb.CreateMetricDescriptorRequest, cfg.MetricConfig.CreateMetricDescriptorBufferSize), mdCache: make(map[string]*monitoringpb.CreateMetricDescriptorRequest), - shutdownC: shutdown, + shutdownC: make(chan struct{}), timeout: timeout, } mExp.exportFunc = mExp.exportToTimeSeries @@ -230,21 +210,47 @@ func NewGoogleCloudMetricsExporter( }) } - if cfg.MetricConfig.WALConfig != nil { - _, _, err = mExp.setupWAL() + return mExp, nil +} + +func (me *MetricsExporter) Start(ctx context.Context, _ component.Host) error { + me.shutdownC = make(chan struct{}) + if me.cfg.MetricConfig.CumulativeNormalization { + me.mapper.normalizer = normalization.NewStandardNormalizer(me.shutdownC, me.obs.log) + } + clientOpts, err := generateClientOptions(ctx, &me.cfg.MetricConfig.ClientConfig, &me.cfg, monitoring.DefaultAuthScopes()) + if err != nil { + return err + } + + client, err := monitoring.NewMetricClient(ctx, clientOpts...) + if err != nil { + return err + } + + if me.cfg.MetricConfig.ClientConfig.Compression == gzip.Name { + client.CallOptions.CreateMetricDescriptor = append(client.CallOptions.CreateMetricDescriptor, + gax.WithGRPCOptions(grpc.UseCompressor(gzip.Name))) + client.CallOptions.CreateTimeSeries = append(client.CallOptions.CreateTimeSeries, + gax.WithGRPCOptions(grpc.UseCompressor(gzip.Name))) + client.CallOptions.CreateServiceTimeSeries = append(client.CallOptions.CreateServiceTimeSeries, + gax.WithGRPCOptions(grpc.UseCompressor(gzip.Name))) + } + me.client = client + if me.cfg.MetricConfig.WALConfig != nil { + _, _, err = me.setupWAL() if err != nil { - return nil, err + return err } // start WAL popper routine - mExp.goroutines.Add(1) - go mExp.runWALReadAndExportLoop(ctx) + me.goroutines.Add(1) + go me.runWALReadAndExportLoop(ctx) } // Fire up the metric descriptor exporter. - mExp.goroutines.Add(1) - go mExp.exportMetricDescriptorRunner() - - return mExp, nil + me.goroutines.Add(1) + go me.exportMetricDescriptorRunner() + return nil } // setupWAL creates the WAL. @@ -299,6 +305,9 @@ func (me *MetricsExporter) closeWAL() error { // PushMetrics calls pushes pdata metrics to GCM, creating metric descriptors if necessary. func (me *MetricsExporter) PushMetrics(ctx context.Context, m pmetric.Metrics) error { + if me.client == nil { + return errors.New("not started") + } if me.wal != nil { me.wal.mutex.Lock() defer me.wal.mutex.Unlock() diff --git a/exporter/collector/metrics_test.go b/exporter/collector/metrics_test.go index 24d6b784a..5f58697e8 100644 --- a/exporter/collector/metrics_test.go +++ b/exporter/collector/metrics_test.go @@ -2573,6 +2573,7 @@ func TestPushMetricsOntoWAL(t *testing.T) { obs: obs, shutdownC: shutdown, cfg: cfg, + client: &mock{}, mapper: metricMapper{ obs: obs, cfg: cfg, diff --git a/exporter/collector/traces.go b/exporter/collector/traces.go index 530ed14b4..938d177ef 100644 --- a/exporter/collector/traces.go +++ b/exporter/collector/traces.go @@ -18,12 +18,14 @@ package collector import ( "context" + "errors" "fmt" "time" traceapi "cloud.google.com/go/trace/apiv2" "go.opencensus.io/plugin/ocgrpc" "go.opencensus.io/stats/view" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/otel/attribute" sdktrace "go.opentelemetry.io/otel/sdk/trace" @@ -34,10 +36,15 @@ import ( // TraceExporter is a wrapper struct of OT cloud trace exporter. type TraceExporter struct { texporter *texporter.Exporter + cfg Config + timeout time.Duration } func (te *TraceExporter) Shutdown(ctx context.Context) error { - return te.texporter.Shutdown(ctx) + if te.texporter != nil { + return te.texporter.Shutdown(ctx) + } + return nil } func NewGoogleCloudTracesExporter(ctx context.Context, cfg Config, version string, timeout time.Duration) (*TraceExporter, error) { @@ -45,32 +52,35 @@ func NewGoogleCloudTracesExporter(ctx context.Context, cfg Config, version strin //nolint:errcheck view.Register(ocgrpc.DefaultClientViews...) setVersionInUserAgent(&cfg, version) + return &TraceExporter{cfg: cfg, timeout: timeout}, nil +} +func (te *TraceExporter) Start(ctx context.Context, _ component.Host) error { topts := []texporter.Option{ - texporter.WithProjectID(cfg.ProjectID), - texporter.WithTimeout(timeout), + texporter.WithProjectID(te.cfg.ProjectID), + texporter.WithTimeout(te.timeout), } - if cfg.DestinationProjectQuota { + if te.cfg.DestinationProjectQuota { topts = append(topts, texporter.WithDestinationProjectQuota()) } - if cfg.TraceConfig.AttributeMappings != nil { - topts = append(topts, texporter.WithAttributeMapping(mappingFuncFromAKM(cfg.TraceConfig.AttributeMappings))) + if te.cfg.TraceConfig.AttributeMappings != nil { + topts = append(topts, texporter.WithAttributeMapping(mappingFuncFromAKM(te.cfg.TraceConfig.AttributeMappings))) } - copts, err := generateClientOptions(ctx, &cfg.TraceConfig.ClientConfig, &cfg, traceapi.DefaultAuthScopes()) + copts, err := generateClientOptions(ctx, &te.cfg.TraceConfig.ClientConfig, &te.cfg, traceapi.DefaultAuthScopes()) if err != nil { - return nil, err + return err } topts = append(topts, texporter.WithTraceClientOptions(copts)) exp, err := texporter.New(topts...) if err != nil { - return nil, fmt.Errorf("error creating GoogleCloud Trace exporter: %w", err) + return fmt.Errorf("error creating GoogleCloud Trace exporter: %w", err) } - - return &TraceExporter{texporter: exp}, nil + te.texporter = exp + return nil } func mappingFuncFromAKM(akm []AttributeMapping) func(attribute.Key) attribute.Key { @@ -91,6 +101,9 @@ func mappingFuncFromAKM(akm []AttributeMapping) func(attribute.Key) attribute.Ke // PushTraces calls texporter.ExportSpan for each span in the given traces. func (te *TraceExporter) PushTraces(ctx context.Context, td ptrace.Traces) error { + if te.texporter == nil { + return errors.New("not started") + } resourceSpans := td.ResourceSpans() spans := make([]sdktrace.ReadOnlySpan, 0, td.SpanCount()) for i := 0; i < resourceSpans.Len(); i++ { diff --git a/exporter/collector/traces_test.go b/exporter/collector/traces_test.go index a339b5a14..00ba5f901 100644 --- a/exporter/collector/traces_test.go +++ b/exporter/collector/traces_test.go @@ -23,6 +23,7 @@ import ( "cloud.google.com/go/trace/apiv2/tracepb" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" "google.golang.org/grpc" @@ -101,6 +102,8 @@ func TestGoogleCloudTraceExport(t *testing.T) { //nolint:errcheck go srv.Serve(lis) sde, err := NewGoogleCloudTracesExporter(ctx, test.cfg, "latest", DefaultTimeout) + require.NoError(t, err) + err = sde.Start(ctx, componenttest.NewNopHost()) if test.expectedErr != "" { assert.EqualError(t, err, test.expectedErr) return