From 2d30f4a999a27ec6bc4f30da21db96adc2d7d399 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 14 Oct 2022 09:07:37 +0530 Subject: [PATCH] Set Metrics configuration using ldlfags (#1088) ## Description This sets up the metrics configs using `ldflags`. Keeping it in draft as I wanted to wait till https://github.com/alcionai/corso/pull/1052 is merged as that will affect how we use it in the CI. I have currently set the base branch to `release-ci` on GH, the branch for https://github.com/alcionai/corso/pull/1052 instead of `main` as the diff would make more sense that way. ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [x] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Issue(s) * #1067 ## Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- .github/workflows/ci.yml | 3 +++ build/build.sh | 2 +- src/.goreleaser.yaml | 4 ++++ src/internal/events/events.go | 12 ++++++------ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b5b3092c3..38ff07d66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -242,6 +242,8 @@ jobs: workdir: src env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RUDDERSTACK_CORSO_WRITE_KEY: ${{ secrets.RUDDERSTACK_CORSO_WRITE_KEY }} + RUDDERSTACK_CORSO_DATA_PLANE_URL: ${{ secrets.RUDDERSTACK_CORSO_DATA_PLANE_URL }} - name: Upload assets uses: actions/upload-artifact@v3 @@ -305,6 +307,7 @@ jobs: - name: Build Corso Binaries run: > + export CORSO_BUILD_LDFLAGS="-X 'github.com/alcionai/corso/src/internal/events.RudderStackWriteKey=${{ secrets.RUDDERSTACK_CORSO_WRITE_KEY }}' -X 'github.com/alcionai/corso/src/internal/events.RudderStackDataPlaneURL=${{ secrets.RUDDERSTACK_CORSO_DATA_PLANE_URL }}'" ./build.sh --platforms ${{ env.PLATFORMS }} diff --git a/build/build.sh b/build/build.sh index 19502092a..aff255902 100755 --- a/build/build.sh +++ b/build/build.sh @@ -63,7 +63,7 @@ do --env GOARCH=${GOARCH} \ --entrypoint /usr/local/go/bin/go \ golang:${GOVER} \ - build -o corso ${CORSO_BUILD_ARGS} + build -o corso ${CORSO_BUILD_ARGS} -ldflags "${CORSO_BUILD_LDFLAGS}" set +x mkdir -p ${PROJECT_ROOT}/bin/${GOOS}-${GOARCH} diff --git a/src/.goreleaser.yaml b/src/.goreleaser.yaml index 8f251243f..e3ab77689 100644 --- a/src/.goreleaser.yaml +++ b/src/.goreleaser.yaml @@ -12,6 +12,10 @@ builds: ignore: - goos: windows goarch: arm64 + ldflags: + - -X 'github.com/alcionai/corso/src/internal/events.RudderStackWriteKey={{.Env.RUDDERSTACK_CORSO_WRITE_KEY}}' + - -X 'github.com/alcionai/corso/src/internal/events.RudderStackDataPlaneURL={{.Env.RUDDERSTACK_CORSO_DATA_PLANE_URL}}' + archives: - replacements: darwin: Darwin diff --git a/src/internal/events/events.go b/src/internal/events/events.go index 414dd5a7f..3f63bd787 100644 --- a/src/internal/events/events.go +++ b/src/internal/events/events.go @@ -57,8 +57,8 @@ type Bus struct { } var ( - WriteKey string - DataPlaneURL string + RudderStackWriteKey string + RudderStackDataPlaneURL string ) func NewBus(s storage.Storage, tenID string, opts control.Options) Bus { @@ -70,17 +70,17 @@ func NewBus(s storage.Storage, tenID string, opts control.Options) Bus { envWK := os.Getenv("RUDDERSTACK_CORSO_WRITE_KEY") if len(envWK) > 0 { - WriteKey = envWK + RudderStackWriteKey = envWK } envDPU := os.Getenv("RUDDERSTACK_CORSO_DATA_PLANE_URL") if len(envDPU) > 0 { - DataPlaneURL = envDPU + RudderStackDataPlaneURL = envDPU } var client analytics.Client - if len(WriteKey) > 0 && len(DataPlaneURL) > 0 { - client = analytics.New(WriteKey, DataPlaneURL) + if len(RudderStackWriteKey) > 0 && len(RudderStackDataPlaneURL) > 0 { + client = analytics.New(RudderStackWriteKey, RudderStackDataPlaneURL) } return Bus{