forked from red-hat-storage/odf-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controllers: report StorageSystem metrics
transforming StorageSystem spec into metrics so that we can use Prometheus queries to understand object relationships. Signed-off-by: Umanga Chapagain <[email protected]>
- Loading branch information
1 parent
39593e9
commit 735d38e
Showing
3 changed files
with
115 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2021 Red Hat OpenShift Data Foundation. | ||
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 metrics | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics" | ||
) | ||
|
||
var ( | ||
storageSystemMap = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: "odf", | ||
Subsystem: "", | ||
Name: "system_map", | ||
Help: "Map of ODF StorageSystems to their target Custom Resource", | ||
}, []string{"storage_system", "target_name", "target_namespace", "target_kind"}) | ||
) | ||
|
||
func init() { | ||
metrics.Registry.MustRegister(storageSystemMap) | ||
} | ||
|
||
func ReportODFSystemMapMetrics(storageSystem, name, namespace, kind string) { | ||
storageSystemMap.With(prometheus.Labels{ | ||
"storage_system": storageSystem, | ||
"target_name": name, | ||
"target_namespace": namespace, | ||
"target_kind": kind, | ||
}).Set(1) | ||
} |
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,68 @@ | ||
/* | ||
Copyright 2021 Red Hat OpenShift Data Foundation. | ||
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 metrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics" | ||
) | ||
|
||
var defaultRegistry = metrics.Registry | ||
var find string = "odf_system_map" | ||
|
||
func TestReportODFSystemMapMetrics(t *testing.T) { | ||
type args struct { | ||
storageSystem, name, namespace, kind string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "StorageSystem to StorageCluster", | ||
args: args{ | ||
storageSystem: "StorageSystem1", | ||
name: "StorageCluster1", | ||
namespace: "Namespace1", | ||
kind: "StorageCluster", | ||
}, | ||
}, | ||
{ | ||
name: "StorageSystem to Flashsystem", | ||
args: args{ | ||
storageSystem: "StorageSystem2", | ||
name: "FlashSystem1", | ||
namespace: "Namespace1", | ||
kind: "Flashsystem", | ||
}, | ||
}, | ||
} | ||
for n, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ReportODFSystemMapMetrics(tt.args.storageSystem, tt.args.name, tt.args.namespace, tt.args.kind) | ||
count, err := testutil.GatherAndCount(defaultRegistry, find) | ||
assert.NoError(t, err) | ||
assert.Equal(t, n+1, count) | ||
problems, err := testutil.GatherAndLint(defaultRegistry, find) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, len(problems)) | ||
}) | ||
} | ||
} |