This commit is contained in:
Lou Knauer 2021-12-09 16:26:59 +01:00
parent 8178b6e854
commit b1d2403839
3 changed files with 12 additions and 7 deletions

View File

@ -29,7 +29,7 @@ var ldapAdminPassword string
func initLdap(config *LdapConfig) error { func initLdap(config *LdapConfig) error {
ldapAdminPassword = os.Getenv("LDAP_ADMIN_PASSWORD") ldapAdminPassword = os.Getenv("LDAP_ADMIN_PASSWORD")
if ldapAdminPassword == "" { if ldapAdminPassword == "" {
log.Println("warning: environment variable 'LDAP_ADMIN_PASSWORD' not set") log.Println("warning: environment variable 'LDAP_ADMIN_PASSWORD' not set (ldap sync or authentication will not work)")
} }
ldapConfig = config ldapConfig = config

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"log"
"net/http" "net/http"
"os" "os"
"time" "time"
@ -50,7 +51,7 @@ func (ccms *CCMetricStore) Init(url string) error {
ccms.url = url // os.Getenv("CCMETRICSTORE_URL") ccms.url = url // os.Getenv("CCMETRICSTORE_URL")
ccms.jwt = os.Getenv("CCMETRICSTORE_JWT") ccms.jwt = os.Getenv("CCMETRICSTORE_JWT")
if ccms.jwt == "" { if ccms.jwt == "" {
return errors.New("environment variable 'CCMETRICSTORE_JWT' not set") log.Println("warning: environment variable 'CCMETRICSTORE_JWT' not set")
} }
return nil return nil
@ -73,7 +74,9 @@ func (ccms *CCMetricStore) doRequest(job *model.Job, suffix string, metrics []st
if err != nil { if err != nil {
return nil, err return nil, err
} }
if ccms.jwt != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", ccms.jwt)) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", ccms.jwt))
}
return ccms.client.Do(req) return ccms.client.Do(req)
} }
@ -174,14 +177,16 @@ func (ccms *CCMetricStore) LoadNodeData(clusterId string, metrics, nodes []strin
var req *http.Request var req *http.Request
if nodes == nil { if nodes == nil {
req, err = http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s/api/%d/%d/all-nodes", ccms.url, from, to), bytes.NewReader(reqBodyBytes)) req, err = http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s/api/%s/%d/%d/all-nodes", ccms.url, clusterId, from, to), bytes.NewReader(reqBodyBytes))
} else { } else {
req, err = http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s/api/%d/%d/timeseries", ccms.url, from, to), bytes.NewReader(reqBodyBytes)) req, err = http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s/api/%d/%d/timeseries", ccms.url, from, to), bytes.NewReader(reqBodyBytes))
} }
if err != nil { if err != nil {
return nil, err return nil, err
} }
if ccms.jwt != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", ccms.jwt)) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", ccms.jwt))
}
res, err := ccms.client.Do(req) res, err := ccms.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -2,8 +2,8 @@ package metricdata
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"log"
"os" "os"
"strings" "strings"
"time" "time"
@ -24,7 +24,7 @@ type InfluxDBv2DataRepository struct {
func (idb *InfluxDBv2DataRepository) Init(url string) error { func (idb *InfluxDBv2DataRepository) Init(url string) error {
token := os.Getenv("INFLUXDB_V2_TOKEN") token := os.Getenv("INFLUXDB_V2_TOKEN")
if token == "" { if token == "" {
return errors.New("warning: environment variable 'INFLUXDB_V2_TOKEN' not set") log.Println("warning: environment variable 'INFLUXDB_V2_TOKEN' not set")
} }
idb.client = influxdb2.NewClient(url, token) idb.client = influxdb2.NewClient(url, token)