istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/telemetry/api/setup_test.go (about) 1 //go:build integ 2 // +build integ 3 4 // Copyright Istio Authors. All Rights Reserved. 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 18 package api 19 20 import ( 21 "encoding/base64" 22 "fmt" 23 "testing" 24 25 "istio.io/api/annotation" 26 "istio.io/istio/pkg/test/echo/common" 27 "istio.io/istio/pkg/test/framework" 28 "istio.io/istio/pkg/test/framework/components/echo" 29 cdeployment "istio.io/istio/pkg/test/framework/components/echo/common/deployment" 30 "istio.io/istio/pkg/test/framework/components/echo/match" 31 "istio.io/istio/pkg/test/framework/components/istio" 32 "istio.io/istio/pkg/test/framework/components/istio/ingress" 33 "istio.io/istio/pkg/test/framework/components/prometheus" 34 "istio.io/istio/pkg/test/framework/label" 35 "istio.io/istio/pkg/test/framework/resource" 36 "istio.io/istio/pkg/test/framework/resource/config/apply" 37 ) 38 39 const ( 40 DefaultBucketCount = 20 41 ) 42 43 var ( 44 apps cdeployment.SingleNamespaceView 45 46 mockProm echo.Instances 47 ist istio.Instance 48 promInst prometheus.Instance 49 ingr []ingress.Instance 50 ) 51 52 func TestMain(m *testing.M) { 53 framework.NewSuite(m). 54 Label(label.CustomSetup). 55 // TODO: Remove this restriction once we validate our prometheus helm chart version is high enough 56 Label(label.IPv4). // https://github.com/istio/istio/issues/35915 57 Setup(istio.Setup(&ist, setupConfig)). 58 Setup(func(ctx resource.Context) error { 59 i, err := istio.Get(ctx) 60 if err != nil { 61 return err 62 } 63 return ctx.ConfigIstio().YAML(i.Settings().SystemNamespace, ` 64 apiVersion: telemetry.istio.io/v1alpha1 65 kind: Telemetry 66 metadata: 67 name: mesh-default 68 spec: 69 metrics: 70 - providers: 71 - name: prometheus 72 `).Apply() 73 }). 74 Setup(testRegistrySetup). 75 Setup(SetupSuite). 76 Run() 77 } 78 79 func setupConfig(_ resource.Context, cfg *istio.Config) { 80 if cfg == nil { 81 return 82 } 83 cfg.ControlPlaneValues = ` 84 meshConfig: 85 accessLogFile: "" # disable from install, we will enable via Telemetry layer 86 ` 87 cfg.RemoteClusterValues = cfg.ControlPlaneValues 88 cfg.Values["global.logging.level"] = "xdsproxy:debug,wasm:debug" 89 } 90 91 // SetupSuite set up echo app for stats testing. 92 func SetupSuite(ctx resource.Context) (err error) { 93 echos := (&cdeployment.Config{}).DefaultEchoConfigs(ctx) 94 customBuckets := `{"istio":[1,5,10,50,100,500,1000,5000,10000]}` 95 proxyMetadata := fmt.Sprintf(` 96 proxyMetadata: 97 WASM_INSECURE_REGISTRIES: %q`, registry.Address()) 98 for _, e := range echos { 99 if e.Subsets[0].Annotations == nil { 100 e.Subsets[0].Annotations = map[string]string{} 101 } 102 if e.Service == "b" { 103 e.Subsets[0].Annotations[annotation.SidecarStatsHistogramBuckets.Name] = customBuckets 104 } 105 e.Subsets[0].Annotations[annotation.ProxyConfig.Name] = proxyMetadata 106 } 107 108 proxyMd := `{"proxyMetadata": {"OUTPUT_CERTS": "/etc/certs/custom"}}` 109 prom := echo.Config{ 110 // mock prom instance is used to mock a prometheus server, which will visit other echo instance /metrics 111 // endpoint with proxy provisioned certs. 112 Service: "mock-prom", 113 Subsets: []echo.SubsetConfig{ 114 { 115 Annotations: map[string]string{ 116 annotation.SidecarTrafficIncludeInboundPorts.Name: "", 117 annotation.SidecarTrafficIncludeOutboundIPRanges.Name: "", 118 annotation.ProxyConfig.Name: proxyMd, 119 annotation.SidecarUserVolumeMount.Name: `[{"name": "custom-certs", "mountPath": "/etc/certs/custom"}]`, 120 }, 121 }, 122 }, 123 TLSSettings: &common.TLSSettings{ 124 ProxyProvision: true, 125 }, 126 Ports: []echo.Port{}, 127 } 128 echos = append(echos, prom) 129 130 if err := cdeployment.SetupSingleNamespace(&apps, cdeployment.Config{Configs: echo.ConfigFuture(&echos)})(ctx); err != nil { 131 return err 132 } 133 134 if err != nil { 135 return err 136 } 137 for _, c := range ctx.Clusters() { 138 ingr = append(ingr, ist.IngressFor(c)) 139 } 140 mockProm = match.ServiceName(echo.NamespacedName{Name: "mock-prom", Namespace: apps.Namespace}).GetMatches(apps.Echos().All.Instances()) 141 promInst, err = prometheus.New(ctx, prometheus.Config{}) 142 if err != nil { 143 return 144 } 145 146 args := map[string]any{ 147 "DockerConfigJson": base64.StdEncoding.EncodeToString( 148 []byte(createDockerCredential(registryUser, registryPasswd, registry.Address()))), 149 } 150 if err := ctx.ConfigIstio().EvalFile(apps.Namespace.Name(), args, "testdata/registry-secret.yaml"). 151 Apply(apply.CleanupConditionally); err != nil { 152 return err 153 } 154 return nil 155 }