From 23c29aba1de3015aca5833ddc7d5f7d734d2dfe2 Mon Sep 17 00:00:00 2001 From: Aleksandr Trushkin Date: Sat, 27 Jun 2026 23:54:07 +0000 Subject: [PATCH] fix(cluster-1): data corruption fixes (C4/C5/C8) - synchandler: combine course date with clock time via time.Date instead of adding two absolute Unix epochs, which produced corrupt start times - tracing: make DeploymentEnvironment configurable via config.Trace (defaults to development instead of hardcoded production) - http: align course handler tracer name to 'kuriweb.http' to match the request middleware instrument so spans share the same tracer --- cmd/kuriweb/trace.go | 9 ++++++--- internal/common/config/trace.go | 9 +++++---- internal/kurious/ports/background/synchandler.go | 8 ++++++-- internal/kurious/ports/http/course.go | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cmd/kuriweb/trace.go b/cmd/kuriweb/trace.go index e11e62d..14838ef 100644 --- a/cmd/kuriweb/trace.go +++ b/cmd/kuriweb/trace.go @@ -50,7 +50,7 @@ func setupOtelSDK(ctx context.Context, cfg config.Trace) (shutdown shutdownFunc, return err } - resource, err := makeServiceResource(ctx) + resource, err := makeServiceResource(ctx, cfg.Environment) if err != nil { return shutdown, fmt.Errorf("making service resource: %w", err) } @@ -102,7 +102,10 @@ type TraceProviderParams struct { Type config.TraceClientType } -func makeServiceResource(ctx context.Context) (*resource.Resource, error) { +func makeServiceResource(ctx context.Context, environment string) (*resource.Resource, error) { + if environment == "" { + environment = "development" + } r, err := resource.New( ctx, resource.WithDetectors( @@ -113,7 +116,7 @@ func makeServiceResource(ctx context.Context) (*resource.Resource, error) { resource.WithHost(), resource.WithAttributes( semconv.ServiceName("bigstats:kuriweb"), - semconv.DeploymentEnvironment("production"), + semconv.DeploymentEnvironment(environment), ), ) if err != nil { diff --git a/internal/common/config/trace.go b/internal/common/config/trace.go index 844e740..35865b3 100644 --- a/internal/common/config/trace.go +++ b/internal/common/config/trace.go @@ -29,10 +29,11 @@ func (t *TraceClientType) UnmarshalText(data []byte) error { } type Trace struct { - Endpoint string `json:"endpoint"` - APIKey string `json:"api_key"` - APIHeader string `json:"api_header"` - Type TraceClientType `json:"type"` + Endpoint string `json:"endpoint"` + APIKey string `json:"api_key"` + APIHeader string `json:"api_header"` + Type TraceClientType `json:"type"` + Environment string `json:"environment"` ShowMetrics bool `json:"show_metrics"` } diff --git a/internal/kurious/ports/background/synchandler.go b/internal/kurious/ports/background/synchandler.go index ca21da0..e5ac1b7 100644 --- a/internal/kurious/ports/background/synchandler.go +++ b/internal/kurious/ports/background/synchandler.go @@ -384,8 +384,12 @@ func courseAsCreateCourseParams(course sravni.Course) command.CreateCourse { startAt = *course.DateStart } if course.TimeStart != nil { - startAtUnix := startAt.Unix() + course.TimeStart.Unix() - startAt = time.Unix(startAtUnix, 0) + clock := *course.TimeStart + startAt = time.Date( + startAt.Year(), startAt.Month(), startAt.Day(), + clock.Hour(), clock.Minute(), clock.Second(), clock.Nanosecond(), + startAt.Location(), + ) } var courseDuration time.Duration diff --git a/internal/kurious/ports/http/course.go b/internal/kurious/ports/http/course.go index e818ed1..db06464 100644 --- a/internal/kurious/ports/http/course.go +++ b/internal/kurious/ports/http/course.go @@ -23,7 +23,7 @@ import ( var ( paramsAttr = attribute.Key("params") - webtracer = otel.Tracer("http") + webtracer = otel.Tracer("kuriweb.http") ) type courseTemplServer struct {