forked from openshift/machine-config-operator
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: Charlie Doern <cbddoern@gmail.com>
- Loading branch information
Showing
21 changed files
with
511 additions
and
17 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
17 changes: 17 additions & 0 deletions
17
install/0000_80-machine-config-operator_04_kube_rbac_proxy_config.yaml
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,17 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: kube-rbac-proxy | ||
namespace: openshift-machine-config-operator | ||
annotations: | ||
include.release.openshift.io/ibm-cloud-managed: "true" | ||
include.release.openshift.io/self-managed-high-availability: "true" | ||
include.release.openshift.io/single-node-developer: "true" | ||
data: | ||
config-file.yaml: |+ | ||
authorization: | ||
resourceAttributes: | ||
apiVersion: v1 | ||
resource: namespace | ||
subresource: metrics | ||
namespace: openshift-machine-config-operator |
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
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
36 changes: 36 additions & 0 deletions
36
install/0000_90_machine-config-operator_00_servicemonitor.yaml
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,50 @@ | ||
package operator | ||
|
||
import ( | ||
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const ( | ||
DefaultBindAddress = ":8797" | ||
) | ||
|
||
// MCO Metrics | ||
var ( | ||
// mcoState is the state of the machine config operator | ||
// pause, updated, updating, degraded | ||
mcoState = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "mco_state", | ||
Help: "state of a specified pool", | ||
}, []string{"pool", "state", "reason"}) | ||
// mcoMachineCount is the total number of nodes in the pool | ||
mcoMachineCount = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "mco_machine_count", | ||
Help: "total number of machines in a specified pool", | ||
}, []string{"pool"}) | ||
// mcoUpdatedMachineCount is the updated machines in the pool | ||
mcoUpdatedMachineCount = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "mco_updated_machine_count", | ||
Help: "total number of updated machines in specified pool", | ||
}, []string{"pool"}) | ||
// mcoDegradedMachineCount is the degraded machines in the pool | ||
mcoDegradedMachineCount = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "mco_degraded_machine_count", | ||
Help: "total number of degraded machines in specified pool", | ||
}, []string{"pool"}) | ||
// mcoUnavailableMachineCount is the degraded machines in the pool | ||
mcoUnavailableMachineCount = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "mco_unavailable_machine_count", | ||
Help: "total number of unavailable machines in specified pool", | ||
}, []string{"pool"}) | ||
) | ||
|
||
func RegisterMCOMetrics() error { | ||
return ctrlcommon.RegisterMetrics([]prometheus.Collector{mcoState, mcoMachineCount, mcoUpdatedMachineCount, mcoDegradedMachineCount, mcoUnavailableMachineCount}) | ||
} |
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,76 @@ | ||
package operator | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
fakeconfigclientset "github.com/openshift/client-go/config/clientset/versioned/fake" | ||
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" | ||
"github.com/openshift/machine-config-operator/test/helpers" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/uuid" | ||
corelisterv1 "k8s.io/client-go/listers/core/v1" | ||
"k8s.io/client-go/tools/cache" | ||
"k8s.io/client-go/tools/record" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
optr := &Operator{ | ||
eventRecorder: &record.FakeRecorder{}, | ||
} | ||
optr.vStore = newVersionStore() | ||
|
||
p1, p2 := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0"), helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0") | ||
p2.Status.MachineCount = 2 | ||
p2.Status.UpdatedMachineCount = 1 | ||
p2.Status.DegradedMachineCount = 1 | ||
optr.mcpLister = &mockMCPLister{ | ||
pools: []*mcfgv1.MachineConfigPool{p1, p2}, | ||
} | ||
|
||
nodeIndexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) | ||
optr.nodeLister = corelisterv1.NewNodeLister(nodeIndexer) | ||
nodeIndexer.Add(&corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "first-node", Labels: map[string]string{"node-role/worker": ""}}, | ||
Status: corev1.NodeStatus{ | ||
NodeInfo: corev1.NodeSystemInfo{ | ||
KubeletVersion: "v1.21", | ||
}, | ||
}, | ||
}) | ||
|
||
coName := fmt.Sprintf("test-%s", uuid.NewUUID()) | ||
co := &configv1.ClusterOperator{ObjectMeta: metav1.ObjectMeta{Name: coName}} | ||
optr.name = coName | ||
kasOperator := &configv1.ClusterOperator{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "kube-apiserver"}, | ||
Status: configv1.ClusterOperatorStatus{ | ||
Versions: []configv1.OperandVersion{ | ||
{Name: "kube-apiserver", Version: "1.21"}, | ||
}, | ||
}, | ||
} | ||
|
||
optr.configClient = fakeconfigclientset.NewSimpleClientset(co, kasOperator) | ||
err := optr.syncAll([]syncFunc{ | ||
{name: "fn1", | ||
fn: func(config *renderConfig) error { return nil }, | ||
}, | ||
}) | ||
require.Nil(t, err) | ||
|
||
metric := testutil.ToFloat64(mcoMachineCount.WithLabelValues("worker")) | ||
assert.Equal(t, metric, float64(2)) | ||
|
||
metric = testutil.ToFloat64(mcoUpdatedMachineCount.WithLabelValues("worker")) | ||
assert.Equal(t, metric, float64(1)) | ||
|
||
metric = testutil.ToFloat64(mcoDegradedMachineCount.WithLabelValues("worker")) | ||
assert.Equal(t, metric, float64(1)) | ||
|
||
} |
Oops, something went wrong.