Skip to content

Commit

Permalink
Change unit of file-cache-latency to us
Browse files Browse the repository at this point in the history
  • Loading branch information
kislaykishore committed Aug 22, 2024
1 parent 3fa3f63 commit 73bc3c3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
7 changes: 4 additions & 3 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.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)
)
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
24 changes: 24 additions & 0 deletions internal/monitor/units.go
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 73bc3c3

Please sign in to comment.