Skip to content

Commit

Permalink
Working code commit - day2
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 28, 2021
1 parent f282cd8 commit b591809
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
5 changes: 2 additions & 3 deletions cmd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ func runQueryViaHTTP(url, bearer string) (string, error) {
return "", err
}

fmt.Printf("Prometheus request returned HTTP Code: %d\n", resp.StatusCode)
return string(contents), nil
}

func RunQueries(promQueries map[string]bool, oc *exutil.CLI, ns, execPodName, baseURL, bearerToken string) {
func RunQueries(promQueries map[string]bool, oc *exutil.CLI, baseURL, bearerToken string) {
// expect all correct metrics within a reasonable time period
queryErrors := make(map[string]error)
passed := make(map[string]struct{})
Expand Down Expand Up @@ -170,7 +169,7 @@ func RunQueries(promQueries map[string]bool, oc *exutil.CLI, ns, execPodName, ba
queryErrors[query] = fmt.Errorf(msg)
continue
}

log.Printf("Result is: %s", result.Data)
// query successful
passed[query] = struct{}{}
delete(queryErrors, query)
Expand Down
35 changes: 11 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

prometheus "github.com/kedark3/cpa/cmd"
exutil "github.com/openshift/openshift-tests/test/extended/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
Expand All @@ -15,37 +14,25 @@ func main() {
o.RegisterFailHandler(g.Fail)

oc := exutil.NewCLI("prometheus-cpa", exutil.KubeConfigPath())
secrets, err := oc.AdminKubeClient().CoreV1().Secrets("openshift-monitoring").List(metav1.ListOptions{})
// secrets, err := oc.AdminKubeClient().CoreV1().Secrets("openshift-monitoring").List(metav1.ListOptions{})

if err != nil {
log.Printf("An Error has occured %s", err)
return
}
log.Printf("Found following secrets %d", secrets.Size())
// if err != nil {
// log.Printf("An Error has occured %s", err)
// return
// }
// log.Printf("Found following secrets %d", secrets.Size())
url, bearerToken, ok := prometheus.LocatePrometheus(oc)
if !ok {
log.Printf("Oops something went wrong while trying to fetch Prometheus url and bearerToken")
return
}

oc.SetupProject()
ns := oc.Namespace()

execPod := exutil.CreateCentosExecPodOrFail(oc.AdminKubeClient(), ns, "execpod", nil)
defer func() { oc.AdminKubeClient().CoreV1().Pods(ns).Delete(execPod.Name, metav1.NewDeleteOptions(1)) }()

tests := map[string]bool{
// Should have successfully sent at least some metrics to remote write endpoint
// uncomment this once https://github.com/openshift/cluster-monitoring-operator/pull/434
// is merged, and remove the other two checks.
// `prometheus_remote_storage_succeeded_samples_total{job="prometheus-k8s"} >= 1`: true,

// should have successfully sent at least once to remote
`metricsclient_request_send{client="federate_to",job="telemeter-client",status_code="200"} >= 1`: true,
// should have scraped some metrics from prometheus
`federate_samples{job="telemeter-client"} >= 10`: true,
`sum(kube_pod_status_phase{}) by (phase) > 0`: true,
`sum(kube_namespace_status_phase) by (phase)`: true,
`sum(kube_node_status_condition{status="true"}) by (condition) > 0`: true,
}
prometheus.RunQueries(tests, oc, ns, execPod.Name, url, bearerToken)
log.Printf("URL is %s and bearerToken is %s", url, bearerToken)
prometheus.RunQueries(tests, oc, url, bearerToken)
// log.Printf("URL is %s and bearerToken is %s", url, bearerToken)

}

0 comments on commit b591809

Please sign in to comment.