Skip to content

Commit

Permalink
Add headers and small fixes
Browse files Browse the repository at this point in the history
Signed-off-by: machadovilaca <machadovilaca@gmail.com>
  • Loading branch information
machadovilaca committed Mar 26, 2024
1 parent 42e9790 commit 6ba8a83
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
24 changes: 18 additions & 6 deletions tests/libmonitoring/metric_matcher.go
@@ -1,3 +1,19 @@
/*
Copyright The KubeVirt 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 libmonitoring

import (
Expand All @@ -9,7 +25,7 @@ import (

const (
prometheusMetricNameLabel = "__name__"
prometheusHistogramBucketPrefix = "_bucket"
prometheusHistogramBucketSuffix = "_bucket"
)

type MetricMatcher struct {
Expand Down Expand Up @@ -50,17 +66,13 @@ func (matcher *MetricMatcher) Match(actual interface{}) (success bool, err error

nameToMatch := matcher.Metric.GetOpts().Name
if matcher.Metric.GetType() == operatormetrics.HistogramType || matcher.Metric.GetType() == operatormetrics.HistogramVecType {
nameToMatch = nameToMatch + prometheusHistogramBucketPrefix
nameToMatch = nameToMatch + prometheusHistogramBucketSuffix
}

if actualName != nameToMatch {
return false, nil
}

if matcher.Labels == nil {
return true, nil
}

for k, v := range matcher.Labels {
actualValue, ok := actualMetric.Metric[k]
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion tests/libmonitoring/prometheus.go
Expand Up @@ -79,7 +79,7 @@ func WaitForMetricValueWithLabels(client kubecli.KubevirtClient, metric string,
return -1
}
return i
}, 5*time.Minute, 1*time.Second).Should(BeNumerically("==", expectedValue))
}, 3*time.Minute, 1*time.Second).Should(BeNumerically("==", expectedValue))
}

func GetMetricValueWithLabels(cli kubecli.KubevirtClient, query string, labels map[string]string) (float64, error) {
Expand Down
19 changes: 17 additions & 2 deletions tests/monitoring/metrics.go
@@ -1,3 +1,19 @@
/*
Copyright The KubeVirt 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 monitoring

import (
Expand Down Expand Up @@ -29,7 +45,6 @@ import (
)

var _ = Describe("[sig-monitoring]Metrics", decorators.SigMonitoring, func() {
var err error
var virtClient kubecli.KubevirtClient
var metrics *libmonitoring.QueryRequestResult

Expand Down Expand Up @@ -61,7 +76,7 @@ var _ = Describe("[sig-monitoring]Metrics", decorators.SigMonitoring, func() {
It("should contain virt components metrics", func() {
metrics = fetchPrometheusMetrics(virtClient)

err = virtoperator.SetupMetrics()
err := virtoperator.SetupMetrics()
Expect(err).ToNot(HaveOccurred())

err = virtapi.SetupMetrics()
Expand Down

0 comments on commit 6ba8a83

Please sign in to comment.