istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/config/analysis/analyzers/telemetry/providers.go (about) 1 // Copyright Istio 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 package telemetry 16 17 import ( 18 telemetryapi "istio.io/api/telemetry/v1alpha1" 19 "istio.io/istio/pkg/config" 20 "istio.io/istio/pkg/config/analysis" 21 "istio.io/istio/pkg/config/analysis/msg" 22 "istio.io/istio/pkg/config/resource" 23 "istio.io/istio/pkg/config/schema/gvk" 24 ) 25 26 type ProdiverAnalyzer struct{} 27 28 var _ analysis.Analyzer = &ProdiverAnalyzer{} 29 30 // Metadata implements Analyzer 31 func (a *ProdiverAnalyzer) Metadata() analysis.Metadata { 32 return analysis.Metadata{ 33 Name: "telemetry.ProviderAnalyzer", 34 Description: "Validates that providers in telemetry resource is valid", 35 Inputs: []config.GroupVersionKind{ 36 gvk.Telemetry, 37 gvk.MeshConfig, 38 }, 39 } 40 } 41 42 // Analyze implements Analyzer 43 func (a *ProdiverAnalyzer) Analyze(c analysis.Context) { 44 meshConfig := fetchMeshConfig(c) 45 if meshConfig.DefaultProviders == nil || 46 len(meshConfig.DefaultProviders.AccessLogging) == 0 { 47 c.ForEach(gvk.Telemetry, func(r *resource.Instance) bool { 48 telemetry := r.Message.(*telemetryapi.Telemetry) 49 50 for _, l := range telemetry.AccessLogging { 51 if l.Disabled != nil && l.Disabled.Value { 52 continue 53 } 54 if len(l.Providers) == 0 { 55 c.Report(gvk.Telemetry, 56 msg.NewInvalidTelemetryProvider(r, string(r.Metadata.FullName.Name), string(r.Metadata.FullName.Namespace))) 57 } 58 } 59 60 return true 61 }) 62 } 63 }