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

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [x] 💻 CI/Deployment
- [ ] 🐹 Trivial/Minor

## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #1067

## Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abin Simon 2022-10-14 09:07:37 +05:30 committed by GitHub
parent 4b94c4f012
commit 2d30f4a999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View File

@ -242,6 +242,8 @@ jobs:
workdir: src workdir: src
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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 - name: Upload assets
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
@ -305,6 +307,7 @@ jobs:
- name: Build Corso Binaries - name: Build Corso Binaries
run: > 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 ./build.sh
--platforms ${{ env.PLATFORMS }} --platforms ${{ env.PLATFORMS }}

View File

@ -63,7 +63,7 @@ do
--env GOARCH=${GOARCH} \ --env GOARCH=${GOARCH} \
--entrypoint /usr/local/go/bin/go \ --entrypoint /usr/local/go/bin/go \
golang:${GOVER} \ golang:${GOVER} \
build -o corso ${CORSO_BUILD_ARGS} build -o corso ${CORSO_BUILD_ARGS} -ldflags "${CORSO_BUILD_LDFLAGS}"
set +x set +x
mkdir -p ${PROJECT_ROOT}/bin/${GOOS}-${GOARCH} mkdir -p ${PROJECT_ROOT}/bin/${GOOS}-${GOARCH}

View File

@ -12,6 +12,10 @@ builds:
ignore: ignore:
- goos: windows - goos: windows
goarch: arm64 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: archives:
- replacements: - replacements:
darwin: Darwin darwin: Darwin

View File

@ -57,8 +57,8 @@ type Bus struct {
} }
var ( var (
WriteKey string RudderStackWriteKey string
DataPlaneURL string RudderStackDataPlaneURL string
) )
func NewBus(s storage.Storage, tenID string, opts control.Options) Bus { 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") envWK := os.Getenv("RUDDERSTACK_CORSO_WRITE_KEY")
if len(envWK) > 0 { if len(envWK) > 0 {
WriteKey = envWK RudderStackWriteKey = envWK
} }
envDPU := os.Getenv("RUDDERSTACK_CORSO_DATA_PLANE_URL") envDPU := os.Getenv("RUDDERSTACK_CORSO_DATA_PLANE_URL")
if len(envDPU) > 0 { if len(envDPU) > 0 {
DataPlaneURL = envDPU RudderStackDataPlaneURL = envDPU
} }
var client analytics.Client var client analytics.Client
if len(WriteKey) > 0 && len(DataPlaneURL) > 0 { if len(RudderStackWriteKey) > 0 && len(RudderStackDataPlaneURL) > 0 {
client = analytics.New(WriteKey, DataPlaneURL) client = analytics.New(RudderStackWriteKey, RudderStackDataPlaneURL)
} }
return Bus{ return Bus{