-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a /metrics endpoint on the OLM container that exposes counts for various OLM specific resources, which currently are: CSVs InstallPlans Subscriptions CatalogSources And also a count for CSV upgrades. Some of the e2e code (getMetricsFromPod) was copied from the kubernetes e2e metrics framework.
- Loading branch information
Jeff Peeler
committed
Sep 18, 2018
1 parent
248ac74
commit 2c4f3bf
Showing
9 changed files
with
224 additions
and
9 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
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,140 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" | ||
"github.com/prometheus/client_golang/prometheus" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type MetricsProvider interface { | ||
HandleMetrics() error | ||
} | ||
|
||
type metricsCSV struct { | ||
opClient operatorclient.ClientInterface | ||
} | ||
|
||
func NewMetricsCSV(opClient operatorclient.ClientInterface) MetricsProvider { | ||
return &metricsCSV{opClient} | ||
} | ||
|
||
func (m *metricsCSV) HandleMetrics() error { | ||
cList, err := m.opClient.ListCustomResource(v1alpha1.GroupName, v1alpha1.GroupVersion, metav1.NamespaceAll, v1alpha1.ClusterServiceVersionKind) | ||
if err != nil { | ||
return err | ||
} | ||
csvCount.Set(float64(len(cList.Items))) | ||
return nil | ||
} | ||
|
||
type metricsInstallPlan struct { | ||
opClient operatorclient.ClientInterface | ||
} | ||
|
||
func NewMetricsInstallPlan(opClient operatorclient.ClientInterface) MetricsProvider { | ||
return &metricsInstallPlan{opClient} | ||
} | ||
|
||
func (m *metricsInstallPlan) HandleMetrics() error { | ||
cList, err := m.opClient.ListCustomResource(v1alpha1.GroupName, v1alpha1.GroupVersion, metav1.NamespaceAll, v1alpha1.InstallPlanKind) | ||
if err != nil { | ||
return err | ||
} | ||
installPlanCount.Set(float64(len(cList.Items))) | ||
return nil | ||
} | ||
|
||
type metricsSubscription struct { | ||
opClient operatorclient.ClientInterface | ||
} | ||
|
||
func NewMetricsSubscription(opClient operatorclient.ClientInterface) MetricsProvider { | ||
return &metricsSubscription{opClient} | ||
} | ||
|
||
func (m *metricsSubscription) HandleMetrics() error { | ||
cList, err := m.opClient.ListCustomResource(v1alpha1.GroupName, v1alpha1.GroupVersion, metav1.NamespaceAll, v1alpha1.SubscriptionKind) | ||
if err != nil { | ||
return err | ||
} | ||
subscriptionCount.Set(float64(len(cList.Items))) | ||
return nil | ||
} | ||
|
||
type metricsCatalogSource struct { | ||
opClient operatorclient.ClientInterface | ||
} | ||
|
||
func NewMetricsCatalogSource(opClient operatorclient.ClientInterface) MetricsProvider { | ||
return &metricsCatalogSource{opClient} | ||
|
||
} | ||
|
||
func (m *metricsCatalogSource) HandleMetrics() error { | ||
cList, err := m.opClient.ListCustomResource(v1alpha1.GroupName, v1alpha1.GroupVersion, metav1.NamespaceAll, v1alpha1.CatalogSourceKind) | ||
if err != nil { | ||
return err | ||
} | ||
catalogSourceCount.Set(float64(len(cList.Items))) | ||
return nil | ||
} | ||
|
||
type MetricsNil struct{} | ||
|
||
func NewMetricsNil() MetricsProvider { | ||
return &MetricsNil{} | ||
} | ||
|
||
func (*MetricsNil) HandleMetrics() error { | ||
return nil | ||
} | ||
|
||
// To add new metrics: | ||
// 1. Register new metrics in Register() below. | ||
// 2. Add appropriate metric updates in HandleMetrics (or elsewhere instead). | ||
var ( | ||
csvCount = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "csv_count", | ||
Help: "Number of CSVs successfully registered", | ||
}, | ||
) | ||
|
||
installPlanCount = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "install_plan_count", | ||
Help: "Number of install plans", | ||
}, | ||
) | ||
|
||
subscriptionCount = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "subscription_count", | ||
Help: "Number of subscriptions", | ||
}, | ||
) | ||
|
||
catalogSourceCount = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "catalog_source_count", | ||
Help: "Number of catalog sources", | ||
}, | ||
) | ||
|
||
// exported since it's not handled by HandleMetrics | ||
CSVUpgradeCount = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "csv_upgrade_count", | ||
Help: "Monotonic count of catalog sources", | ||
}, | ||
) | ||
) | ||
|
||
func Register() { | ||
prometheus.MustRegister(csvCount) | ||
prometheus.MustRegister(installPlanCount) | ||
prometheus.MustRegister(subscriptionCount) | ||
prometheus.MustRegister(catalogSourceCount) | ||
prometheus.MustRegister(CSVUpgradeCount) | ||
} |
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,48 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" | ||
log "github.com/sirupsen/logrus" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// TestMetrics tests the metrics endpoint of the OLM pod. | ||
func TestMetricsEndpoint(t *testing.T) { | ||
c := newKubeClient(t) | ||
|
||
listOptions := metav1.ListOptions{LabelSelector: "app=olm-operator"} | ||
podList, err := c.KubernetesInterface().CoreV1().Pods(e2eNamespace).List(listOptions) | ||
if err != nil { | ||
log.Infof("Error %v\n", err) | ||
t.Fatalf("Listing pods failed: %v\n", err) | ||
} | ||
if len(podList.Items) > 1 { | ||
t.Fatalf("Expected only 1 olm-operator pod, got %v", len(podList.Items)) | ||
} | ||
|
||
podName := podList.Items[0].GetName() | ||
|
||
rawOutput, err := getMetricsFromPod(t, c, podName, e2eNamespace, 8080) | ||
if err != nil { | ||
t.Fatalf("Metrics test failed: %v\n", err) | ||
} | ||
|
||
log.Debugf("Metrics:\n%v", rawOutput) | ||
} | ||
|
||
func getMetricsFromPod(t *testing.T, client operatorclient.ClientInterface, podName string, namespace string, port int) (string, error) { | ||
rawOutput, err := client.KubernetesInterface().CoreV1().RESTClient().Get(). | ||
Namespace(namespace). | ||
Resource("pods"). | ||
SubResource("proxy"). | ||
Name(fmt.Sprintf("%v:%v", podName, port)). | ||
Suffix("metrics"). | ||
Do().Raw() | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(rawOutput), nil | ||
} |
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