mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 05:19:05 +01:00
Fix bugs in stats.go
This commit is contained in:
parent
0458675608
commit
e348ec74fd
@ -286,6 +286,7 @@ func (r *JobRepository) JobsStats(
|
|||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Make generic
|
||||||
func LoadJobStat(job *schema.JobMeta, metric string) float64 {
|
func LoadJobStat(job *schema.JobMeta, metric string) float64 {
|
||||||
if stats, ok := job.Statistics[metric]; ok {
|
if stats, ok := job.Statistics[metric]; ok {
|
||||||
if metric == "mem_used" {
|
if metric == "mem_used" {
|
||||||
@ -609,16 +610,16 @@ func (r *JobRepository) jobsMetricStatisticsHistogram(
|
|||||||
bins := 10
|
bins := 10
|
||||||
binQuery := fmt.Sprintf(`CAST( (case when %s = value.max
|
binQuery := fmt.Sprintf(`CAST( (case when %s = value.max
|
||||||
then value.max*0.999999999 else %s end - value.min) / (value.max -
|
then value.max*0.999999999 else %s end - value.min) / (value.max -
|
||||||
value.min) * %d as INTEGER )`, metric, metric, bins)
|
value.min) * %d as INTEGER )`, jm, jm, bins)
|
||||||
|
|
||||||
mainQuery := sq.Select(
|
mainQuery := sq.Select(
|
||||||
fmt.Sprintf(`%s + 1 as bin`, binQuery),
|
fmt.Sprintf(`%s + 1 as bin`, binQuery),
|
||||||
fmt.Sprintf(`count(%s) as count`, metric),
|
fmt.Sprintf(`count(%s) as count`, jm),
|
||||||
fmt.Sprintf(`CAST(((value.max / %d) * (%s )) as INTEGER ) as min`, bins, binQuery),
|
fmt.Sprintf(`CAST(((value.max / %d) * (%s )) as INTEGER ) as min`, bins, binQuery),
|
||||||
fmt.Sprintf(`CAST(((value.max / %d) * (%s + 1 )) as INTEGER ) as max`, bins, binQuery),
|
fmt.Sprintf(`CAST(((value.max / %d) * (%s + 1 )) as INTEGER ) as max`, bins, binQuery),
|
||||||
).From("job").CrossJoin(
|
).From("job").CrossJoin(
|
||||||
fmt.Sprintf(`(%s) as value`, crossJoinQuerySql), crossJoinQueryArgs...,
|
fmt.Sprintf(`(%s) as value`, crossJoinQuerySql), crossJoinQueryArgs...,
|
||||||
).Where(fmt.Sprintf(`%s is not null and %s <= %f`, metric, metric, peak))
|
).Where(fmt.Sprintf(`%s is not null and %s <= %f`, jm, jm, peak))
|
||||||
|
|
||||||
mainQuery, qerr := SecurityCheck(ctx, mainQuery)
|
mainQuery, qerr := SecurityCheck(ctx, mainQuery)
|
||||||
|
|
||||||
@ -643,7 +644,7 @@ func (r *JobRepository) jobsMetricStatisticsHistogram(
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
point := model.MetricHistoPoint{}
|
point := model.MetricHistoPoint{}
|
||||||
if err := rows.Scan(&point.Bin, &point.Count, &point.Min, &point.Max); err != nil {
|
if err := rows.Scan(&point.Bin, &point.Count, &point.Min, &point.Max); err != nil {
|
||||||
log.Warnf("Error while scanning rows for %s", metric)
|
log.Warnf("Error while scanning rows for %s", jm)
|
||||||
return nil, err // Totally bricks cc-backend if returned and if all metrics requested?
|
return nil, err // Totally bricks cc-backend if returned and if all metrics requested?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user