From 56c1064f934fd766b3778a4c31274c050bd5ab16 Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:29:31 -0700 Subject: [PATCH 01/11] dx: introduce HYPERDX_API_* + HYPERDX_APP_* env vars --- .env | 6 ++++++ docker-compose.yml | 20 ++++++++++---------- packages/api/Dockerfile | 6 +++++- packages/app/Dockerfile | 6 ++++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.env b/.env index b3ed11c8e..8e544472d 100644 --- a/.env +++ b/.env @@ -1,2 +1,8 @@ IMAGE_NAME=ghcr.io/hyperdxio/hyperdx IMAGE_VERSION=1.1.1 + +# Set up domain URLs +HYPERDX_API_PORT=8000 +HYPERDX_API_URL=http://localhost +HYPERDX_APP_PORT=8080 +HYPERDX_APP_URL=http://localhost diff --git a/docker-compose.yml b/docker-compose.yml index 29d60a640..509ecbd4c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -80,12 +80,12 @@ services: CLICKHOUSE_HOST: http://ch-server:8123 CLICKHOUSE_PASSWORD: aggregator CLICKHOUSE_USER: aggregator - FRONTEND_URL: 'http://localhost:8080' # need to be localhost (CORS) + FRONTEND_URL: ${HYPERDX_APP_URL} # need to be localhost (CORS) MONGO_URI: 'mongodb://db:27017/hyperdx' NODE_ENV: development PORT: 8001 REDIS_URL: redis://redis:6379 - SERVER_URL: 'http://localhost:8000' + SERVER_URL: ${HYPERDX_API_URL} networks: - internal depends_on: @@ -103,7 +103,7 @@ services: CLICKHOUSE_LOG_LEVEL: trace CLICKHOUSE_PASSWORD: worker CLICKHOUSE_USER: worker - FRONTEND_URL: 'http://localhost:8080' # need to be localhost (CORS) + FRONTEND_URL: ${HYPERDX_APP_URL} # need to be localhost (CORS) HDX_NODE_ADVANCED_NETWORK_CAPTURE: 1 HDX_NODE_BETA_MODE: 0 HDX_NODE_CONSOLE_CAPTURE: 1 @@ -126,7 +126,7 @@ services: image: ${IMAGE_NAME}:${IMAGE_VERSION}-api container_name: hdx-oss-api ports: - - 8000:8000 + - ${HYPERDX_API_PORT}:${HYPERDX_API_PORT} environment: AGGREGATOR_API_URL: 'http://aggregator:8001' APP_TYPE: 'api' @@ -135,7 +135,7 @@ services: CLICKHOUSE_PASSWORD: api CLICKHOUSE_USER: api EXPRESS_SESSION_SECRET: 'hyperdx is cool 👋' - FRONTEND_URL: 'http://localhost:8080' # need to be localhost (CORS) + FRONTEND_URL: ${HYPERDX_APP_URL} # need to be localhost (CORS) HDX_NODE_ADVANCED_NETWORK_CAPTURE: 1 HDX_NODE_BETA_MODE: 1 HDX_NODE_CONSOLE_CAPTURE: 1 @@ -146,9 +146,9 @@ services: NODE_ENV: development OTEL_EXPORTER_OTLP_ENDPOINT: 'http://otel-collector:4318' OTEL_SERVICE_NAME: 'hdx-oss-api' - PORT: 8000 + PORT: ${HYPERDX_API_PORT} REDIS_URL: redis://redis:6379 - SERVER_URL: 'http://localhost:8000' + SERVER_URL: ${HYPERDX_API_URL}:${HYPERDX_API_PORT} USAGE_STATS_ENABLED: ${USAGE_STATS_ENABLED:-true} networks: - internal @@ -160,14 +160,14 @@ services: image: ${IMAGE_NAME}:${IMAGE_VERSION}-app container_name: hdx-oss-app ports: - - 8080:8080 + - ${HYPERDX_APP_PORT}:${HYPERDX_APP_PORT} environment: - NEXT_PUBLIC_API_SERVER_URL: 'http://localhost:8000' # need to be localhost (CORS) + NEXT_PUBLIC_API_SERVER_URL: ${HYPERDX_API_URL}:${HYPERDX_API_PORT} # need to be localhost (CORS) NEXT_PUBLIC_HDX_API_KEY: ${HYPERDX_API_KEY} NEXT_PUBLIC_HDX_COLLECTOR_URL: 'http://localhost:4318' NEXT_PUBLIC_HDX_SERVICE_NAME: 'hdx-oss-app' NODE_ENV: development - PORT: 8080 + PORT: ${HYPERDX_APP_PORT} networks: - internal depends_on: diff --git a/packages/api/Dockerfile b/packages/api/Dockerfile index ced284be9..74272f14e 100644 --- a/packages/api/Dockerfile +++ b/packages/api/Dockerfile @@ -34,7 +34,11 @@ ARG CODE_VERSION ENV CODE_VERSION=$CODE_VERSION -EXPOSE 8000 +ARG PORT + +ENV PORT=$PORT + +EXPOSE ${PORT} USER node diff --git a/packages/app/Dockerfile b/packages/app/Dockerfile index 10fc05d78..8ed6bf2e4 100644 --- a/packages/app/Dockerfile +++ b/packages/app/Dockerfile @@ -53,9 +53,11 @@ COPY --from=builder /app/package.json ./package.json USER nextjs -EXPOSE 8080 +ARG PORT + +ENV PORT=$PORT -ENV PORT 8080 +EXPOSE ${PORT} # Next.js collects completely anonymous telemetry data about general usage. # Learn more here: https://nextjs.org/telemetry From ddeef73aed3a37e24c3c4fe13546e9e2647d9e6f Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Thu, 21 Sep 2023 15:35:08 -0700 Subject: [PATCH 02/11] feat: local-build cli + update compose file --- .env | 1 + Makefile | 29 ++++++++++++++++++++++++++--- docker-compose.yml | 22 +++++++++++----------- packages/app/Dockerfile | 15 +++++++++++---- packages/app/src/config.ts | 10 +++++----- 5 files changed, 54 insertions(+), 23 deletions(-) diff --git a/.env b/.env index 8e544472d..7755b1190 100644 --- a/.env +++ b/.env @@ -6,3 +6,4 @@ HYPERDX_API_PORT=8000 HYPERDX_API_URL=http://localhost HYPERDX_APP_PORT=8080 HYPERDX_APP_URL=http://localhost + diff --git a/Makefile b/Makefile index a3e155f53..60706d021 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,20 @@ dev-int: ci-int: docker compose -p int -f ./docker-compose.ci.yml run --rm api ci:int +.PHONY: build-local-app +build-local: + docker build \ + --build-arg CODE_VERSION=${LATEST_VERSION} \ + --build-arg PORT=${HYPERDX_API_PORT} \ + . -f ./packages/api/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-api --target prod + docker build \ + --build-arg CODE_VERSION=${LATEST_VERSION} \ + --build-arg HYPERDX_API_KEY=${HYPERDX_API_KEY} \ + --build-arg OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT} \ + --build-arg OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME} \ + --build-arg PORT=${HYPERDX_APP_PORT} \ + --build-arg SERVER_URL=${HYPERDX_API_URL}:${HYPERDX_API_PORT} \ + . -f ./packages/app/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-app --target prod .PHONY: build-and-push-ghcr build-and-push-ghcr: @@ -46,7 +60,16 @@ build-and-push-ghcr: docker buildx build --platform ${BUILD_PLATFORMS} ./docker/ingestor -t ${IMAGE_NAME}:${LATEST_VERSION}-ingestor --target prod --push & docker buildx build --platform ${BUILD_PLATFORMS} ./docker/otel-collector -t ${IMAGE_NAME}:${LATEST_VERSION}-otel-collector --target prod --push & docker buildx build --build-arg CODE_VERSION=${LATEST_VERSION} --platform ${BUILD_PLATFORMS} . -f ./packages/miner/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-miner --target prod --push & - docker buildx build --build-arg CODE_VERSION=${LATEST_VERSION} --platform ${BUILD_PLATFORMS} . -f ./packages/api/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-api --target prod --push & - docker buildx build --build-arg CODE_VERSION=${LATEST_VERSION} --platform ${BUILD_PLATFORMS} . -f ./packages/app/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-app --target prod --push - + docker buildx build \ + --build-arg CODE_VERSION=${LATEST_VERSION} \ + --build-arg PORT=${HYPERDX_API_PORT} \ + --platform ${BUILD_PLATFORMS} . -f ./packages/api/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-api --target prod --push & + docker buildx build \ + --build-arg CODE_VERSION=${LATEST_VERSION} \ + --build-arg HYPERDX_API_KEY=${HYPERDX_API_KEY} \ + --build-arg OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT} \ + --build-arg OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME} \ + --build-arg PORT=${HYPERDX_APP_PORT} \ + --build-arg SERVER_URL=${HYPERDX_API_URL}:${HYPERDX_API_PORT} \ + --platform ${BUILD_PLATFORMS} . -f ./packages/app/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-app --target prod --push diff --git a/docker-compose.yml b/docker-compose.yml index 509ecbd4c..639b67a9e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -80,12 +80,12 @@ services: CLICKHOUSE_HOST: http://ch-server:8123 CLICKHOUSE_PASSWORD: aggregator CLICKHOUSE_USER: aggregator - FRONTEND_URL: ${HYPERDX_APP_URL} # need to be localhost (CORS) + FRONTEND_URL: ${HYPERDX_APP_URL}:${HYPERDX_APP_PORT} # need to be localhost (CORS) MONGO_URI: 'mongodb://db:27017/hyperdx' NODE_ENV: development PORT: 8001 REDIS_URL: redis://redis:6379 - SERVER_URL: ${HYPERDX_API_URL} + SERVER_URL: ${HYPERDX_API_URL}:${HYPERDX_API_PORT} networks: - internal depends_on: @@ -103,7 +103,7 @@ services: CLICKHOUSE_LOG_LEVEL: trace CLICKHOUSE_PASSWORD: worker CLICKHOUSE_USER: worker - FRONTEND_URL: ${HYPERDX_APP_URL} # need to be localhost (CORS) + FRONTEND_URL: ${HYPERDX_APP_URL}:${HYPERDX_APP_PORT} # need to be localhost (CORS) HDX_NODE_ADVANCED_NETWORK_CAPTURE: 1 HDX_NODE_BETA_MODE: 0 HDX_NODE_CONSOLE_CAPTURE: 1 @@ -135,7 +135,7 @@ services: CLICKHOUSE_PASSWORD: api CLICKHOUSE_USER: api EXPRESS_SESSION_SECRET: 'hyperdx is cool 👋' - FRONTEND_URL: ${HYPERDX_APP_URL} # need to be localhost (CORS) + FRONTEND_URL: ${HYPERDX_APP_URL}:${HYPERDX_APP_PORT} # need to be localhost (CORS) HDX_NODE_ADVANCED_NETWORK_CAPTURE: 1 HDX_NODE_BETA_MODE: 1 HDX_NODE_CONSOLE_CAPTURE: 1 @@ -161,13 +161,13 @@ services: container_name: hdx-oss-app ports: - ${HYPERDX_APP_PORT}:${HYPERDX_APP_PORT} - environment: - NEXT_PUBLIC_API_SERVER_URL: ${HYPERDX_API_URL}:${HYPERDX_API_PORT} # need to be localhost (CORS) - NEXT_PUBLIC_HDX_API_KEY: ${HYPERDX_API_KEY} - NEXT_PUBLIC_HDX_COLLECTOR_URL: 'http://localhost:4318' - NEXT_PUBLIC_HDX_SERVICE_NAME: 'hdx-oss-app' - NODE_ENV: development - PORT: ${HYPERDX_APP_PORT} + # environment: + # NEXT_PUBLIC_SERVER_URL: ${HYPERDX_API_URL}:${HYPERDX_API_PORT} # need to be localhost (CORS) + # NEXT_PUBLIC_HYPERDX_API_KEY: ${HYPERDX_API_KEY} + # NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT: 'http://localhost:4318' + # NEXT_PUBLIC_OTEL_SERVICE_NAME: 'hdx-oss-app' + # NODE_ENV: development + # PORT: ${HYPERDX_APP_PORT} networks: - internal depends_on: diff --git a/packages/app/Dockerfile b/packages/app/Dockerfile index 8ed6bf2e4..82ce6cf15 100644 --- a/packages/app/Dockerfile +++ b/packages/app/Dockerfile @@ -22,9 +22,16 @@ CMD ["dev"] # Rebuild the source code only when needed FROM base AS builder -# Expose NEXT_PUBLIC_API_SERVER_URL during build time if needed -ARG NEXT_PUBLIC_API_SERVER_URL -ENV NEXT_PUBLIC_API_SERVER_URL $NEXT_PUBLIC_API_SERVER_URL +# Expose custom env variables to the browser (needs NEXT_PUBLIC_ prefix) +# doc: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser +ARG HYPERDX_API_KEY +ARG OTEL_EXPORTER_OTLP_ENDPOINT +ARG OTEL_SERVICE_NAME +ARG SERVER_URL +ENV NEXT_PUBLIC_HYPERDX_API_KEY $HYPERDX_API_KEY +ENV NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT $OTEL_EXPORTER_OTLP_ENDPOINT +ENV NEXT_PUBLIC_OTEL_SERVICE_NAME $OTEL_SERVICE_NAME +ENV NEXT_PUBLIC_SERVER_URL $SERVER_URL COPY ./packages/app/tsconfig.json ./packages/app/next.config.js ./packages/app/mdx.d.ts ./packages/app/.eslintrc.js ./ COPY ./packages/app/src ./src @@ -64,4 +71,4 @@ EXPOSE ${PORT} # Uncomment the following line in case you want to disable telemetry. ENV NEXT_TELEMETRY_DISABLED 1 -CMD ["node_modules/.bin/next", "start"] +CMD ["node_modules/.bin/next", "start", "-p", "${PORT}"] diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index 8aef38df8..56911290d 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -1,11 +1,11 @@ export const API_SERVER_URL = - process.env.NEXT_PUBLIC_API_SERVER_URL || 'http://localhost:8000'; // NEXT_PUBLIC_API_SERVER_URL can be empty string + process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:8000'; // NEXT_PUBLIC_API_SERVER_URL can be empty string -export const HDX_API_KEY = (process.env.NEXT_PUBLIC_HDX_API_KEY || - process.env.HYPERDX_API_KEY) as string; +export const HDX_API_KEY = process.env.NEXT_PUBLIC_HYPERDX_API_KEY as string; export const HDX_SERVICE_NAME = - process.env.NEXT_PUBLIC_HDX_SERVICE_NAME || 'hdx-oss-dev-app'; + process.env.NEXT_PUBLIC_OTEL_SERVICE_NAME || 'hdx-oss-dev-app'; export const HDX_COLLECTOR_URL = - process.env.NEXT_PUBLIC_HDX_COLLECTOR_URL || 'http://localhost:4318'; + process.env.NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT || + 'http://localhost:4318'; export const IS_OSS = process.env.NEXT_PUBLIC_IS_OSS ?? 'true' === 'true'; From c935cccc89fa939b819b13050c209e0ade58501a Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:04:10 -0700 Subject: [PATCH 03/11] style: cleanup build-local cli + inject api key (next server) --- Makefile | 5 +++-- docker-compose.yml | 10 +++------- packages/app/Dockerfile | 2 +- packages/app/src/config.ts | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 60706d021..27c8d12ef 100644 --- a/Makefile +++ b/Makefile @@ -39,12 +39,13 @@ dev-int: ci-int: docker compose -p int -f ./docker-compose.ci.yml run --rm api ci:int -.PHONY: build-local-app +# api + app services only +.PHONY: build-local build-local: docker build \ --build-arg CODE_VERSION=${LATEST_VERSION} \ --build-arg PORT=${HYPERDX_API_PORT} \ - . -f ./packages/api/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-api --target prod + . -f ./packages/api/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-api --target prod & docker build \ --build-arg CODE_VERSION=${LATEST_VERSION} \ --build-arg HYPERDX_API_KEY=${HYPERDX_API_KEY} \ diff --git a/docker-compose.yml b/docker-compose.yml index 639b67a9e..3c57bfe84 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -161,13 +161,9 @@ services: container_name: hdx-oss-app ports: - ${HYPERDX_APP_PORT}:${HYPERDX_APP_PORT} - # environment: - # NEXT_PUBLIC_SERVER_URL: ${HYPERDX_API_URL}:${HYPERDX_API_PORT} # need to be localhost (CORS) - # NEXT_PUBLIC_HYPERDX_API_KEY: ${HYPERDX_API_KEY} - # NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT: 'http://localhost:4318' - # NEXT_PUBLIC_OTEL_SERVICE_NAME: 'hdx-oss-app' - # NODE_ENV: development - # PORT: ${HYPERDX_APP_PORT} + environment: + NODE_ENV: development + PORT: ${HYPERDX_APP_PORT} networks: - internal depends_on: diff --git a/packages/app/Dockerfile b/packages/app/Dockerfile index 82ce6cf15..638e5400a 100644 --- a/packages/app/Dockerfile +++ b/packages/app/Dockerfile @@ -71,4 +71,4 @@ EXPOSE ${PORT} # Uncomment the following line in case you want to disable telemetry. ENV NEXT_TELEMETRY_DISABLED 1 -CMD ["node_modules/.bin/next", "start", "-p", "${PORT}"] +CMD ["sh", "-c", "node_modules/.bin/next start -p ${PORT}"] diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index 56911290d..ac51fafb2 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -1,7 +1,7 @@ export const API_SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:8000'; // NEXT_PUBLIC_API_SERVER_URL can be empty string -export const HDX_API_KEY = process.env.NEXT_PUBLIC_HYPERDX_API_KEY as string; +export const HDX_API_KEY = process.env.HYPERDX_API_KEY as string; // for nextjs server export const HDX_SERVICE_NAME = process.env.NEXT_PUBLIC_OTEL_SERVICE_NAME || 'hdx-oss-dev-app'; export const HDX_COLLECTOR_URL = From 22f4c59d2dea17a8f5a58660fa5ca9df3f5c7a64 Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:15:58 -0700 Subject: [PATCH 04/11] style: remove HYPERDX_API_KEYP from frontend build --- docker-compose.yml | 1 + packages/app/Dockerfile | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3c57bfe84..de4b93d05 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -162,6 +162,7 @@ services: ports: - ${HYPERDX_APP_PORT}:${HYPERDX_APP_PORT} environment: + HYPERDX_API_KEY: ${HYPERDX_API_KEY} NODE_ENV: development PORT: ${HYPERDX_APP_PORT} networks: diff --git a/packages/app/Dockerfile b/packages/app/Dockerfile index 638e5400a..e44a2ab6c 100644 --- a/packages/app/Dockerfile +++ b/packages/app/Dockerfile @@ -24,11 +24,9 @@ FROM base AS builder # Expose custom env variables to the browser (needs NEXT_PUBLIC_ prefix) # doc: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser -ARG HYPERDX_API_KEY ARG OTEL_EXPORTER_OTLP_ENDPOINT ARG OTEL_SERVICE_NAME ARG SERVER_URL -ENV NEXT_PUBLIC_HYPERDX_API_KEY $HYPERDX_API_KEY ENV NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT $OTEL_EXPORTER_OTLP_ENDPOINT ENV NEXT_PUBLIC_OTEL_SERVICE_NAME $OTEL_SERVICE_NAME ENV NEXT_PUBLIC_SERVER_URL $SERVER_URL From c3d1707300bab60359e4449fc5ea0eb625259bdb Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:28:10 -0700 Subject: [PATCH 05/11] feat: add default OTEL_EXPORTER_OTLP_ENDPOINT to .env --- .env | 1 + 1 file changed, 1 insertion(+) diff --git a/.env b/.env index 7755b1190..980325e1e 100644 --- a/.env +++ b/.env @@ -6,4 +6,5 @@ HYPERDX_API_PORT=8000 HYPERDX_API_URL=http://localhost HYPERDX_APP_PORT=8080 HYPERDX_APP_URL=http://localhost +OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 From fa773fdd4ef3a53c862b3f9cba22e2512ea365e6 Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:36:10 -0700 Subject: [PATCH 06/11] style: remove unused build arg --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 27c8d12ef..6d8427dac 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,6 @@ build-local: . -f ./packages/api/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-api --target prod & docker build \ --build-arg CODE_VERSION=${LATEST_VERSION} \ - --build-arg HYPERDX_API_KEY=${HYPERDX_API_KEY} \ --build-arg OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT} \ --build-arg OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME} \ --build-arg PORT=${HYPERDX_APP_PORT} \ @@ -67,7 +66,6 @@ build-and-push-ghcr: --platform ${BUILD_PLATFORMS} . -f ./packages/api/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-api --target prod --push & docker buildx build \ --build-arg CODE_VERSION=${LATEST_VERSION} \ - --build-arg HYPERDX_API_KEY=${HYPERDX_API_KEY} \ --build-arg OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT} \ --build-arg OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME} \ --build-arg PORT=${HYPERDX_APP_PORT} \ From 35e91b324e0c90bd3e49ebf2091e9761e0b50430 Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:34:43 -0700 Subject: [PATCH 07/11] feat: add commands to build the rest of services --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6d8427dac..5aa0965d6 100644 --- a/Makefile +++ b/Makefile @@ -39,9 +39,12 @@ dev-int: ci-int: docker compose -p int -f ./docker-compose.ci.yml run --rm api ci:int -# api + app services only .PHONY: build-local build-local: + docker build ./docker/hostmetrics -t ${IMAGE_NAME}:${LATEST_VERSION}-hostmetrics --target prod & + docker build ./docker/ingestor -t ${IMAGE_NAME}:${LATEST_VERSION}-ingestor --target prod & + docker build ./docker/otel-collector -t ${IMAGE_NAME}:${LATEST_VERSION}-otel-collector --target prod & + docker build --build-arg CODE_VERSION=${LATEST_VERSION} . -f ./packages/miner/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-miner --target prod & docker build \ --build-arg CODE_VERSION=${LATEST_VERSION} \ --build-arg PORT=${HYPERDX_API_PORT} \ From 86dfb0a9e2481a6185db0129b67f134cea8104fa Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:43:59 -0700 Subject: [PATCH 08/11] doc: add comment --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index 980325e1e..35ce9e857 100644 --- a/.env +++ b/.env @@ -6,5 +6,5 @@ HYPERDX_API_PORT=8000 HYPERDX_API_URL=http://localhost HYPERDX_APP_PORT=8080 HYPERDX_APP_URL=http://localhost -OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 +OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 # port is fixed From a01a8a9225d7576d9b5997edee9d7d5258b4bd20 Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:04:02 -0700 Subject: [PATCH 09/11] feat: add version script --- Makefile | 4 ++++ version.sh | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 version.sh diff --git a/Makefile b/Makefile index 5aa0965d6..46d602f6d 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,10 @@ build-local: --build-arg SERVER_URL=${HYPERDX_API_URL}:${HYPERDX_API_PORT} \ . -f ./packages/app/Dockerfile -t ${IMAGE_NAME}:${LATEST_VERSION}-app --target prod +.PHONY: version +version: + sh ./version.sh + .PHONY: build-and-push-ghcr build-and-push-ghcr: docker buildx build --platform ${BUILD_PLATFORMS} ./docker/hostmetrics -t ${IMAGE_NAME}:${LATEST_VERSION}-hostmetrics --target prod --push & diff --git a/version.sh b/version.sh new file mode 100755 index 000000000..f3675e30e --- /dev/null +++ b/version.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +yarn changeset version + +# update root package.json version +API_LATEST_VERSION=$(sed -n 's/.*"version": "\([^"]*\)".*/\1/p' ./packages/api/package.json) +APP_LATEST_VERSION=$(sed -n 's/.*"version": "\([^"]*\)".*/\1/p' ./packages/app/package.json) + +# check if api and app versions are the same +if [ "$API_LATEST_VERSION" != "$APP_LATEST_VERSION" ]; then + echo "API and APP versions are not the same. Please check and try again." + exit 1 +fi + +# update root package.json version +sed -i '' -e "s/\"version\": \".*\"/\"version\": \"$API_LATEST_VERSION\"/g" ./package.json + +echo "Updated root package.json version to $API_LATEST_VERSION" +echo "Run 'make build-and-push-ghcr' to publish new version to GHCR" From 4476bdfd6347b2bfffb7f7b06f0a8ad3c2a2793b Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:06:01 -0700 Subject: [PATCH 10/11] doc: add comment --- .env | 1 + 1 file changed, 1 insertion(+) diff --git a/.env b/.env index 35ce9e857..91c919a99 100644 --- a/.env +++ b/.env @@ -1,3 +1,4 @@ +# Used by docker-compose.yml IMAGE_NAME=ghcr.io/hyperdxio/hyperdx IMAGE_VERSION=1.1.1 From 59252abd25b22d75a6c46dc53e2a0874cddf885d Mon Sep 17 00:00:00 2001 From: Warren <5959690+wrn14897@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:34:50 -0700 Subject: [PATCH 11/11] fix: dynamicall update the tracePropagationTargets (from api url) --- packages/app/pages/_app.tsx | 11 ++++++++++- packages/app/pages/api/config.ts | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/app/pages/_app.tsx b/packages/app/pages/_app.tsx index 7a41cf573..719c1cec1 100644 --- a/packages/app/pages/_app.tsx +++ b/packages/app/pages/_app.tsx @@ -29,15 +29,24 @@ export default function MyApp({ Component, pageProps }: AppProps) { .then(res => res.json()) .then(_jsonData => { if (_jsonData?.apiKey) { + let hostname; + try { + const url = new URL(_jsonData.apiServerUrl); + hostname = url.hostname; + } catch (err) { + // console.log(err); + } HyperDX.init({ apiKey: _jsonData.apiKey, consoleCapture: true, maskAllInputs: true, maskAllText: true, service: _jsonData.serviceName, - tracePropagationTargets: [/localhost/i, /hyperdx\.io/i], + tracePropagationTargets: [new RegExp(hostname ?? 'localhost', 'i')], url: _jsonData.collectorUrl, }); + } else { + console.warn('No API key found'); } }) .catch(err => { diff --git a/packages/app/pages/api/config.ts b/packages/app/pages/api/config.ts index 7c88fa2e0..fa25f3d2b 100644 --- a/packages/app/pages/api/config.ts +++ b/packages/app/pages/api/config.ts @@ -1,6 +1,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { + API_SERVER_URL, HDX_API_KEY, HDX_COLLECTOR_URL, HDX_SERVICE_NAME, @@ -8,6 +9,7 @@ import { type ResponseData = { apiKey: string; + apiServerUrl: string; collectorUrl: string; serviceName: string; }; @@ -18,6 +20,7 @@ export default function handler( ) { res.status(200).json({ apiKey: HDX_API_KEY, + apiServerUrl: API_SERVER_URL, collectorUrl: HDX_COLLECTOR_URL, serviceName: HDX_SERVICE_NAME, });