Fix return error, fix wrong log path, add notice log where applicable

- Adresses issue #26
This commit is contained in:
Christoph Kluge 2023-01-24 12:02:29 +01:00
parent 79a949b55e
commit bd770d0e32
6 changed files with 65 additions and 22 deletions

View File

@ -52,7 +52,7 @@ func (r *mutationResolver) CreateTag(ctx context.Context, typeArg string, name s
// DeleteTag is the resolver for the deleteTag field. // DeleteTag is the resolver for the deleteTag field.
func (r *mutationResolver) DeleteTag(ctx context.Context, id string) (string, error) { func (r *mutationResolver) DeleteTag(ctx context.Context, id string) (string, error) {
log.Panic(fmt.Errorf("not implemented: DeleteTag - deleteTag")) panic(fmt.Errorf("not implemented: DeleteTag - deleteTag"))
} }
// AddTagsToJob is the resolver for the addTagsToJob field. // AddTagsToJob is the resolver for the addTagsToJob field.

View File

@ -273,7 +273,7 @@ func (ccms *CCMetricStore) buildQueries(
mc := archive.GetMetricConfig(job.Cluster, metric) mc := archive.GetMetricConfig(job.Cluster, metric)
if mc == nil { if mc == nil {
// return nil, fmt.Errorf("METRICDATA/CCMS > metric '%s' is not specified for cluster '%s'", metric, job.Cluster) // return nil, fmt.Errorf("METRICDATA/CCMS > metric '%s' is not specified for cluster '%s'", metric, job.Cluster)
// log.Printf("METRICDATA/CCMS > metric '%s' is not specified for cluster '%s'", metric, job.Cluster) log.Notef("metric '%s' is not specified for cluster '%s'", metric, job.Cluster)
continue continue
} }

View File

@ -97,10 +97,10 @@ func (idb *InfluxDBv2DataRepository) LoadData(
idb.formatTime(job.StartTime), idb.formatTime(idb.epochToTime(job.StartTimeUnix+int64(job.Duration)+int64(1))), idb.formatTime(job.StartTime), idb.formatTime(idb.epochToTime(job.StartTimeUnix+int64(job.Duration)+int64(1))),
measurementsCond, hostsCond) measurementsCond, hostsCond)
case "socket": case "socket":
log.Info("Scope 'socket' requested, but not yet supported: Will return 'node' scope only. ") log.Note("Scope 'socket' requested, but not yet supported: Will return 'node' scope only. ")
continue continue
case "core": case "core":
log.Info(" Scope 'core' requested, but not yet supported: Will return 'node' scope only. ") log.Note(" Scope 'core' requested, but not yet supported: Will return 'node' scope only. ")
continue continue
// Get Finest Granularity only, Set NULL to 0.0 // Get Finest Granularity only, Set NULL to 0.0
// query = fmt.Sprintf(` // query = fmt.Sprintf(`
@ -114,7 +114,7 @@ func (idb *InfluxDBv2DataRepository) LoadData(
// idb.formatTime(job.StartTime), idb.formatTime(idb.epochToTime(job.StartTimeUnix + int64(job.Duration) + int64(1) )), // idb.formatTime(job.StartTime), idb.formatTime(idb.epochToTime(job.StartTimeUnix + int64(job.Duration) + int64(1) )),
// measurementsCond, hostsCond) // measurementsCond, hostsCond)
default: default:
log.Info("Unknown Scope requested: Will return 'node' scope. ") log.Notef("Unknown scope '%s' requested: Will return 'node' scope.", scope)
continue continue
// return nil, errors.New("METRICDATA/INFLUXV2 > the InfluxDB metric data repository does not yet support other scopes than 'node'") // return nil, errors.New("METRICDATA/INFLUXV2 > the InfluxDB metric data repository does not yet support other scopes than 'node'")
} }
@ -192,6 +192,7 @@ func (idb *InfluxDBv2DataRepository) LoadData(
// hostSeries.Data = append(hostSeries.Data, schema.Float(val)) // hostSeries.Data = append(hostSeries.Data, schema.Float(val))
// } // }
default: default:
log.Notef("Unknown scope '%s' requested: Will return 'node' scope.", scope)
continue continue
// return nil, errors.New("the InfluxDB metric data repository does not yet support other scopes than 'node, core'") // return nil, errors.New("the InfluxDB metric data repository does not yet support other scopes than 'node, core'")
} }
@ -319,7 +320,7 @@ func (idb *InfluxDBv2DataRepository) LoadNodeData(
ctx context.Context) (map[string]map[string][]*schema.JobMetric, error) { ctx context.Context) (map[string]map[string][]*schema.JobMetric, error) {
// TODO : Implement to be used in Analysis- und System/Node-View // TODO : Implement to be used in Analysis- und System/Node-View
log.Infof("LoadNodeData unimplemented for InfluxDBv2DataRepository, Args: cluster %s, metrics %v, nodes %v, scopes %v", cluster, metrics, nodes, scopes) log.Notef("LoadNodeData unimplemented for InfluxDBv2DataRepository, Args: cluster %s, metrics %v, nodes %v, scopes %v", cluster, metrics, nodes, scopes)
return nil, errors.New("METRICDATA/INFLUXV2 > unimplemented for InfluxDBv2DataRepository") return nil, errors.New("METRICDATA/INFLUXV2 > unimplemented for InfluxDBv2DataRepository")
} }

View File

@ -283,7 +283,7 @@ func (pdb *PrometheusDataRepository) LoadData(
for _, scope := range scopes { for _, scope := range scopes {
if scope != schema.MetricScopeNode { if scope != schema.MetricScopeNode {
logOnce.Do(func(){log.Infof("Scope '%s' requested, but not yet supported: Will return 'node' scope only.", scope)}) logOnce.Do(func(){log.Notef("Scope '%s' requested, but not yet supported: Will return 'node' scope only.", scope)})
continue continue
} }
@ -389,7 +389,7 @@ func (pdb *PrometheusDataRepository) LoadNodeData(
} }
for _, scope := range scopes { for _, scope := range scopes {
if scope != schema.MetricScopeNode { if scope != schema.MetricScopeNode {
logOnce.Do(func(){log.Infof("Note: Scope '%s' requested, but not yet supported: Will return 'node' scope only.", scope)}) logOnce.Do(func(){log.Notef("Note: Scope '%s' requested, but not yet supported: Will return 'node' scope only.", scope)})
continue continue
} }
for _, metric := range metrics { for _, metric := range metrics {

View File

@ -292,6 +292,8 @@ func (r *JobRepository) CountGroupedJobs(ctx context.Context, aggreg model.Aggre
now := time.Now().Unix() now := time.Now().Unix()
count = fmt.Sprintf(`sum(job.num_nodes * (CASE WHEN job.job_state = "running" THEN %d - job.start_time ELSE job.duration END)) as count`, now) count = fmt.Sprintf(`sum(job.num_nodes * (CASE WHEN job.job_state = "running" THEN %d - job.start_time ELSE job.duration END)) as count`, now)
runner = r.DB runner = r.DB
default:
log.Notef("CountGroupedJobs() Weight %v unknown.", *weight)
} }
} }
@ -356,6 +358,8 @@ func (r *JobRepository) MarkArchived(
stmt = stmt.Set("net_bw_avg", stats.Avg) stmt = stmt.Set("net_bw_avg", stats.Avg)
case "file_bw": case "file_bw":
stmt = stmt.Set("file_bw_avg", stats.Avg) stmt = stmt.Set("file_bw_avg", stats.Avg)
default:
log.Notef("MarkArchived() Metric %s unknown.", metric)
} }
} }

View File

@ -97,6 +97,8 @@ func printStr(v ...interface{}) string {
return fmt.Sprint(v...) return fmt.Sprint(v...)
} }
// Uses Info() -> If errorpath required at some point:
// Will need own writer with 'Output(2, out)' to correctly render path
func Print(v ...interface{}) { func Print(v ...interface{}) {
Info(v...) Info(v...)
} }
@ -156,17 +158,20 @@ func Error(v ...interface{}) {
} }
} }
// Writes panic stacktrace, keeps application alive // Writes panic stacktrace, but keeps application alive
func Panic(v ...interface{}) { func Panic(v ...interface{}) {
Error(v...) if ErrWriter != io.Discard {
out := printStr(v...)
if logDateTime {
ErrTimeLog.Output(2, out)
} else {
ErrLog.Output(2, out)
}
}
panic("Panic triggered ...") panic("Panic triggered ...")
} }
// Writes error log, stops application
func Fatal(v ...interface{}) {
Error(v...)
os.Exit(1)
}
func Crit(v ...interface{}) { func Crit(v ...interface{}) {
if CritWriter != io.Discard { if CritWriter != io.Discard {
@ -179,6 +184,20 @@ func Crit(v ...interface{}) {
} }
} }
// Writes critical log, stops application
func Fatal(v ...interface{}) {
if CritWriter != io.Discard {
out := printStr(v...)
if logDateTime {
CritTimeLog.Output(2, out)
} else {
CritLog.Output(2, out)
}
}
os.Exit(1)
}
/* PRINT FORMAT*/ /* PRINT FORMAT*/
// Private helper // Private helper
@ -186,6 +205,8 @@ func printfStr(format string, v ...interface{}) string {
return fmt.Sprintf(format, v...) return fmt.Sprintf(format, v...)
} }
// Uses Infof() -> If errorpath required at some point:
// Will need own writer with 'Output(2, out)' to correctly render path
func Printf(format string, v ...interface{}) { func Printf(format string, v ...interface{}) {
Infof(format, v...) Infof(format, v...)
} }
@ -245,17 +266,20 @@ func Errorf(format string, v ...interface{}) {
} }
} }
// Writes panic stacktrace, keeps application alive // Writes panic stacktrace, but keeps application alive
func Panicf(format string, v ...interface{}) { func Panicf(format string, v ...interface{}) {
Errorf(format, v...) if ErrWriter != io.Discard {
out := printfStr(format, v...)
if logDateTime {
ErrTimeLog.Output(2, out)
} else {
ErrLog.Output(2, out)
}
}
panic("Panic triggered ...") panic("Panic triggered ...")
} }
// Writes error log, stops application
func Fatalf(format string, v ...interface{}) {
Errorf(format, v...)
os.Exit(1)
}
func Critf(format string, v ...interface{}) { func Critf(format string, v ...interface{}) {
if CritWriter != io.Discard { if CritWriter != io.Discard {
@ -268,6 +292,20 @@ func Critf(format string, v ...interface{}) {
} }
} }
// Writes crit log, stops application
func Fatalf(format string, v ...interface{}) {
if CritWriter != io.Discard {
out := printfStr(format, v...)
if logDateTime {
CritTimeLog.Output(2, out)
} else {
CritLog.Output(2, out)
}
}
os.Exit(1)
}
/* SPECIAL */ /* SPECIAL */
func Finfof(w io.Writer, format string, v ...interface{}) { func Finfof(w io.Writer, format string, v ...interface{}) {