k8s.io/perf-tests/clusterloader2@v0.0.0-20240304094227-64bdb12da87e/pkg/measurement/common/cilium_endpoint_propagation_delay_test.go (about) 1 /* 2 Copyright 2022 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package common 18 19 import ( 20 "fmt" 21 "testing" 22 "time" 23 24 "github.com/stretchr/testify/assert" 25 26 "k8s.io/perf-tests/clusterloader2/pkg/measurement" 27 "k8s.io/perf-tests/clusterloader2/pkg/measurement/common/executors" 28 ) 29 30 func TestCiliumEndpointPropagationDelayMeasurement(t *testing.T) { 31 cases := []struct { 32 name string 33 config *measurement.Config 34 hasError bool 35 testSeriesFile string 36 testSeriesDuration time.Duration 37 }{ 38 { 39 name: "default_slo_pass", 40 hasError: false, 41 testSeriesFile: "default_slo_pass.yaml", 42 testSeriesDuration: 100 * time.Minute, 43 config: &measurement.Config{ 44 Params: map[string]interface{}{}, 45 }, 46 }, 47 { 48 name: "default_slo_fail", 49 hasError: true, 50 testSeriesFile: "default_slo_fail.yaml", 51 testSeriesDuration: 100 * time.Minute, 52 config: &measurement.Config{ 53 Params: map[string]interface{}{}, 54 }, 55 }, 56 { 57 name: "custom_slo_pass", 58 hasError: false, 59 testSeriesFile: "default_slo_pass.yaml", 60 testSeriesDuration: 100 * time.Minute, 61 config: &measurement.Config{ 62 Params: map[string]interface{}{ 63 "bucketSLO": float64(600), 64 "percentileSLO": float64(99), 65 }, 66 }, 67 }, 68 { 69 name: "custom_slo_fail", 70 hasError: true, 71 testSeriesFile: "default_slo_fail.yaml", 72 testSeriesDuration: 100 * time.Minute, 73 config: &measurement.Config{ 74 Params: map[string]interface{}{ 75 "bucketSLO": float64(1), 76 "percentileSLO": float64(99), 77 }, 78 }, 79 }, 80 } 81 82 for _, tc := range cases { 83 t.Run(tc.name, func(t *testing.T) { 84 executor, err := executors.NewPromqlExecutor(fmt.Sprintf("testdata/cilium_endpoint_propagation_delay/%s", tc.testSeriesFile)) 85 if err != nil { 86 t.Fatalf("failed to create PromQL executor: %v", err) 87 } 88 defer executor.Close() 89 gatherer := &cepPropagationDelayGatherer{} 90 start := time.Unix(0, 0).UTC() 91 end := start.Add(tc.testSeriesDuration) 92 _, err = gatherer.Gather(executor, start, end, tc.config) 93 if tc.hasError { 94 assert.NotNil(t, err, "Wanted error, but got none") 95 } else { 96 assert.Nil(t, err, "Wanted no error, but got %v", err) 97 } 98 }) 99 } 100 }