Skip to content

Commit

Permalink
Set UUID into the logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schneider committed Oct 27, 2022
1 parent 2b4502b commit 3cd831d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
20 changes: 13 additions & 7 deletions command/jobs/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import (
)

type Job struct {
ctx context.Context
handler *handler.Endpoint
job *config.Job
ctx context.Context
handler *handler.Endpoint
job *config.Job
settings *config.Settings
}

var jobs = make(map[string]*Job)

func AddJob(ctx context.Context, j *config.Job, h *handler.Endpoint) {
func AddJob(ctx context.Context, j *config.Job, h *handler.Endpoint, settings *config.Settings) {
jobs[j.Name] = &Job{
ctx: ctx,
handler: h,
job: j,
ctx: ctx,
handler: h,
job: j,
settings: settings,
}
}

Expand All @@ -38,3 +40,7 @@ func (j *Job) GetHandler() *handler.Endpoint {
func (j *Job) GetJob() *config.Job {
return j.job
}

func (j *Job) GetSettings() *config.Settings {
return j.settings
}
9 changes: 7 additions & 2 deletions command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/avenga/couper/config/runtime"
"github.com/avenga/couper/errors"
"github.com/avenga/couper/eval"
"github.com/avenga/couper/handler/middleware"
"github.com/avenga/couper/server"
"github.com/avenga/couper/server/writer"
"github.com/avenga/couper/telemetry"
Expand Down Expand Up @@ -228,8 +229,10 @@ func (r *Run) Execute(args Args, config *config.Couper, logEntry *logrus.Entry)
ctx := context.WithValue(req.Context(), request.LogEntry, logEntry)
*req = *req.WithContext(ctx)

uidHandler := middleware.NewUIDHandler(job.GetSettings(), "")(job.GetHandler())

// Execute initial, do not wait for execution
go job.GetHandler().ServeHTTP(writer.NewResponseWriter(httptest.NewRecorder(), ""), req)
go uidHandler.ServeHTTP(writer.NewResponseWriter(httptest.NewRecorder(), ""), req)

interval, _ := time.ParseDuration(job.GetJob().Interval)

Expand All @@ -238,8 +241,10 @@ func (r *Run) Execute(args Args, config *config.Couper, logEntry *logrus.Entry)
case <-job.GetCtx().Done():
return
case <-time.After(interval):
uidHandler := middleware.NewUIDHandler(job.GetSettings(), "")(job.GetHandler())

// Do not wait for execution
go job.GetHandler().ServeHTTP(writer.NewResponseWriter(httptest.NewRecorder(), ""), req)
go uidHandler.ServeHTTP(writer.NewResponseWriter(httptest.NewRecorder(), ""), req)
}
}
}(job, name)
Expand Down
2 changes: 1 addition & 1 deletion config/runtime/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func NewServerConfiguration(conf *config.Couper, log *logrus.Entry, memStore *ca

endpointHandler := handler.NewEndpoint(endpointOptions, log, nil)

jobs.AddJob(conf.Context, job, endpointHandler)
jobs.AddJob(conf.Context, job, endpointHandler, conf.Settings)
}
}

Expand Down

0 comments on commit 3cd831d

Please sign in to comment.