diff --git a/internal/fs/wrappers/monitoring.go b/internal/fs/wrappers/monitoring.go index f787caacec..ec7def2cf3 100644 --- a/internal/fs/wrappers/monitoring.go +++ b/internal/fs/wrappers/monitoring.go @@ -22,6 +22,7 @@ import ( "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/jacobsa/fuse/fuseops" "github.com/jacobsa/fuse/fuseutil" @@ -38,9 +39,9 @@ import ( const name = "cloud.google.com/gcsfuse" var ( - opsCount = stats.Int64("fs/ops_count", "The number of ops processed by the file system.", stats.UnitDimensionless) - opsLatency = stats.Int64("fs/ops_latency", "The latency of a file system operation.", "us") - opsErrorCount = stats.Int64("fs/ops_error_count", "The number of errors generated by file system operation.", stats.UnitDimensionless) + 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) tracer = otel.Tracer(name) ) diff --git a/internal/gcsx/random_reader.go b/internal/gcsx/random_reader.go index d883fac880..96c90eca1c 100644 --- a/internal/gcsx/random_reader.go +++ b/internal/gcsx/random_reader.go @@ -202,7 +202,7 @@ func (rr *randomReader) tryReadingFromFileCache(ctx context.Context, readType = util.Sequential } // Capture file cache metrics to be exported via stackdriver - monitor.CaptureFileCacheMetrics(ctx, readType, n, cacheHit, executionTime.Nanoseconds()) + monitor.CaptureFileCacheMetrics(ctx, readType, n, cacheHit, executionTime) }() // Create fileCacheHandle if not already. diff --git a/internal/monitor/reader.go b/internal/monitor/reader.go index a1c957de4c..d31b4772d2 100644 --- a/internal/monitor/reader.go +++ b/internal/monitor/reader.go @@ -17,6 +17,7 @@ package monitor import ( "log" "strconv" + "time" "github.com/googlecloudplatform/gcsfuse/v2/internal/logger" "github.com/googlecloudplatform/gcsfuse/v2/internal/monitor/tags" @@ -34,19 +35,19 @@ var ( // 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", - stats.UnitDimensionless) + UnitDimensionless) downloadBytesCount = stats.Int64("gcs/download_bytes_count", "The cumulative number of bytes downloaded from GCS along with type - Sequential/Random", - stats.UnitBytes) + 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", - stats.UnitDimensionless) + UnitDimensionless) fileCacheReadBytesCount = stats.Int64("file_cache/read_bytes_count", "The cumulative number of bytes read from file cache along with read type - Sequential/Random", - stats.UnitBytes) - fileCacheReadLatency = stats.Float64("file_cache/read_latency", + UnitBytes) + fileCacheReadLatency = stats.Int64("file_cache/read_latency", "Latency of read from file cache along with cache hit - true/false", - stats.UnitMilliseconds) + UnitMicroseconds) ) const NanosecondsInOneMillisecond = 1000000 @@ -120,7 +121,7 @@ func CaptureGCSReadMetrics(ctx context.Context, readType string, requestedDataSi } } -func CaptureFileCacheMetrics(ctx context.Context, readType string, readDataSize int, cacheHit bool, readLatencyNs int64) { +func CaptureFileCacheMetrics(ctx context.Context, readType string, readDataSize int, cacheHit bool, readLatency time.Duration) { if err := stats.RecordWithTags( ctx, []tag.Mutator{ @@ -144,13 +145,12 @@ func CaptureFileCacheMetrics(ctx context.Context, readType string, readDataSize logger.Errorf("Cannot record fileCacheReadBytesCount %v", err) } - readLatencyMs := float64(readLatencyNs) / float64(NanosecondsInOneMillisecond) if err := stats.RecordWithTags( ctx, []tag.Mutator{ tag.Upsert(tags.CacheHit, strconv.FormatBool(cacheHit)), }, - fileCacheReadLatency.M(readLatencyMs), + fileCacheReadLatency.M(readLatency.Microseconds()), ); err != nil { // Error in recording fileCacheReadLatency. logger.Errorf("Cannot record fileCacheReadLatency %v", err) diff --git a/internal/monitor/units.go b/internal/monitor/units.go new file mode 100644 index 0000000000..fb4da4ea70 --- /dev/null +++ b/internal/monitor/units.go @@ -0,0 +1,24 @@ +// Copyright 2024 Google LLC +// +// 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 monitor + +import "go.opencensus.io/stats" + +const ( + UnitDimensionless = stats.UnitDimensionless + UnitMicroseconds = "us" + + UnitBytes = stats.UnitBytes +)