Skip to content

Commit

Permalink
feat(cd): edit iris dockerfile to run sh to get containerId (#1679)
Browse files Browse the repository at this point in the history
feat(infra): add containerId parameter on metric code
  • Loading branch information
goathoon authored May 10, 2024
1 parent 6a2f5a7 commit 9cb4046
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
7 changes: 4 additions & 3 deletions apps/iris/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
7 changes: 7 additions & 0 deletions apps/iris/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions apps/iris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions apps/iris/src/observability/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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),
))
}

Expand Down

0 comments on commit 9cb4046

Please sign in to comment.