-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: assaf-admi <[email protected]>
- Loading branch information
Showing
32 changed files
with
2,667 additions
and
1,555 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
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,72 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Copyright 2022 Red Hat, Inc. | ||
# | ||
# 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. | ||
|
||
set -e | ||
|
||
linter_image_tag="v0.0.2" | ||
|
||
PROJECT_ROOT="$(readlink -e "$(dirname "${BASH_SOURCE[0]}")"/../)" | ||
export METRICS_COLLECTOR_PATH="${METRICS_COLLECTOR_PATH:-${PROJECT_ROOT}/tools/prom-metrics-collector}" | ||
|
||
if [[ ! -d "$METRICS_COLLECTOR_PATH" ]]; then | ||
echo "Invalid METRICS_COLLECTOR_PATH: $METRICS_COLLECTOR_PATH is not a valid directory path" | ||
exit 1 | ||
fi | ||
|
||
# Parse command-line arguments | ||
while [[ $# -gt 0 ]]; do | ||
case "$1" in | ||
--operator-name=*) | ||
operator_name="${1#*=}" | ||
shift | ||
;; | ||
--sub-operator-name=*) | ||
sub_operator_name="${1#*=}" | ||
shift | ||
;; | ||
*) | ||
echo "Invalid argument: $1" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# Get the metrics list | ||
go build -o _out/prom-metrics-collector "$METRICS_COLLECTOR_PATH/..." | ||
json_output=$(_out/prom-metrics-collector 2>/dev/null) | ||
|
||
# Select container runtime | ||
source "${PROJECT_ROOT}"/hack/config.sh | ||
|
||
# Check if runs as part of Openshift-ci. If so, run directly | ||
if [[ "${OPENSHIFT_CI}" == "true" ]]; then | ||
errors=$(/usr/bin/prom-metrics-linter \ | ||
--metric-families="$json_output" \ | ||
--operator-name="$operator_name" \ | ||
--sub-operator-name="$sub_operator_name" 2>/dev/null) | ||
# Else, run in a container, using the linter image | ||
else | ||
errors=$($KUBEVIRT_CRI run -i "quay.io/kubevirt/prom-metrics-linter:$linter_image_tag" \ | ||
--metric-families="$json_output" \ | ||
--operator-name="$operator_name" \ | ||
--sub-operator-name="$sub_operator_name" 2>/dev/null) | ||
fi | ||
|
||
# Check if there were any errors, if yes print and fail | ||
if [[ $errors != "" ]]; then | ||
echo "$errors" | ||
exit 1 | ||
fi |
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,37 @@ | ||
package main | ||
|
||
import ( | ||
parser "github.com/kubevirt/monitoring/pkg/metrics/parser" | ||
"kubevirt.io/ssp-operator/internal/operands/metrics" | ||
|
||
dto "github.com/prometheus/client_model/go" | ||
) | ||
|
||
// excludedMetrics defines the metrics to ignore. | ||
// open bug: https://bugzilla.redhat.com/show_bug.cgi?id=2219763 | ||
// Do not add metrics to this list! | ||
var excludedMetrics = map[string]struct{}{ | ||
"kubevirt_ssp_operator_up_total": {}, | ||
"kubevirt_ssp_template_validator_up_total": {}, | ||
"ssp_operator_reconciling_properly": {}, | ||
"total_rejected_vms": {}, | ||
"total_restored_common_templates": {}, | ||
} | ||
|
||
func readMetrics() []*dto.MetricFamily { | ||
var metricFamilies []*dto.MetricFamily | ||
sspMetrics := metrics.RecordRulesDescList | ||
|
||
for _, metric := range sspMetrics { | ||
if _, isExcludedMetric := excludedMetrics[metric.Name]; !isExcludedMetric { | ||
mf := parser.CreateMetricFamily(parser.Metric{ | ||
Name: metric.Name, | ||
Help: metric.Description, | ||
Type: metric.Type, | ||
}) | ||
metricFamilies = append(metricFamilies, mf) | ||
} | ||
} | ||
|
||
return metricFamilies | ||
} |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func main() { | ||
metricFamilies := readMetrics() | ||
|
||
jsonBytes, err := json.Marshal(metricFamilies) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(string(jsonBytes)) | ||
} |
52 changes: 52 additions & 0 deletions
52
vendor/github.com/kubevirt/monitoring/pkg/metrics/parser/metrics_parser.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.