istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/webhooks/validation/server/monitoring.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 server 16 17 import ( 18 "strconv" 19 20 "istio.io/istio/pkg/kube" 21 "istio.io/istio/pkg/monitoring" 22 ) 23 24 const ( 25 group = "group" 26 version = "version" 27 resourceTag = "resource" 28 reason = "reason" 29 status = "status" 30 ) 31 32 var ( 33 // GroupTag holds the resource group for the context. 34 GroupTag = monitoring.CreateLabel(group) 35 36 // VersionTag holds the resource version for the context. 37 VersionTag = monitoring.CreateLabel(version) 38 39 // ResourceTag holds the resource name for the context. 40 ResourceTag = monitoring.CreateLabel(resourceTag) 41 42 // ReasonTag holds the error reason for the context. 43 ReasonTag = monitoring.CreateLabel(reason) 44 45 // StatusTag holds the error code for the context. 46 StatusTag = monitoring.CreateLabel(status) 47 ) 48 49 var ( 50 metricValidationPassed = monitoring.NewSum( 51 "galley_validation_passed", 52 "Resource is valid", 53 ) 54 metricValidationFailed = monitoring.NewSum( 55 "galley_validation_failed", 56 "Resource validation failed", 57 ) 58 metricValidationHTTPError = monitoring.NewSum( 59 "galley_validation_http_error", 60 "Resource validation http serve errors", 61 ) 62 ) 63 64 func reportValidationFailed(request *kube.AdmissionRequest, reason string, dryRun bool) { 65 if dryRun { 66 return 67 } 68 metricValidationFailed. 69 With(GroupTag.Value(request.Resource.Group)). 70 With(VersionTag.Value(request.Resource.Version)). 71 With(ResourceTag.Value(request.Resource.Resource)). 72 With(ReasonTag.Value(reason)). 73 Increment() 74 } 75 76 func reportValidationPass(request *kube.AdmissionRequest) { 77 metricValidationPassed. 78 With(GroupTag.Value(request.Resource.Group)). 79 With(VersionTag.Value(request.Resource.Version)). 80 With(ResourceTag.Value(request.Resource.Resource)). 81 Increment() 82 } 83 84 func reportValidationHTTPError(status int) { 85 metricValidationHTTPError. 86 With(StatusTag.Value(strconv.Itoa(status))). 87 Increment() 88 } 89 90 const ( 91 reasonUnsupportedOperation = "unsupported_operation" 92 reasonYamlDecodeError = "yaml_decode_error" 93 reasonUnknownType = "unknown_type" 94 reasonCRDConversionError = "crd_conversion_error" 95 reasonInvalidConfig = "invalid_resource" 96 )