Skip to content

Commit 03c326e

Browse files
authored
test(monitoring): add integration tests for kernel reader metrics (#4318)
* Add metrics test for Kernel reader
1 parent f7b3616 commit 03c326e

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package monitoring
16+
17+
import (
18+
"log"
19+
"os"
20+
"path"
21+
"strings"
22+
"testing"
23+
24+
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/client"
25+
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
26+
"github.com/stretchr/testify/require"
27+
"github.com/stretchr/testify/suite"
28+
)
29+
30+
type PromKernelReaderTest struct {
31+
PromTestBase
32+
}
33+
34+
func (p *PromKernelReaderTest) TestKernelReaderMetrics() {
35+
testName := strings.ReplaceAll(p.T().Name(), "/", "_")
36+
gcsDir := path.Join(testDirName, testName)
37+
fileName := "mrd_test_file.txt"
38+
client.SetupFileInTestDirectory(testEnv.ctx, testEnv.storageClient, gcsDir, fileName, 10*1024*1024, p.T())
39+
40+
// Read file to trigger metrics
41+
_, err := os.ReadFile(path.Join(testEnv.testDirPath, fileName))
42+
43+
require.NoError(p.T(), err)
44+
assertNonZeroCountMetric(p.T(), "fs_ops_count", "fs_op", "ReadFile", p.prometheusPort)
45+
assertNonZeroCountMetric(p.T(), "gcs_download_bytes_count", "read_type", "Parallel", p.prometheusPort)
46+
assertNonZeroCountMetric(p.T(), "gcs_read_bytes_count", "", "", p.prometheusPort)
47+
assertNonZeroCountMetric(p.T(), "gcs_read_count", "read_type", "Parallel", p.prometheusPort)
48+
assertNonZeroCountMetric(p.T(), "gcs_request_count", "gcs_method", "MultiRangeDownloader::Add", p.prometheusPort)
49+
assertNonZeroHistogramMetric(p.T(), "gcs_request_latencies", "gcs_method", "MultiRangeDownloader::Add", p.prometheusPort)
50+
}
51+
52+
func TestPromKernelReaderSuite(t *testing.T) {
53+
ts := &PromKernelReaderTest{}
54+
flagSets := setup.BuildFlagSets(*testEnv.cfg, testEnv.bucketType, t.Name())
55+
for _, flags := range flagSets {
56+
ts.flags = flags
57+
ts.prometheusPort = parsePortFromFlags(flags)
58+
log.Printf("Running prom kernel reader tests with flags: %s", ts.flags)
59+
suite.Run(t, ts)
60+
}
61+
}

tools/integration_tests/monitoring/setup_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestMain(m *testing.M) {
176176
testEnv.cfg.LogFile = setup.LogFile()
177177
testEnv.cfg.GKEMountedDirectory = setup.MountedDirectory()
178178

179-
testEnv.cfg.Configs = make([]test_suite.ConfigItem, 6)
179+
testEnv.cfg.Configs = make([]test_suite.ConfigItem, 7)
180180
testEnv.cfg.Configs[0].Flags = []string{"--prometheus-port=9190 --cache-dir=/gcsfuse-tmp/PromOTELSuite --log-file=/gcsfuse-tmp/monitoring.log --enable-kernel-reader=false"}
181181
testEnv.cfg.Configs[0].Compatible = map[string]bool{"flat": true, "hns": false, "zonal": false}
182182
testEnv.cfg.Configs[0].Run = "TestPromOTELSuite"
@@ -197,6 +197,10 @@ func TestMain(m *testing.M) {
197197
testEnv.cfg.Configs[5].Flags = []string{"--client-protocol=grpc --experimental-enable-grpc-metrics=true --prometheus-port=10192 --cache-dir=/gcsfuse-tmp/TestPromGrpcMetricsSuite --log-file=/gcsfuse-tmp/prom_grpc_metrics_hns.log --enable-kernel-reader=false"}
198198
testEnv.cfg.Configs[5].Compatible = map[string]bool{"flat": false, "hns": true, "zonal": true}
199199
testEnv.cfg.Configs[5].Run = "TestPromGrpcMetricsSuite"
200+
201+
testEnv.cfg.Configs[6].Flags = []string{"--prometheus-port=9193 --log-file=/gcsfuse-tmp/prom_kernel_reader.log"}
202+
testEnv.cfg.Configs[6].Compatible = map[string]bool{"flat": false, "hns": false, "zonal": true}
203+
testEnv.cfg.Configs[6].Run = "TestPromKernelReaderSuite"
200204
}
201205
testEnv.cfg = &configFile.Monitoring[0]
202206
testEnv.ctx = context.Background()

tools/integration_tests/test_config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,3 +882,11 @@ monitoring:
882882
zonal: true
883883
run: "TestPromGrpcMetricsSuite"
884884
run_on_gke: true
885+
- flags:
886+
- "--prometheus-port=9193 --log-file=/gcsfuse-tmp/prom_kernel_reader.log"
887+
compatible:
888+
flat: false
889+
hns: false
890+
zonal: true
891+
run: "TestPromKernelReaderSuite"
892+
run_on_gke: false

0 commit comments

Comments
 (0)