From bd770d0e32600a832c0c562a68790b35c30498a6 Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Tue, 24 Jan 2023 12:02:29 +0100 Subject: [PATCH] Fix return error, fix wrong log path, add notice log where applicable - Adresses issue #26 --- internal/graph/schema.resolvers.go | 2 +- internal/metricdata/cc-metric-store.go | 2 +- internal/metricdata/influxdb-v2.go | 9 ++-- internal/metricdata/prometheus.go | 4 +- internal/repository/job.go | 4 ++ pkg/log/log.go | 66 ++++++++++++++++++++------ 6 files changed, 65 insertions(+), 22 deletions(-) diff --git a/internal/graph/schema.resolvers.go b/internal/graph/schema.resolvers.go index 5c927f1..139da17 100644 --- a/internal/graph/schema.resolvers.go +++ b/internal/graph/schema.resolvers.go @@ -52,7 +52,7 @@ func (r *mutationResolver) CreateTag(ctx context.Context, typeArg string, name s // DeleteTag is the resolver for the deleteTag field. 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. diff --git a/internal/metricdata/cc-metric-store.go b/internal/metricdata/cc-metric-store.go index 027c0e0..65d0742 100644 --- a/internal/metricdata/cc-metric-store.go +++ b/internal/metricdata/cc-metric-store.go @@ -273,7 +273,7 @@ func (ccms *CCMetricStore) buildQueries( mc := archive.GetMetricConfig(job.Cluster, metric) if mc == nil { // 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 } diff --git a/internal/metricdata/influxdb-v2.go b/internal/metricdata/influxdb-v2.go index 8c1e428..349f8a8 100644 --- a/internal/metricdata/influxdb-v2.go +++ b/internal/metricdata/influxdb-v2.go @@ -97,10 +97,10 @@ func (idb *InfluxDBv2DataRepository) LoadData( idb.formatTime(job.StartTime), idb.formatTime(idb.epochToTime(job.StartTimeUnix+int64(job.Duration)+int64(1))), measurementsCond, hostsCond) 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 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 // Get Finest Granularity only, Set NULL to 0.0 // 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) )), // measurementsCond, hostsCond) default: - log.Info("Unknown Scope requested: Will return 'node' scope. ") + log.Notef("Unknown scope '%s' requested: Will return 'node' scope.", scope) continue // 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)) // } default: + log.Notef("Unknown scope '%s' requested: Will return 'node' scope.", scope) continue // 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) { // 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") } diff --git a/internal/metricdata/prometheus.go b/internal/metricdata/prometheus.go index 7d51218..3c79866 100644 --- a/internal/metricdata/prometheus.go +++ b/internal/metricdata/prometheus.go @@ -283,7 +283,7 @@ func (pdb *PrometheusDataRepository) LoadData( for _, scope := range scopes { 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 } @@ -389,7 +389,7 @@ func (pdb *PrometheusDataRepository) LoadNodeData( } for _, scope := range scopes { 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 } for _, metric := range metrics { diff --git a/internal/repository/job.go b/internal/repository/job.go index 76db377..0ade90b 100644 --- a/internal/repository/job.go +++ b/internal/repository/job.go @@ -292,6 +292,8 @@ func (r *JobRepository) CountGroupedJobs(ctx context.Context, aggreg model.Aggre 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) 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) case "file_bw": stmt = stmt.Set("file_bw_avg", stats.Avg) + default: + log.Notef("MarkArchived() Metric %s unknown.", metric) } } diff --git a/pkg/log/log.go b/pkg/log/log.go index e7cabb0..c223566 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -97,6 +97,8 @@ func printStr(v ...interface{}) string { 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{}) { 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{}) { - Error(v...) + if ErrWriter != io.Discard { + out := printStr(v...) + if logDateTime { + ErrTimeLog.Output(2, out) + } else { + ErrLog.Output(2, out) + } + } + panic("Panic triggered ...") } -// Writes error log, stops application -func Fatal(v ...interface{}) { - Error(v...) - os.Exit(1) -} func Crit(v ...interface{}) { 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*/ // Private helper @@ -186,6 +205,8 @@ func printfStr(format string, v ...interface{}) string { 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{}) { 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{}) { - 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 ...") } -// Writes error log, stops application -func Fatalf(format string, v ...interface{}) { - Errorf(format, v...) - os.Exit(1) -} func Critf(format string, v ...interface{}) { 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 */ func Finfof(w io.Writer, format string, v ...interface{}) {