Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] make telemetrygen build faster #30989

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/telemetrygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
pull_request:
env:
# Make sure to exit early if cache segment download times out after 2 minutes.
# We limit cache download as a whole to 5 minutes.
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2

# Do not cancel this workflow on main. See https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/16616
concurrency:
Expand All @@ -17,10 +21,30 @@ jobs:
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ~1.20.12
cache: false
- name: Cache Go
id: go-cache
timeout-minutes: 5
uses: actions/cache@v3
with:
path: |
~/go/bin
~/go/pkg/mod
key: go-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build binaries
run: |
GOOS=linux GOARCH=ppc64le make telemetrygen
GOOS=linux GOARCH=arm64 make telemetrygen
GOOS=linux GOARCH=amd64 make telemetrygen
GOOS=linux GOARCH=s390x make telemetrygen
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
cp bin/telemetrygen_* cmd/telemetrygen/
- name: Build telemetrygen
uses: docker/build-push-action@v5
with:
Expand All @@ -36,6 +60,19 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ~1.20.12
cache: false
- name: Cache Go
id: go-cache
timeout-minutes: 5
uses: actions/cache@v3
with:
path: |
~/go/bin
~/go/pkg/mod
key: go-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand All @@ -46,6 +83,13 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build binaries
run: |
GOOS=linux GOARCH=ppc64le make telemetrygen
GOOS=linux GOARCH=arm64 make telemetrygen
GOOS=linux GOARCH=amd64 make telemetrygen
GOOS=linux GOARCH=s390x make telemetrygen
cp bin/telemetrygen_* cmd/telemetrygen/
- name: Push telemetrygen to Github packages
uses: docker/build-push-action@v5
with:
Expand All @@ -61,6 +105,19 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ~1.20.12
cache: false
- name: Cache Go
id: go-cache
timeout-minutes: 5
uses: actions/cache@v3
with:
path: |
~/go/bin
~/go/pkg/mod
key: go-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand All @@ -74,6 +131,13 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build binaries
run: |
GOOS=linux GOARCH=ppc64le make telemetrygen
GOOS=linux GOARCH=arm64 make telemetrygen
GOOS=linux GOARCH=amd64 make telemetrygen
GOOS=linux GOARCH=s390x make telemetrygen
cp bin/telemetrygen_* cmd/telemetrygen/
- name: Push telemetrygen to Github packages
uses: docker/build-push-action@v5
with:
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ docker-otelcontribcol:

.PHONY: docker-telemetrygen
docker-telemetrygen:
COMPONENT=telemetrygen $(MAKE) docker-component
GOOS=linux GOARCH=$(GOARCH) $(MAKE) telemetrygen
cp bin/telemetrygen_* cmd/telemetrygen/
cd cmd/telemetrygen && docker build --platform linux/$(GOARCH) -t telemetrygen:latest .
rm cmd/telemetrygen/telemetrygen_*

.PHONY: generate
generate: install-tools
Expand Down
12 changes: 4 additions & 8 deletions cmd/telemetrygen/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
FROM golang:1.21 AS build

WORKDIR /src
ADD . /src

RUN CGO_ENABLED=0 go build -o /telemetrygen

FROM alpine:latest as certs
RUN apk --update add ca-certificates

Expand All @@ -13,7 +6,10 @@ FROM scratch
ARG USER_UID=10001
USER ${USER_UID}

ARG TARGETOS
ARG TARGETARCH

COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=build /telemetrygen /telemetrygen
COPY ./telemetrygen_${TARGETOS}_${TARGETARCH} /telemetrygen

ENTRYPOINT ["/telemetrygen"]
10 changes: 10 additions & 0 deletions cmd/telemetrygen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ go install github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemet

Check the [`go install` reference](https://go.dev/ref/mod#go-install) to install specific versions.

### Docker build

You can build locally the Docker image with:

```bash
make docker-telemetrygen
```

Using github actions, we also push a docker image on commit to main or on release to this [Github docker registry](https://github.com/open-telemetry/opentelemetry-collector-contrib/pkgs/container/opentelemetry-collector-contrib%2Ftelemetrygen).

## Running

First, you'll need an OpenTelemetry Collector to receive the telemetry data. Follow the project's instructions for a detailed setting up guide. The following configuration file should be sufficient:
Expand Down
Loading