-
Notifications
You must be signed in to change notification settings - Fork 40.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57346 from tallclair/psp-metrics-alt
Automatic merge from submit-queue. Temporary implementation of count metrics for PodSecurityPolicy **What this PR does / why we need it**: Alternative proposal to #57173 > We need rejection counts in order to turn on the PodSecurityPolicy controller. Comprehensive metrics were added for all admission controllers in 1.9, but backporting all those metrics was deemed to risky. So instead, this PR only enables the metrics on the PodSecurityPolicy controller. **Which issue(s) this PR fixes**: Fixes #55030 **Special notes for your reviewer**: Most of the diff is tests & boiler plate. Most prod code changes are contained in metrics.go, with a small hook in admission.go. This deviates from the metrics in HEAD, but some amount of drift between 1.8 and 1.9 is inevitable, due to the admission refactorings that went into 1.9. **Release note**: ```release-note Add prometheus metrics for the PodSecurityPolicy admission controller ```
- Loading branch information
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
plugin/pkg/admission/security/podsecuritypolicy/metrics.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package podsecuritypolicy | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"k8s.io/apiserver/pkg/admission" | ||
) | ||
|
||
const ( | ||
namespace = "apiserver" | ||
subsystem = "admission" | ||
) | ||
|
||
var ( | ||
admitCounter = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "controller_admission_latencies_seconds_count", | ||
Help: "Admission controller counts, identified by name and broken out for each operation and API resource and type (validate or admit).", | ||
}, | ||
[]string{"name", "type", "operation", "group", "version", "resource", "subresource", "rejected"}, | ||
) | ||
) | ||
|
||
func init() { | ||
prometheus.MustRegister(admitCounter) | ||
} | ||
|
||
func ObserveAdmit(rejected bool, attr admission.Attributes) { | ||
gvr := attr.GetResource() | ||
labels := []string{PluginName, "admit", string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected)} | ||
admitCounter.WithLabelValues(labels...).Inc() | ||
} |