mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 21:39:06 +01:00
Fix build error with updated prometheus client
This commit is contained in:
parent
a8721dcc69
commit
a07d167390
@ -166,10 +166,10 @@ func (pdb *PrometheusDataRepository) Init(rawConfig json.RawMessage) error {
|
|||||||
var rt http.RoundTripper = nil
|
var rt http.RoundTripper = nil
|
||||||
if prom_pw := os.Getenv("PROMETHEUS_PASSWORD"); prom_pw != "" && config.Username != "" {
|
if prom_pw := os.Getenv("PROMETHEUS_PASSWORD"); prom_pw != "" && config.Username != "" {
|
||||||
prom_pw := promcfg.Secret(prom_pw)
|
prom_pw := promcfg.Secret(prom_pw)
|
||||||
rt = promcfg.NewBasicAuthRoundTripper(config.Username, prom_pw, "", promapi.DefaultRoundTripper)
|
rt = promcfg.NewBasicAuthRoundTripper(promcfg.NewInlineSecret(config.Username), promcfg.NewInlineSecret(string(prom_pw)), promapi.DefaultRoundTripper)
|
||||||
} else {
|
} else {
|
||||||
if config.Username != "" {
|
if config.Username != "" {
|
||||||
return errors.New("METRICDATA/PROMETHEUS > Prometheus username provided, but PROMETHEUS_PASSWORD not set.")
|
return errors.New("METRICDATA/PROMETHEUS > Prometheus username provided, but PROMETHEUS_PASSWORD not set")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// init client
|
// init client
|
||||||
@ -204,8 +204,8 @@ func (pdb *PrometheusDataRepository) FormatQuery(
|
|||||||
metric string,
|
metric string,
|
||||||
scope schema.MetricScope,
|
scope schema.MetricScope,
|
||||||
nodes []string,
|
nodes []string,
|
||||||
cluster string) (string, error) {
|
cluster string,
|
||||||
|
) (string, error) {
|
||||||
args := PromQLArgs{}
|
args := PromQLArgs{}
|
||||||
if len(nodes) > 0 {
|
if len(nodes) > 0 {
|
||||||
args.Nodes = fmt.Sprintf("(%s)%s", nodeRegex(nodes), pdb.suffix)
|
args.Nodes = fmt.Sprintf("(%s)%s", nodeRegex(nodes), pdb.suffix)
|
||||||
@ -233,12 +233,13 @@ func (pdb *PrometheusDataRepository) RowToSeries(
|
|||||||
from time.Time,
|
from time.Time,
|
||||||
step int64,
|
step int64,
|
||||||
steps int64,
|
steps int64,
|
||||||
row *promm.SampleStream) schema.Series {
|
row *promm.SampleStream,
|
||||||
|
) schema.Series {
|
||||||
ts := from.Unix()
|
ts := from.Unix()
|
||||||
hostname := strings.TrimSuffix(string(row.Metric["exported_instance"]), pdb.suffix)
|
hostname := strings.TrimSuffix(string(row.Metric["exported_instance"]), pdb.suffix)
|
||||||
// init array of expected length with NaN
|
// init array of expected length with NaN
|
||||||
values := make([]schema.Float, steps+1)
|
values := make([]schema.Float, steps+1)
|
||||||
for i, _ := range values {
|
for i := range values {
|
||||||
values[i] = schema.NaN
|
values[i] = schema.NaN
|
||||||
}
|
}
|
||||||
// copy recorded values from prom sample pair
|
// copy recorded values from prom sample pair
|
||||||
@ -263,8 +264,8 @@ func (pdb *PrometheusDataRepository) LoadData(
|
|||||||
job *schema.Job,
|
job *schema.Job,
|
||||||
metrics []string,
|
metrics []string,
|
||||||
scopes []schema.MetricScope,
|
scopes []schema.MetricScope,
|
||||||
ctx context.Context) (schema.JobData, error) {
|
ctx context.Context,
|
||||||
|
) (schema.JobData, error) {
|
||||||
// TODO respect requested scope
|
// TODO respect requested scope
|
||||||
if len(scopes) == 0 || !contains(scopes, schema.MetricScopeNode) {
|
if len(scopes) == 0 || !contains(scopes, schema.MetricScopeNode) {
|
||||||
scopes = append(scopes, schema.MetricScopeNode)
|
scopes = append(scopes, schema.MetricScopeNode)
|
||||||
@ -306,7 +307,6 @@ func (pdb *PrometheusDataRepository) LoadData(
|
|||||||
Step: time.Duration(metricConfig.Timestep * 1e9),
|
Step: time.Duration(metricConfig.Timestep * 1e9),
|
||||||
}
|
}
|
||||||
result, warnings, err := pdb.queryClient.QueryRange(ctx, query, r)
|
result, warnings, err := pdb.queryClient.QueryRange(ctx, query, r)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Prometheus query error in LoadData: %v\nQuery: %s", err, query)
|
log.Errorf("Prometheus query error in LoadData: %v\nQuery: %s", err, query)
|
||||||
return nil, errors.New("Prometheus query error")
|
return nil, errors.New("Prometheus query error")
|
||||||
@ -335,7 +335,7 @@ func (pdb *PrometheusDataRepository) LoadData(
|
|||||||
pdb.RowToSeries(from, step, steps, row))
|
pdb.RowToSeries(from, step, steps, row))
|
||||||
}
|
}
|
||||||
// only add metric if at least one host returned data
|
// only add metric if at least one host returned data
|
||||||
if !ok && len(jobMetric.Series) > 0{
|
if !ok && len(jobMetric.Series) > 0 {
|
||||||
jobData[metric][scope] = jobMetric
|
jobData[metric][scope] = jobMetric
|
||||||
}
|
}
|
||||||
// sort by hostname to get uniform coloring
|
// sort by hostname to get uniform coloring
|
||||||
@ -351,8 +351,8 @@ func (pdb *PrometheusDataRepository) LoadData(
|
|||||||
func (pdb *PrometheusDataRepository) LoadStats(
|
func (pdb *PrometheusDataRepository) LoadStats(
|
||||||
job *schema.Job,
|
job *schema.Job,
|
||||||
metrics []string,
|
metrics []string,
|
||||||
ctx context.Context) (map[string]map[string]schema.MetricStatistics, error) {
|
ctx context.Context,
|
||||||
|
) (map[string]map[string]schema.MetricStatistics, error) {
|
||||||
// map of metrics of nodes of stats
|
// map of metrics of nodes of stats
|
||||||
stats := map[string]map[string]schema.MetricStatistics{}
|
stats := map[string]map[string]schema.MetricStatistics{}
|
||||||
|
|
||||||
@ -376,7 +376,8 @@ func (pdb *PrometheusDataRepository) LoadNodeData(
|
|||||||
metrics, nodes []string,
|
metrics, nodes []string,
|
||||||
scopes []schema.MetricScope,
|
scopes []schema.MetricScope,
|
||||||
from, to time.Time,
|
from, to time.Time,
|
||||||
ctx context.Context) (map[string]map[string][]*schema.JobMetric, error) {
|
ctx context.Context,
|
||||||
|
) (map[string]map[string][]*schema.JobMetric, error) {
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
// Map of hosts of metrics of value slices
|
// Map of hosts of metrics of value slices
|
||||||
data := make(map[string]map[string][]*schema.JobMetric)
|
data := make(map[string]map[string][]*schema.JobMetric)
|
||||||
@ -411,7 +412,6 @@ func (pdb *PrometheusDataRepository) LoadNodeData(
|
|||||||
Step: time.Duration(metricConfig.Timestep * 1e9),
|
Step: time.Duration(metricConfig.Timestep * 1e9),
|
||||||
}
|
}
|
||||||
result, warnings, err := pdb.queryClient.QueryRange(ctx, query, r)
|
result, warnings, err := pdb.queryClient.QueryRange(ctx, query, r)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Prometheus query error in LoadNodeData: %v\n", err)
|
log.Errorf("Prometheus query error in LoadNodeData: %v\n", err)
|
||||||
return nil, errors.New("Prometheus query error")
|
return nil, errors.New("Prometheus query error")
|
||||||
|
Loading…
Reference in New Issue
Block a user