Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Set Metrics configuration using ldlfags (#1088)
Browse files Browse the repository at this point in the history
## Description

This sets up the metrics configs using `ldflags`. Keeping it in draft as I wanted to wait till #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 #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
  • Loading branch information
meain authored Oct 14, 2022
1 parent 4b94c4f commit 2d30f4a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions src/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/internal/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand Down

0 comments on commit 2d30f4a

Please sign in to comment.