gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/metric/condmetric_profiling_disabled_test.go (about) 1 // Copyright 2022 The gVisor Authors. 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 //go:build !sentry_profiling 16 // +build !sentry_profiling 17 18 package metric 19 20 import ( 21 "testing" 22 23 pb "gvisor.dev/gvisor/pkg/metric/metric_go_proto" 24 ) 25 26 func TestProfilingMetricsDisabled(t *testing.T) { 27 defer resetTest() 28 29 _, err := SentryProfiling.NewUint64Metric("/counterM", false, pb.MetricMetadata_UNITS_NONE, "One uint64 metric") 30 if err != nil { 31 t.Fatalf("NewUint64Metric got err %v want nil", err) 32 } 33 34 bucketer := NewExponentialBucketer(3, 2, 0, 1) 35 _, err = SentryProfiling.NewDistributionMetric("/distribM", false, bucketer, pb.MetricMetadata_UNITS_NANOSECONDS, "One distribution metric") 36 if err != nil { 37 t.Fatalf("NewDistributionMetric got err %v want nil", err) 38 } 39 40 _, err = SentryProfiling.NewTimerMetric("/timerM", bucketer, "One timer metric") 41 if err != nil { 42 t.Fatalf("NewTimerMetric got err %v want nil", err) 43 } 44 45 if err := Initialize(); err != nil { 46 t.Fatalf("Initialize(): %s", err) 47 } 48 49 if len(emitter) != 1 { 50 t.Fatalf("Initialize emitted %d events want 1", len(emitter)) 51 } 52 53 mr, ok := emitter[0].(*pb.MetricRegistration) 54 if !ok { 55 t.Fatalf("emitter %v got %T want pb.MetricRegistration", emitter[0], emitter[0]) 56 } 57 58 if len(mr.Metrics) != 0 { 59 t.Errorf("MetricRegistration got %d metrics want %d", len(mr.Metrics), 0) 60 } 61 }