-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch upstream/main into add-metrics
- Loading branch information
Showing
12 changed files
with
322 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ | |
.idea/ | ||
coverage.txt | ||
k8s-image-swapper | ||
__debug_bin | ||
.vscode/launch.json |
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
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,20 @@ | ||
## Metrics | ||
|
||
The following metrics are available to be scraped by Prometheus on traffic port and `/metrics` path | ||
|
||
| Metric Name | Meaning | | ||
| ----------- | ----------- | | ||
go_* | Standard Go instrumentation metrics | ||
process_* | Standard Go instrumentation metrics | ||
promhttp_metric_handler_requests_in_flight | Amount of parallel requests in flight | ||
promhttp_metric_handler_requests_total | Total count of metric requests (scrapes) | ||
kubewebhook_mutating_webhook_review_duration_seconds | Webhook duration, in buckets for percentiles | ||
kubewebhook_webhook_review_warnings_total | Webhook warnings | ||
k8s_image_swapper_ecr_errors | Number of errors related to ecr provider | ||
k8s_image_swapper_main_errors | Number of errors | ||
k8s_image_swapper_cache_hits | Number of registry cache hits | ||
k8s_image_swapper_cache_misses | Number of registry cache misses | ||
k8s_image_swapper_cache_filtered | Number of registry cache filtered out | ||
k8s_image_swapper_cache_image_copy_duration_seconds | Copy duration distribution and count | ||
k8s_image_swapper_cache_repos_create_requests | Number of repositories creation requests | ||
k8s_image_swapper_cache_repos_created | Number of repositories created |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
/* | ||
Copyright © 2020 Enrico Stahn <enrico.stahn@gmail.com> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
package metrics | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/collectors" | ||
) | ||
|
||
var ( | ||
commonRepoLabels = []string{"resource_namespace", "registry", "repo"} | ||
|
||
errors = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: "k8s_image_swapper", | ||
Subsystem: "main", | ||
Name: "errors", | ||
Help: "Number of errors", | ||
}, | ||
[]string{"error_type"}, | ||
) | ||
ecrErrors = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: "k8s_image_swapper", | ||
Subsystem: "ecr", | ||
Name: "errors", | ||
Help: "Number of ecr errors", | ||
}, | ||
append(commonRepoLabels, "error_type"), | ||
) | ||
|
||
cacheHits = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: "k8s_image_swapper", | ||
Subsystem: "cache", | ||
Name: "hits", | ||
Help: "Number of registry cache hits", | ||
}, | ||
commonRepoLabels, | ||
) | ||
|
||
cacheMisses = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: "k8s_image_swapper", | ||
Subsystem: "cache", | ||
Name: "misses", | ||
Help: "Number of registry cache misses", | ||
}, | ||
commonRepoLabels, | ||
) | ||
cacheFiltered = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: "k8s_image_swapper", | ||
Subsystem: "cache", | ||
Name: "filtered", | ||
Help: "Number of registry cache filtered out", | ||
}, | ||
commonRepoLabels, | ||
) | ||
|
||
imageCopyDuration = prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Namespace: "k8s_image_swapper", | ||
Subsystem: "cache", | ||
Name: "image_copy_duration_seconds", | ||
Help: "Image copy duration distribution in seconds", | ||
Buckets: prometheus.ExponentialBuckets(4, 2, 10), | ||
}, | ||
commonRepoLabels, | ||
) | ||
|
||
reposCreateRequests = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: "k8s_image_swapper", | ||
Subsystem: "cache", | ||
Name: "repos_create_requests", | ||
Help: "Number of repository create requests", | ||
}, | ||
commonRepoLabels, | ||
) | ||
reposCreated = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Subsystem: "cache", | ||
Name: "repos_created", | ||
Help: "Number of repositories created", | ||
}, | ||
[]string{"registry", "repo"}, | ||
) | ||
) | ||
|
||
var PromReg *prometheus.Registry | ||
|
||
func init() { | ||
PromReg = prometheus.NewRegistry() | ||
PromReg.MustRegister(collectors.NewGoCollector()) | ||
PromReg.MustRegister(errors) | ||
PromReg.MustRegister(ecrErrors) | ||
PromReg.MustRegister(cacheHits) | ||
PromReg.MustRegister(cacheMisses) | ||
PromReg.MustRegister(cacheFiltered) | ||
PromReg.MustRegister(imageCopyDuration) | ||
PromReg.MustRegister(reposCreateRequests) | ||
PromReg.MustRegister(reposCreated) | ||
} | ||
|
||
// Increments the counter of errors | ||
func IncrementError(errType string) { | ||
errors.With( | ||
prometheus.Labels{ | ||
"error_type": errType, | ||
}, | ||
).Inc() | ||
} | ||
|
||
// Increments the counter of ecr errors | ||
func IncrementEcrError(resource_namespace string, registry string, repo string, errType string) { | ||
ecrErrors.With( | ||
prometheus.Labels{ | ||
"resource_namespace": resource_namespace, | ||
"registry": registry, | ||
"repo": repo, | ||
"error_type": errType, | ||
}, | ||
).Inc() | ||
} | ||
|
||
// Increments the counter of registry cache hits | ||
func IncrementCacheHits(resource_namespace string, registry string, repo string) { | ||
cacheHits.With( | ||
prometheus.Labels{ | ||
"resource_namespace": resource_namespace, | ||
"registry": registry, | ||
"repo": repo, | ||
}, | ||
).Inc() | ||
} | ||
|
||
// Increments the counter of registry cache misses | ||
func IncrementCacheMisses(resource_namespace string, registry string, repo string) { | ||
cacheMisses.With( | ||
prometheus.Labels{ | ||
"resource_namespace": resource_namespace, | ||
"registry": registry, | ||
"repo": repo, | ||
}, | ||
).Inc() | ||
} | ||
|
||
// Increments the counter of registry cache ignored/filtered out | ||
func IncrementCacheFiltered(resource_namespace string, registry string, repo string) { | ||
cacheFiltered.With( | ||
prometheus.Labels{ | ||
"resource_namespace": resource_namespace, | ||
"registry": registry, | ||
"repo": repo, | ||
}, | ||
).Inc() | ||
} | ||
|
||
// Sets the duration of image copy operation | ||
func SetImageCopyDuration(resource_namespace string, registry string, repo string, duration float64) { | ||
imageCopyDuration.With( | ||
prometheus.Labels{ | ||
"resource_namespace": resource_namespace, | ||
"registry": registry, | ||
"repo": repo, | ||
}, | ||
).Observe(duration) | ||
} | ||
|
||
// Increments the counter of repo create requests | ||
func IncrementReposCreateRequests(resource_namespace string, registry string, repo string) { | ||
reposCreateRequests.With( | ||
prometheus.Labels{ | ||
"resource_namespace": resource_namespace, | ||
"registry": registry, | ||
"repo": repo, | ||
}, | ||
).Inc() | ||
} | ||
|
||
// Increments the counter of repos created | ||
func IncrementReposCreated(registry string, repo string) { | ||
reposCreated.With( | ||
prometheus.Labels{ | ||
"registry": registry, | ||
"repo": repo, | ||
}, | ||
).Inc() | ||
} |
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
Oops, something went wrong.