diff --git a/cmd/legacy_main.go b/cmd/legacy_main.go index 7a228c5df8..1bc3b1fdcc 100644 --- a/cmd/legacy_main.go +++ b/cmd/legacy_main.go @@ -20,6 +20,7 @@ package cmd import ( + "context" "fmt" "io/fs" "os" @@ -43,7 +44,6 @@ import ( "github.com/jacobsa/fuse" "github.com/kardianos/osext" "github.com/urfave/cli" - "golang.org/x/net/context" ) const ( @@ -395,9 +395,8 @@ func Mount(newConfig *cfg.Config, bucketName, mountPoint string) (err error) { // The returned error is ignored as we do not enforce monitoring exporters _ = monitor.EnableStackdriverExporter(newConfig.Metrics.StackdriverExportInterval) _ = monitor.EnableOpenTelemetryCollectorExporter(newConfig.Monitoring.ExperimentalOpentelemetryCollectorAddress) - _ = monitor.EnablePrometheusCollectorExporter(int(newConfig.Metrics.PrometheusPort)) ctx := context.Background() - shutdownFn := monitor.SetupTracing(ctx, newConfig) + shutdownFn := monitor.SetupOTelSDK(ctx, newConfig) // Mount, writing information about our progress to the writer that package // daemonize gives us and telling it about the outcome. @@ -459,11 +458,8 @@ func Mount(newConfig *cfg.Config, bucketName, mountPoint string) (err error) { monitor.CloseStackdriverExporter() monitor.CloseOpenTelemetryCollectorExporter() - monitor.ClosePrometheusCollectorExporter() - if shutdownFn != nil { - if shutdownErr := shutdownFn(ctx); shutdownErr != nil { - logger.Errorf("Error while shutting down trace exporter: %v", shutdownErr) - } + if shutdownErr := shutdownFn(ctx); shutdownErr != nil { + logger.Errorf("Error while shutting down OTel exporters: %v", shutdownErr) } if err != nil { diff --git a/internal/monitor/units.go b/common/common.go similarity index 67% rename from internal/monitor/units.go rename to common/common.go index 839a744abf..b46d394e7f 100644 --- a/internal/monitor/units.go +++ b/common/common.go @@ -12,12 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -package monitor +package common -import "go.opencensus.io/stats" +import "go.opentelemetry.io/otel/metric" -const ( - UnitDimensionless = stats.UnitDimensionless - UnitMicroseconds = "us" - UnitBytes = stats.UnitBytes -) +var DefaultLatencyDistribution = metric.WithExplicitBucketBoundaries(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) diff --git a/go.mod b/go.mod index c847e8a23f..940a5e49c3 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( cloud.google.com/go/secretmanager v1.14.0 cloud.google.com/go/storage v1.43.0 contrib.go.opencensus.io/exporter/ocagent v0.7.0 - contrib.go.opencensus.io/exporter/prometheus v0.4.2 contrib.go.opencensus.io/exporter/stackdriver v0.13.14 github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.24.1 github.com/fsouza/fake-gcs-server v1.49.3 @@ -24,6 +23,7 @@ require ( github.com/jacobsa/timeutil v0.0.0-20170205232429-577e5acbbcf6 github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/mitchellh/mapstructure v1.5.0 + github.com/prometheus/client_golang v1.20.3 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.19.0 @@ -32,8 +32,11 @@ require ( go.opencensus.io v0.24.0 go.opentelemetry.io/contrib/detectors/gcp v1.30.0 go.opentelemetry.io/otel v1.30.0 + go.opentelemetry.io/otel/exporters/prometheus v0.52.0 go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.30.0 + go.opentelemetry.io/otel/metric v1.30.0 go.opentelemetry.io/otel/sdk v1.30.0 + go.opentelemetry.io/otel/sdk/metric v1.30.0 go.opentelemetry.io/otel/trace v1.30.0 golang.org/x/net v0.30.0 golang.org/x/oauth2 v0.23.0 @@ -70,8 +73,6 @@ require ( github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/go-kit/log v0.2.1 // indirect - github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect @@ -85,18 +86,17 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/magiconair/properties v1.8.7 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pkg/xattr v0.4.10 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_golang v1.13.0 // indirect - github.com/prometheus/client_model v0.6.0 // indirect - github.com/prometheus/common v0.37.0 // indirect - github.com/prometheus/procfs v0.8.0 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/procfs v0.15.1 // indirect github.com/prometheus/prometheus v0.35.0 // indirect - github.com/prometheus/statsd_exporter v0.22.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect @@ -108,7 +108,6 @@ require ( github.com/subosito/gotenv v1.6.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect - go.opentelemetry.io/otel/metric v1.30.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.28.0 // indirect golang.org/x/exp v0.0.0-20240530194437-404ba88c7ed0 // indirect @@ -116,5 +115,4 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index beafba9465..4b9971b180 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,6 @@ cloud.google.com/go/trace v1.11.0 h1:UHX6cOJm45Zw/KIbqHe4kII8PupLt/V5tscZUkeiJVI cloud.google.com/go/trace v1.11.0/go.mod h1:Aiemdi52635dBR7o3zuc9lLjXo3BwGaChEjCa3tJNmM= contrib.go.opencensus.io/exporter/ocagent v0.7.0 h1:BEfdCTXfMV30tLZD8c9n64V/tIZX5+9sXiuFLnrr1k8= contrib.go.opencensus.io/exporter/ocagent v0.7.0/go.mod h1:IshRmMJBhDfFj5Y67nVhMYTTIze91RUeT73ipWKs/GY= -contrib.go.opencensus.io/exporter/prometheus v0.4.2 h1:sqfsYl5GIY/L570iT+l93ehxaWJs2/OwXtiWwew3oAg= -contrib.go.opencensus.io/exporter/prometheus v0.4.2/go.mod h1:dvEHbiKmgvbr5pjaF9fpw1KeYcjrnC1J8B+JKjsZyRQ= contrib.go.opencensus.io/exporter/stackdriver v0.13.14 h1:zBakwHardp9Jcb8sQHcHpXy/0+JIb1M8KjigCJzx7+4= contrib.go.opencensus.io/exporter/stackdriver v0.13.14/go.mod h1:5pSSGY0Bhuk7waTHuDf4aQ8D2DrhgETRo9fy6k3Xlzc= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= @@ -453,12 +451,9 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2 github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-kit/log v0.2.0/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= -github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= -github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA= github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= @@ -611,7 +606,6 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= -github.com/google/go-cmp v0.5.8/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.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0= @@ -855,7 +849,6 @@ github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vq github.com/mattn/go-shellwords v1.0.6/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -905,6 +898,7 @@ github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJ github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= @@ -1001,16 +995,15 @@ github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3O github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= -github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= -github.com/prometheus/client_golang v1.13.0 h1:b71QUfeo5M8gq2+evJdTPfZhYMAU0uKPkyPJ7TPsloU= -github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ= +github.com/prometheus/client_golang v1.20.3 h1:oPksm4K8B+Vt35tUhw6GbSNSgVlVSBH0qELP/7u83l4= +github.com/prometheus/client_golang v1.20.3/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= -github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= +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/common v0.0.0-20180110214958-89604d197083/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= @@ -1023,9 +1016,8 @@ github.com/prometheus/common v0.29.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+ github.com/prometheus/common v0.30.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= github.com/prometheus/common v0.34.0/go.mod h1:gB3sOl7P0TvJabZpLY5uQMpUqRCPPCyRLCZYc7JZTNE= -github.com/prometheus/common v0.35.0/go.mod h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA= -github.com/prometheus/common v0.37.0 h1:ccBbHCgIiT9uSoFY0vX8H3zsNR5eLt17/RQLUvn8pXE= -github.com/prometheus/common v0.37.0/go.mod h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA= +github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= +github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= github.com/prometheus/common/assets v0.1.0/go.mod h1:D17UVUE12bHbim7HzwUvtqm6gwBEaDQ0F+hIGbFbccI= github.com/prometheus/common/sigv4 v0.1.0/go.mod h1:2Jkxxk9yYvCkE5G1sQT7GuEXm57JrvHu9k5YwTjsNtI= github.com/prometheus/exporter-toolkit v0.7.1/go.mod h1:ZUBIj498ePooX9t/2xtDjeQYwvRpiPP2lh5u4iblj2g= @@ -1041,12 +1033,10 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= -github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/prometheus/prometheus v0.35.0 h1:N93oX6BrJ2iP3UuE2Uz4Lt+5BkUpaFer3L9CbADzesc= github.com/prometheus/prometheus v0.35.0/go.mod h1:7HaLx5kEPKJ0GDgbODG0fZgXbQ8K/XjZNJXQmbmgQlY= -github.com/prometheus/statsd_exporter v0.22.7 h1:7Pji/i2GuhK6Lu7DHrtTkFmNBCudCPT1pX2CziuyQR0= -github.com/prometheus/statsd_exporter v0.22.7/go.mod h1:N/TevpjkIh9ccs6nuzY3jQn9dFqnUakOjnEuMPJJJnI= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= @@ -1146,7 +1136,6 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= @@ -1250,6 +1239,8 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.3.0/go.mod h1 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.6.1/go.mod h1:UJJXJj0rltNIemDMwkOJyggsvyMG9QHfJeFH0HS5JjM= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.3.0/go.mod h1:QNX1aly8ehqqX1LEa6YniTU7VY9I6R3X/oPxhGdTceE= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.6.1/go.mod h1:DAKwdo06hFLc0U88O10x4xnb5sc7dDRDqRuiN+io8JE= +go.opentelemetry.io/otel/exporters/prometheus v0.52.0 h1:kmU3H0b9ufFSi8IQCcxack+sWUblKkFbqWYs6YiACGQ= +go.opentelemetry.io/otel/exporters/prometheus v0.52.0/go.mod h1:+wsAp2+JhuGXX7YRkjlkx6hyWY3ogFPfNA4x3nyiAh0= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.30.0 h1:kn1BudCgwtE7PxLqcZkErpD8GKqLZ6BSzeW9QihQJeM= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.30.0/go.mod h1:ljkUDtAMdleoi9tIG1R6dJUpVwDcYjw3J2Q6Q/SuiC0= go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= @@ -1264,6 +1255,8 @@ go.opentelemetry.io/otel/sdk v1.30.0 h1:cHdik6irO49R5IysVhdn8oaiR9m8XluDaJAs4DfO go.opentelemetry.io/otel/sdk v1.30.0/go.mod h1:p14X4Ok8S+sygzblytT1nqG98QG2KYKv++HE0LY/mhg= go.opentelemetry.io/otel/sdk/export/metric v0.20.0/go.mod h1:h7RBNMsDJ5pmI1zExLi+bJK+Dr8NQCh0qGhm1KDnNlE= go.opentelemetry.io/otel/sdk/metric v0.20.0/go.mod h1:knxiS8Xd4E/N+ZqKmUPf3gTTZ4/0TjTXukfxjzSTpHE= +go.opentelemetry.io/otel/sdk/metric v1.30.0 h1:QJLT8Pe11jyHBHfSAgYH7kEmT24eX792jZO1bo4BXkM= +go.opentelemetry.io/otel/sdk/metric v1.30.0/go.mod h1:waS6P3YqFNzeP01kuo/MBBYqaoBJl7efRQHOaydhy1Y= go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk= go.opentelemetry.io/otel/trace v1.6.0/go.mod h1:qs7BrU5cZ8dXQHBGxHMOxwME/27YH2qEp4/+tZLLwJE= @@ -1458,7 +1451,6 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= @@ -1587,7 +1579,6 @@ golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= @@ -1877,7 +1868,6 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= diff --git a/internal/fs/wrappers/monitoring.go b/internal/fs/wrappers/monitoring.go index 4387812e02..cb086d51ac 100644 --- a/internal/fs/wrappers/monitoring.go +++ b/internal/fs/wrappers/monitoring.go @@ -17,27 +17,25 @@ package wrappers import ( "context" "errors" - "fmt" "syscall" "time" - "github.com/googlecloudplatform/gcsfuse/v2/internal/logger" - "github.com/googlecloudplatform/gcsfuse/v2/internal/monitor" - "github.com/googlecloudplatform/gcsfuse/v2/internal/monitor/tags" + "github.com/googlecloudplatform/gcsfuse/v2/common" "github.com/jacobsa/fuse/fuseops" "github.com/jacobsa/fuse/fuseutil" - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" ) const name = "cloud.google.com/gcsfuse" var ( - opsCount = stats.Int64("fs/ops_count", "The number of ops processed by the file system.", monitor.UnitDimensionless) - opsLatency = stats.Int64("fs/ops_latency", "The latency of a file system operation.", monitor.UnitMicroseconds) - opsErrorCount = stats.Int64("fs/ops_error_count", "The number of errors generated by file system operation.", monitor.UnitDimensionless) + meter = otel.Meter("fs") + opsCount, _ = meter.Int64Counter("fs/ops_count", metric.WithDescription("The number of ops processed by the file system.")) + opsLatency, _ = meter.Int64Histogram("fs/ops_latency", metric.WithDescription("The latency of a file system operation."), metric.WithUnit("us"), + common.DefaultLatencyDistribution) + opsErrorCount, _ = meter.Int64Counter("fs/ops_error_count", metric.WithDescription("The number of errors generated by file system operation.")) ) // Error categories @@ -62,32 +60,32 @@ const ( // Initialize the metrics. func init() { - - // Register the view. - if err := view.Register( - &view.View{ - Name: "fs/ops_count", - Measure: opsCount, - Description: "The cumulative number of ops processed by the file system.", - Aggregation: view.Sum(), - TagKeys: []tag.Key{tags.FSOp}, - }, - &view.View{ - Name: "fs/ops_error_count", - Measure: opsErrorCount, - Description: "The cumulative number of errors generated by file system operations", - Aggregation: view.Sum(), - TagKeys: []tag.Key{tags.FSOp, tags.FSErrCategory}, - }, - &view.View{ - Name: "fs/ops_latency", - Measure: opsLatency, - Description: "The cumulative distribution of file system operation latencies", - Aggregation: ochttp.DefaultLatencyDistribution, - TagKeys: []tag.Key{tags.FSOp}, - }); err != nil { - fmt.Printf("Failed to register metrics for the file system: %v\n", err) - } + /* + // Register the view. + if err := view.Register( + &view.View{ + Name: "fs/ops_count", + Measure: opsCount, + Description: "The cumulative number of ops processed by the file system.", + Aggregation: view.Sum(), + TagKeys: []tag.Key{tags.FSOp}, + }, + &view.View{ + Name: "fs/ops_error_count", + Measure: opsErrorCount, + Description: "The cumulative number of errors generated by file system operations", + Aggregation: view.Sum(), + TagKeys: []tag.Key{tags.FSOp, tags.FSErrCategory}, + }, + &view.View{ + Name: "fs/ops_latency", + Measure: opsLatency, + Description: "The cumulative distribution of file system operation latencies", + Aggregation: ochttp.DefaultLatencyDistribution, + TagKeys: []tag.Key{tags.FSOp}, + }); err != nil { + fmt.Printf("Failed to register metrics for the file system: %v\n", err) + }*/ } // categorize maps an error to an error-category. @@ -270,44 +268,15 @@ func categorize(err error) string { // Records file system operation count, failed operation count and the operation latency. func recordOp(ctx context.Context, method string, start time.Time, fsErr error) { // Recording opCount. - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.FSOp, method), - }, - opsCount.M(1), - ); err != nil { - // Error in recording opCount. - logger.Errorf("Cannot record file system op: %v", err) - } + opsCount.Add(ctx, 1, metric.WithAttributes(attribute.String("fs_op", method))) // Recording opErrorCount. if fsErr != nil { errCategory := categorize(fsErr) - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.FSOp, method), - tag.Upsert(tags.FSErrCategory, errCategory), - }, - opsErrorCount.M(1), - ); err != nil { - // Error in recording opErrorCount. - logger.Errorf("Cannot record error count of the file system failed operations: %v", err) - } + opsErrorCount.Add(ctx, 1, metric.WithAttributes(attribute.String("fs_op", method), attribute.String("fs_error_category", errCategory))) } - // Recording opLatency. - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.FSOp, method), - }, - opsLatency.M(time.Since(start).Microseconds()), - ); err != nil { - // Error in opLatency. - logger.Errorf("Cannot record file system operation latency: %v", err) - } + opsLatency.Record(ctx, time.Since(start).Microseconds(), metric.WithAttributes(attribute.String("fs_op", method))) } // WithMonitoring takes a FileSystem, returns a FileSystem with monitoring diff --git a/internal/monitor/bucket.go b/internal/monitor/bucket.go index ae5f5281b0..4a21d7db38 100644 --- a/internal/monitor/bucket.go +++ b/internal/monitor/bucket.go @@ -20,83 +20,25 @@ import ( "io" "time" - "github.com/googlecloudplatform/gcsfuse/v2/internal/logger" - "github.com/googlecloudplatform/gcsfuse/v2/internal/monitor/tags" "github.com/googlecloudplatform/gcsfuse/v2/internal/storage/gcs" - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" ) var ( + meter = otel.Meter("gcs") // OpenCensus measures - readBytesCount = stats.Int64("gcs/read_bytes_count", "The number of bytes read from GCS objects.", stats.UnitBytes) - readerCount = stats.Int64("gcs/reader_count", "The number of GCS object readers opened or closed.", stats.UnitDimensionless) - requestCount = stats.Int64("gcs/request_count", "The number of GCS requests processed.", stats.UnitDimensionless) - requestLatency = stats.Float64("gcs/request_latency", "The latency of a GCS request.", stats.UnitMilliseconds) + readBytesCount, _ = meter.Int64Counter("gcs/read_bytes_count", metric.WithDescription("The number of bytes read from GCS objects."), metric.WithUnit("By")) + readerCount, _ = meter.Int64Counter("gcs/reader_count", metric.WithDescription("The number of GCS object readers opened or closed.")) + requestCount, _ = meter.Int64Counter("gcs/request_count", metric.WithDescription("The number of GCS requests processed.")) + requestLatency, _ = meter.Int64Histogram("gcs/request_latencies", metric.WithDescription("The latency of a GCS request."), metric.WithUnit("ms")) ) -// Initialize the metrics. -func init() { - // OpenCensus views (aggregated measures) - if err := view.Register( - &view.View{ - Name: "gcs/read_bytes_count", - Measure: readBytesCount, - Description: "The cumulative number of bytes read from GCS objects.", - Aggregation: view.Sum(), - }, - &view.View{ - Name: "gcs/reader_count", - Measure: readerCount, - Description: "The cumulative number of GCS object readers opened or closed.", - Aggregation: view.Sum(), - TagKeys: []tag.Key{tags.IOMethod}, - }, - &view.View{ - Name: "gcs/request_count", - Measure: requestCount, - Description: "The cumulative number of GCS requests processed.", - Aggregation: view.Sum(), - TagKeys: []tag.Key{tags.GCSMethod}, - }, - &view.View{ - Name: "gcs/request_latencies", - Measure: requestLatency, - Description: "The cumulative distribution of the GCS request latencies.", - Aggregation: ochttp.DefaultLatencyDistribution, - TagKeys: []tag.Key{tags.GCSMethod}, - }); err != nil { - fmt.Printf("Failed to register OpenCensus metrics for GCS client library: %v", err) - } -} - // recordRequest records a request and its latency. func recordRequest(ctx context.Context, method string, start time.Time) { - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.GCSMethod, method), - }, - requestCount.M(1), - ); err != nil { - // The error should be caused by a bad tag - logger.Errorf("Cannot record request count: %v", err) - } - - latencyUs := time.Since(start).Microseconds() - latencyMs := float64(latencyUs) / 1000.0 - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.GCSMethod, method), - }, - requestLatency.M(latencyMs), - ); err != nil { - // The error should be caused by a bad tag - logger.Errorf("Cannot record request latency: %v", err) - } + requestCount.Add(ctx, 1, metric.WithAttributes(attribute.String("gcs_method", method))) + requestLatency.Record(ctx, time.Since(start).Milliseconds(), metric.WithAttributes(attribute.String("gcs_method", method))) } // NewMonitoringBucket returns a gcs.Bucket that exports metrics for monitoring @@ -225,15 +167,7 @@ func (mb *monitoringBucket) RenameFolder(ctx context.Context, folderName string, // recordReader increments the reader count when it's opened or closed. func recordReader(ctx context.Context, ioMethod string) { - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.IOMethod, ioMethod), - }, - readerCount.M(1), - ); err != nil { - logger.Errorf("Cannot record a reader %v: %v", ioMethod, err) - } + readerCount.Add(ctx, 1, metric.WithAttributes(attribute.String("io_method", ioMethod))) } // Monitoring on the object reader @@ -255,7 +189,7 @@ type monitoringReadCloser struct { func (mrc *monitoringReadCloser) Read(p []byte) (n int, err error) { n, err = mrc.wrapped.Read(p) if err == nil || err == io.EOF { - stats.Record(mrc.ctx, readBytesCount.M(int64(n))) + readBytesCount.Add(mrc.ctx, int64(n)) } return } diff --git a/internal/monitor/exporter.go b/internal/monitor/exporter.go index 089f2c5936..f21188dea3 100644 --- a/internal/monitor/exporter.go +++ b/internal/monitor/exporter.go @@ -15,15 +15,11 @@ package monitor import ( - "context" - "errors" "fmt" - "net/http" "strings" "time" "contrib.go.opencensus.io/exporter/ocagent" - "contrib.go.opencensus.io/exporter/prometheus" "contrib.go.opencensus.io/exporter/stackdriver" "github.com/googlecloudplatform/gcsfuse/v2/internal/logger" "go.opencensus.io/stats/view" @@ -110,70 +106,3 @@ func CloseOpenTelemetryCollectorExporter() { } ocExporter = nil } - -var prometheusExporter *prometheus.Exporter -var prometheusServer *http.Server - -// EnablePrometheusCollectorExporter starts exporting monitoring metrics for -// the Prometheus to scrape on the given port. -func EnablePrometheusCollectorExporter(port int) error { - if port == 0 { - return nil - } - - if prometheusServer != nil { - return errors.New("a Prometheus server is already running") - } - - if prometheusExporter != nil { - return errors.New("a Prometheus exporter is already running") - } - - var err error - if prometheusExporter, err = prometheus.NewExporter( - prometheus.Options{ - OnError: func(err error) { - logger.Errorf("Fail to collect metric: %v", err) - }, - }, - ); err != nil { - return fmt.Errorf("create Prometheus collector exporter: %w", err) - } - - view.RegisterExporter(prometheusExporter) - - mux := http.NewServeMux() - mux.HandleFunc("/metrics", prometheusExporter.ServeHTTP) - prometheusServer = &http.Server{ - Addr: fmt.Sprintf(":%d", port), - Handler: mux, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, - MaxHeaderBytes: 1 << 20, - } - - go func() { - if err := prometheusServer.ListenAndServe(); err != nil { - logger.Errorf("Failed to start Prometheus server: %v", err) - } - }() - - logger.Info("Prometheus collector exporter started") - return nil -} - -// ClosePrometheusCollectorExporter closes the Prometheus exporter. -func ClosePrometheusCollectorExporter() { - if prometheusServer != nil { - if err := prometheusServer.Shutdown(context.Background()); err != nil { - logger.Errorf("Failed to shutdown Prometheus server: %v", err) - } - } - - if prometheusExporter != nil { - view.UnregisterExporter(prometheusExporter) - } - - prometheusServer = nil - prometheusExporter = nil -} diff --git a/internal/monitor/traceexporter.go b/internal/monitor/otelexporters.go similarity index 56% rename from internal/monitor/traceexporter.go rename to internal/monitor/otelexporters.go index 232c0df1b8..395811741b 100644 --- a/internal/monitor/traceexporter.go +++ b/internal/monitor/otelexporters.go @@ -16,13 +16,21 @@ package monitor import ( "context" + "errors" + "fmt" + "log" + "net/http" + "time" cloudtrace "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace" "github.com/googlecloudplatform/gcsfuse/v2/cfg" "github.com/googlecloudplatform/gcsfuse/v2/common" "github.com/googlecloudplatform/gcsfuse/v2/internal/logger" + "github.com/prometheus/client_golang/prometheus/promhttp" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/prometheus" "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" + "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/trace" @@ -33,8 +41,78 @@ import ( type ShutdownFn func(ctx context.Context) error -// SetupTracing bootstraps the OpenTelemetry tracing pipeline. -func SetupTracing(ctx context.Context, c *cfg.Config) ShutdownFn { +func SetupOTelSDK(ctx context.Context, c *cfg.Config) (shutdown ShutdownFn) { + var shutdownFuncs []func(context.Context) error + + shutdown = func(ctx context.Context) error { + var err error + for _, fn := range shutdownFuncs { + err = errors.Join(err, fn(ctx)) + } + shutdownFuncs = nil + return err + } + + if shutdownFn := setupTracing(ctx, c); shutdownFn != nil { + shutdownFuncs = append(shutdownFuncs, shutdownFn) + } + + if shutdownFn := setupMetrics(ctx, c); shutdownFn != nil { + shutdownFuncs = append(shutdownFuncs, shutdownFn) + } + return shutdown +} + +func setupMetrics(_ context.Context, c *cfg.Config) ShutdownFn { + exporter, err := prometheus.New(prometheus.WithoutUnits(), prometheus.WithoutCounterSuffixes(), prometheus.WithoutScopeInfo(), prometheus.WithoutTargetInfo()) + if err != nil { + logger.Errorf("Error while creating prometheus exporter") + return nil + } + + meterProvider := metric.NewMeterProvider( + metric.WithReader(exporter), + ) + otel.SetMeterProvider(meterProvider) + ch := make(chan context.Context) + go serveMetrics(c.Metrics.PrometheusPort, ch) + return func(ctx context.Context) error { + ch <- ctx + return nil + } +} + +func serveMetrics(port int64, done <-chan context.Context) { + log.Printf("serving metrics at localhost:%d/metrics", port) + mux := http.NewServeMux() + mux.Handle("/metrics", promhttp.Handler()) + prometheusServer := &http.Server{ + Addr: fmt.Sprintf(":%d", port), + Handler: mux, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + MaxHeaderBytes: 1 << 20, + } + + go func() { + if err := prometheusServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { + logger.Errorf("Failed to start Prometheus server: %v", err) + } + }() + + go func() { + ctx := <-done + if err := prometheusServer.Shutdown(ctx); err != nil { + logger.Errorf("Error while shutting down Prometheus exporter:%v", err) + return + } + logger.Info("Prometheus exporter shutdown") + }() + + logger.Info("Prometheus collector exporter started") +} + +func setupTracing(ctx context.Context, c *cfg.Config) ShutdownFn { tp, shutdown, err := newTraceProvider(ctx, c) if err != nil { logger.Errorf("error occurred while setting up tracing: %v", err) diff --git a/internal/monitor/reader.go b/internal/monitor/reader.go index d31b4772d2..d6868de2e3 100644 --- a/internal/monitor/reader.go +++ b/internal/monitor/reader.go @@ -15,144 +15,44 @@ package monitor import ( - "log" - "strconv" "time" - "github.com/googlecloudplatform/gcsfuse/v2/internal/logger" - "github.com/googlecloudplatform/gcsfuse/v2/internal/monitor/tags" - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" + "github.com/googlecloudplatform/gcsfuse/v2/common" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" "golang.org/x/net/context" ) var ( + gcsMeter = otel.Meter("gcs") + fileCacheMeter = otel.Meter("file_cache") // When a first read call is made by the user, we either fetch entire file or x number of bytes from GCS based on the request. // Now depending on the pagesize multiple read calls will be issued by user to read the entire file. These // requests will be served from the downloaded data. // This metric captures only the requests made to GCS, not the subsequent page calls. - gcsReadCount = stats.Int64("gcs/read_count", - "Specifies the number of gcs reads made along with type - Sequential/Random", - UnitDimensionless) - downloadBytesCount = stats.Int64("gcs/download_bytes_count", - "The cumulative number of bytes downloaded from GCS along with type - Sequential/Random", - UnitBytes) - fileCacheReadCount = stats.Int64("file_cache/read_count", - "Specifies the number of read requests made via file cache along with type - Sequential/Random and cache hit - true/false", - UnitDimensionless) - fileCacheReadBytesCount = stats.Int64("file_cache/read_bytes_count", - "The cumulative number of bytes read from file cache along with read type - Sequential/Random", - UnitBytes) - fileCacheReadLatency = stats.Int64("file_cache/read_latency", - "Latency of read from file cache along with cache hit - true/false", - UnitMicroseconds) + gcsReadCount, _ = gcsMeter.Int64Counter("gcs/read_count", metric.WithDescription("Specifies the number of gcs reads made along with type - Sequential/Random")) + downloadBytesCount, _ = gcsMeter.Int64Counter("gcs/download_bytes_count", + metric.WithDescription("The cumulative number of bytes downloaded from GCS along with type - Sequential/Random"), + metric.WithUnit("By")) + fileCacheReadCount, _ = fileCacheMeter.Int64Counter("file_cache/read_count", + metric.WithDescription("Specifies the number of read requests made via file cache along with type - Sequential/Random and cache hit - true/false")) + fileCacheReadBytesCount, _ = fileCacheMeter.Int64Counter("file_cache/read_bytes_count", + metric.WithDescription("The cumulative number of bytes read from file cache along with read type - Sequential/Random"), + metric.WithUnit("By")) + fileCacheReadLatency, _ = fileCacheMeter.Int64Histogram("file_cache/read_latencies", + metric.WithDescription("Latency of read from file cache along with cache hit - true/false"), + metric.WithUnit("us"), + common.DefaultLatencyDistribution) ) -const NanosecondsInOneMillisecond = 1000000 - -// Initialize the metrics. -func init() { - // GCS related metrics - if err := view.Register( - &view.View{ - Name: "gcs/read_count", - Measure: gcsReadCount, - Description: "Specifies the number of gcs reads made along with type - Sequential/Random", - Aggregation: view.Sum(), - TagKeys: []tag.Key{tags.ReadType}, - }, - &view.View{ - Name: "gcs/download_bytes_count", - Measure: downloadBytesCount, - Description: "The cumulative number of bytes downloaded from GCS along with type - Sequential/Random", - Aggregation: view.Sum(), - TagKeys: []tag.Key{tags.ReadType}, - }, - // File cache related metrics - &view.View{ - Name: "file_cache/read_count", - Measure: fileCacheReadCount, - Description: "Specifies the number of read requests made via file cache along with type - Sequential/Random and cache hit - true/false", - Aggregation: view.Sum(), - TagKeys: []tag.Key{tags.ReadType, tags.CacheHit}, - }, - &view.View{ - Name: "file_cache/read_bytes_count", - Measure: fileCacheReadBytesCount, - Description: "The cumulative number of bytes read from file cache along with read type - Sequential/Random", - Aggregation: view.Sum(), - TagKeys: []tag.Key{tags.ReadType}, - }, - &view.View{ - Name: "file_cache/read_latencies", - Measure: fileCacheReadLatency, - Description: "The cumulative distribution of the file cache read latencies along with cache hit - true/false", - Aggregation: ochttp.DefaultLatencyDistribution, - TagKeys: []tag.Key{tags.CacheHit}, - }, - ); err != nil { - log.Fatalf("Failed to register the reader view: %v", err) - } -} - func CaptureGCSReadMetrics(ctx context.Context, readType string, requestedDataSize int64) { - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.ReadType, readType), - }, - gcsReadCount.M(1), - ); err != nil { - // Error in recording gcsReadCount. - logger.Errorf("Cannot record gcsReadCount %v", err) - } - - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.ReadType, readType), - }, - downloadBytesCount.M(requestedDataSize), - ); err != nil { - // Error in recording downloadBytesCount. - logger.Errorf("Cannot record downloadBytesCount %v", err) - } + gcsReadCount.Add(ctx, 1, metric.WithAttributes(attribute.String("read_type", readType))) + downloadBytesCount.Add(ctx, requestedDataSize, metric.WithAttributes(attribute.String("read_type", readType))) } func CaptureFileCacheMetrics(ctx context.Context, readType string, readDataSize int, cacheHit bool, readLatency time.Duration) { - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.ReadType, readType), - tag.Upsert(tags.CacheHit, strconv.FormatBool(cacheHit)), - }, - fileCacheReadCount.M(1), - ); err != nil { - // Error in recording fileCacheReadCount. - logger.Errorf("Cannot record fileCacheReadCount %v", err) - } - - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.ReadType, readType), - }, - fileCacheReadBytesCount.M(int64(readDataSize)), - ); err != nil { - // Error in recording fileCacheReadBytesCount. - logger.Errorf("Cannot record fileCacheReadBytesCount %v", err) - } - - if err := stats.RecordWithTags( - ctx, - []tag.Mutator{ - tag.Upsert(tags.CacheHit, strconv.FormatBool(cacheHit)), - }, - fileCacheReadLatency.M(readLatency.Microseconds()), - ); err != nil { - // Error in recording fileCacheReadLatency. - logger.Errorf("Cannot record fileCacheReadLatency %v", err) - } + fileCacheReadCount.Add(ctx, 1, metric.WithAttributes(attribute.String("read_type", readType), attribute.Bool("cache_hit", cacheHit))) + fileCacheReadBytesCount.Add(ctx, int64(readDataSize), metric.WithAttributes(attribute.String("read_type", readType))) + fileCacheReadLatency.Record(ctx, readLatency.Microseconds(), metric.WithAttributes(attribute.Bool("cache_hit", cacheHit))) }