From 30a436e27e0a1f5e4a2b443196c684429343bde6 Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Mon, 20 Dec 2021 10:49:46 +0100 Subject: [PATCH] use token from cluster.json --- .env | 7 ------- metricdata/cc-metric-store.go | 12 +++--------- metricdata/metricdata.go | 4 ++-- server.go | 14 ++++++-------- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/.env b/.env index 48076cd..0301d4b 100644 --- a/.env +++ b/.env @@ -1,11 +1,4 @@ - -export CCMETRICSTORE_URL="http://localhost:8081" -export CCMETRICSTORE_JWT="eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlcyI6WyJST0xFX0FETUlOIiwiUk9MRV9BTkFMWVNUIiwiUk9MRV9VU0VSIl19.d-3_3FZTsadPjDEdsWrrQ7nS0edMAR4zjl-eK7rJU3HziNBfI9PDHDIpJVHTNN5E5SlLGLFXctWyKAkwhXL-Dw" - -export INFLUXDB_V2_TOKEN="egLfcf7fx0FESqFYU3RpAAbj" - export JWT_PUBLIC_KEY="kzfYrYy+TzpanWZHJ5qSdMj5uKUWgq74BWhQG6copP0=" export JWT_PRIVATE_KEY="dtPC/6dWJFKZK7KZ78CvWuynylOmjBFyMsUWArwmodOTN9itjL5POlqdZkcnmpJ0yPm4pRaCrvgFaFAbpyik/Q==" export SESSION_KEY="67d829bf61dc5f87a73fd814e2c9f629" - export LDAP_ADMIN_PASSWORD="mashup" diff --git a/metricdata/cc-metric-store.go b/metricdata/cc-metric-store.go index 2602f3b..603c82f 100644 --- a/metricdata/cc-metric-store.go +++ b/metricdata/cc-metric-store.go @@ -6,9 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "log" "net/http" - "os" "time" "github.com/ClusterCockpit/cc-jobarchive/config" @@ -46,13 +44,9 @@ type ApiStatsData struct { Max schema.Float `json:"max"` } -func (ccms *CCMetricStore) Init(url string) error { - ccms.url = url // os.Getenv("CCMETRICSTORE_URL") - ccms.jwt = os.Getenv("CCMETRICSTORE_JWT") - if ccms.jwt == "" { - log.Println("warning: environment variable 'CCMETRICSTORE_JWT' not set") - } - +func (ccms *CCMetricStore) Init(url, token string) error { + ccms.url = url + ccms.jwt = token return nil } diff --git a/metricdata/metricdata.go b/metricdata/metricdata.go index d066015..18f3aac 100644 --- a/metricdata/metricdata.go +++ b/metricdata/metricdata.go @@ -11,7 +11,7 @@ import ( type MetricDataRepository interface { // Initialize this MetricDataRepository. One instance of // this interface will only ever be responsible for one cluster. - Init(url string) error + Init(url, token string) error // Return the JobData for the given job, only with the requested metrics. LoadData(job *schema.Job, metrics []string, ctx context.Context) (schema.JobData, error) @@ -37,7 +37,7 @@ func Init(jobArchivePath string, disableArchive bool) error { switch cluster.MetricDataRepository.Kind { case "cc-metric-store": ccms := &CCMetricStore{} - if err := ccms.Init(cluster.MetricDataRepository.Url); err != nil { + if err := ccms.Init(cluster.MetricDataRepository.Url, cluster.MetricDataRepository.Token); err != nil { return err } metricDataRepos[cluster.Name] = ccms diff --git a/server.go b/server.go index 827b929..18f4ccc 100644 --- a/server.go +++ b/server.go @@ -16,6 +16,7 @@ import ( "github.com/ClusterCockpit/cc-jobarchive/graph" "github.com/ClusterCockpit/cc-jobarchive/graph/generated" "github.com/ClusterCockpit/cc-jobarchive/metricdata" + "github.com/ClusterCockpit/cc-jobarchive/schema" "github.com/ClusterCockpit/cc-jobarchive/templates" "github.com/gorilla/handlers" "github.com/gorilla/mux" @@ -264,19 +265,16 @@ func monitoringRoutes(router *mux.Router, resolver *graph.Resolver) { filterPresets := map[string]interface{}{} query := r.URL.Query() if query.Get("tag") != "" { - filterPresets["tagId"] = query.Get("tag") + filterPresets["tag"] = query.Get("tag") } if query.Get("cluster") != "" { - filterPresets["clusterId"] = query.Get("cluster") + filterPresets["cluster"] = query.Get("cluster") } if query.Get("project") != "" { - filterPresets["projectId"] = query.Get("project") + filterPresets["project"] = query.Get("project") } - if query.Get("running") == "true" { - filterPresets["isRunning"] = true - } - if query.Get("running") == "false" { - filterPresets["isRunning"] = false + if query.Get("state") != "" && schema.JobState(query.Get("state")).Valid() { + filterPresets["state"] = query.Get("state") } if query.Get("from") != "" && query.Get("to") != "" { filterPresets["startTime"] = map[string]string{