Skip to content

Commit

Permalink
Initial commit -Shri Ganesha
Browse files Browse the repository at this point in the history
Signed-off-by: Kedar Vijay Kulkarni <[email protected]>
  • Loading branch information
Kedar Vijay Kulkarni committed Oct 27, 2021
1 parent 6c196ce commit f1c17c0
Show file tree
Hide file tree
Showing 8 changed files with 986 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CPA - Continuous Performance Analysis


This tool allows OpenShift users to run a watcher for Prometheus queries and define thresholds (using a yaml file) to observe the performance of the OpenShift cluster during performance testing. It could be generalized to run constantly against a cluster and alert you when cluster is looking bad. It may sound like some of the other monitoring & alerting solutions but its supposed to be simple, scalable and user-friendly.

## To Do:

* [x] Create oc cli connection to OpenShift/Kubernetes using Kubeconfig
* [ ] Create yaml format for queries, and expected outcomes (Use a struct to read that in)
* [ ] Determine Prometheus url, bearerToken for OpenShift if not already included in the yaml
* [ ] Spawn goroutines to keep running queries and evaluating results
* [ ] Notify/Do Something when results don't match conditions
Binary file added bin/cpa
Binary file not shown.
42 changes: 42 additions & 0 deletions cmd/prometheus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"log"
"strings"
"time"

exutil "github.com/openshift/openshift-tests/test/extended/util"
v1 "k8s.io/api/core/v1"
kapierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func LocatePrometheus(oc *exutil.CLI) (url, bearerToken string, ok bool) {
_, err := oc.AdminKubeClient().CoreV1().Services("openshift-monitoring").Get("prometheus-k8s", metav1.GetOptions{})
if kapierrs.IsNotFound(err) {
return "", "", false
}
for i := 0; i < 30; i++ {
secrets, err := oc.AdminKubeClient().CoreV1().Secrets("openshift-monitoring").List(metav1.ListOptions{})
if err != nil {
log.Printf("An Error has occured %s", err)
return
}
for _, secret := range secrets.Items {
if secret.Type != v1.SecretTypeServiceAccountToken {
continue
}
if !strings.HasPrefix(secret.Name, "prometheus-") {
continue
}
bearerToken = string(secret.Data[v1.ServiceAccountTokenKey])
break
}
if len(bearerToken) == 0 {
log.Println("Waiting for prometheus service account secret to show up")
time.Sleep(time.Second)
continue
}
}
return "https://prometheus-k8s.openshift-monitoring.svc:9901", bearerToken, true
}
5 changes: 5 additions & 0 deletions config/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# You can also set these as env vars or program will try to fetch this dynamically from OpenShift
# as long as KUBECONFIG is set
url:
bearerToken:
Empty file added config/queries.yaml
Empty file.
45 changes: 45 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// module github.com/kedark3/cpa

// go 1.16

module github.com/kedark3/cpa

go 1.16

require (
github.com/openshift/openshift-tests v0.0.0-20210916082130-4fca21c38ee6
k8s.io/apimachinery v0.17.1
)

replace (
bitbucket.org/ww/goautoneg => github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d
github.com/golang/glog => github.com/openshift/golang-glog v0.0.0-20190322123450-3c92600d7533
github.com/google/cadvisor => github.com/openshift/google-cadvisor v0.33.2-0.20190902063809-4db825a8ad0d
github.com/jteeuwen/go-bindata => github.com/jteeuwen/go-bindata v3.0.8-0.20151023091102-a0ff2567cfb7+incompatible
github.com/onsi/ginkgo => github.com/openshift/onsi-ginkgo v1.4.1-0.20190902091932-d0603c19fe78
github.com/opencontainers/runc => github.com/openshift/opencontainers-runc v1.0.0-rc4.0.20190926164333-b942ff4cc6f8
github.com/openshift/api => github.com/openshift/api v0.0.0-20200117162508-e7ccdda6ba67
k8s.io/api => k8s.io/api v0.17.1
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.17.1
k8s.io/apimachinery => github.com/openshift/kubernetes-apimachinery v0.0.0-20191121175448-79c2a76c473a
k8s.io/apiserver => github.com/openshift/kubernetes-apiserver v0.0.0-20200109101329-ed563d1b80a1
k8s.io/cli-runtime => github.com/openshift/kubernetes-cli-runtime v0.0.0-20200115000600-01f2488fd0b7
k8s.io/client-go => github.com/openshift/kubernetes-client-go v0.0.0-20200106170045-1fda2942f64d
k8s.io/cloud-provider => k8s.io/cloud-provider v0.17.1
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.17.1
k8s.io/code-generator => k8s.io/code-generator v0.17.1
k8s.io/component-base => k8s.io/component-base v0.17.1
k8s.io/cri-api => k8s.io/cri-api v0.17.1
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.17.1
k8s.io/kube-aggregator => github.com/openshift/kubernetes-kube-aggregator v0.0.0-20191209133208-1e3c0eec4d61
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.17.1
k8s.io/kube-proxy => k8s.io/kube-proxy v0.17.1
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.17.1
k8s.io/kubectl => k8s.io/kubectl v0.17.1
k8s.io/kubelet => k8s.io/kubelet v0.17.1

k8s.io/kubernetes => github.com/openshift/kubernetes v1.17.0-alpha.0.0.20200120180958-5945c3b07163
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20191121182806-cdbd52110e91
k8s.io/metrics => k8s.io/metrics v0.0.0-20191121181631-c7d4ee0ffc0e
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191121181040-36c9528858d2
)
Loading

0 comments on commit f1c17c0

Please sign in to comment.