|
| 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 | +} |
0 commit comments