diff --git a/apps/iris/Dockerfile b/apps/iris/Dockerfile index 9253dd2d2d..8caf219f6e 100644 --- a/apps/iris/Dockerfile +++ b/apps/iris/Dockerfile @@ -6,10 +6,9 @@ WORKDIR /build RUN go build -### PRODUCTION ### +### SERVER ### FROM ubuntu:24.04 -ENV APP_ENV=production COPY --from=builder /build/iris . # Install dependencies @@ -29,4 +28,6 @@ RUN architecture=$(dpkg --print-architecture) && if [ "$architecture" = "arm64" fi RUN chmod 750 /app/sandbox/libjudger.so -ENTRYPOINT ["./iris"] +COPY ./entrypoint.sh . + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/apps/iris/entrypoint.sh b/apps/iris/entrypoint.sh new file mode 100755 index 0000000000..60eeabf0c3 --- /dev/null +++ b/apps/iris/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash +if [[ -n "$APP_ENV" && $APP_ENV = "production" ]] + then ECS_CONTAINER_ID=$(head -1 /proc/self/cgroup | cut -d/ -f4) + ./iris $ECS_CONTAINER_ID +else + ./iris +fi \ No newline at end of file diff --git a/apps/iris/main.go b/apps/iris/main.go index 7b890d4eb0..97af007e46 100644 --- a/apps/iris/main.go +++ b/apps/iris/main.go @@ -28,17 +28,19 @@ const ( ) func main() { + // profile() env := Env(utils.Getenv("APP_ENV", "stage")) logProvider := logger.NewLogger(logger.Console, env == Production) ctx := context.Background() - cache := cache.NewCache(ctx) if env == "production" { + // load container Id from args + containerId := os.Args[1] if utils.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT_URL", "") != "" { shutdown := observability.InitTracer(ctx) defer shutdown() - observability.SetGlobalMeterProvider() + observability.SetGlobalMeterProvider(containerId) // Aynchronous Instruments로써, go routine 불필요 observability.GetMemoryMeter(otel.Meter("memory-metrics")) observability.GetCPUMeter(otel.Meter("cpu-metrics"), 15*time.Second) @@ -49,6 +51,8 @@ func main() { logProvider.Log(logger.INFO, "Running in stage mode") } + cache := cache.NewCache(ctx) + bucketName := os.Getenv("TESTCASE_BUCKET_NAME") if bucketName == "" { logProvider.Log(logger.ERROR, "Cannot find TESTCASE_BUCKET_NAME") diff --git a/apps/iris/src/observability/metric.go b/apps/iris/src/observability/metric.go index 50ca2db58c..d5ecdfe75d 100644 --- a/apps/iris/src/observability/metric.go +++ b/apps/iris/src/observability/metric.go @@ -21,9 +21,9 @@ import ( const defaultMetricDuration time.Duration = 3 * time.Second -func SetGlobalMeterProvider() { +func SetGlobalMeterProvider(containerId string) { // Create resource. - res, err := newMetricResource() + res, err := newMetricResource(containerId) if err != nil { reportErr(err, "failed to create metric resource") } @@ -44,12 +44,13 @@ func SetGlobalMeterProvider() { otel.SetMeterProvider(meterProvider) } -func newMetricResource() (*resource.Resource, error) { +func newMetricResource(containerId string) (*resource.Resource, error) { return resource.Merge(resource.Default(), resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceName("iris-metric"), semconv.ServiceVersion("0.1.0"), semconv.ServiceInstanceID(getInstanceId()), + semconv.ContainerID(containerId), )) }