Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change unit of ops and file-cache latency metrics to microseconds #2380

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/fs/wrappers/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.Float64("fs/ops_latency", "The latency of a file system operation.", stats.UnitMilliseconds)
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)
)
Expand Down Expand Up @@ -292,13 +293,12 @@ func recordOp(ctx context.Context, method string, start time.Time, fsErr error)
}

// Recording opLatency.
latencyMs := float64(time.Since(start).Microseconds()) / 1000.0
if err := stats.RecordWithTags(
ctx,
[]tag.Mutator{
tag.Upsert(tags.FSOp, method),
},
opsLatency.M(latencyMs),
opsLatency.M(time.Since(start).Microseconds()),
); err != nil {
// Error in opLatency.
logger.Errorf("Cannot record file system operation latency: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/gcsx/random_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions internal/monitor/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions internal/monitor/units.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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
)
Loading