From 8fff2519f280665dab783d66125b07eda4214576 Mon Sep 17 00:00:00 2001 From: Vimal Kumar Date: Fri, 24 Nov 2023 09:47:09 +0530 Subject: [PATCH 1/2] chore(ci): make libbpf image as the default image - tag existing 'latest' image as 'latest-bcc' - tag existing 'latest-libbpf' as 'latest' - make libbpf image as default released image - use libbpf as attacher for PR image - make unit_test run with libbpf attacher - updated unit_test workflow to install libbpf from source - build kepler with libbpf attacher for rpm build - rename integration_test to integration_test_bcc - rename integration_test_libbpf to integration_test Signed-off-by: Vimal Kumar --- .github/workflows/image.yml | 12 +++++----- .github/workflows/image_pr.yml | 2 +- .github/workflows/integration_test.yml | 14 ++++++------ ...st_libbpf.yml => integration_test_bcc.yml} | 22 +++++++++---------- .github/workflows/pull_request.yml | 6 ++--- .github/workflows/release.yml | 6 ++--- .github/workflows/unit_test.yml | 15 ++++++++++--- Makefile | 3 ++- packaging/rpm/kepler.spec | 2 +- 9 files changed, 46 insertions(+), 36 deletions(-) rename .github/workflows/{integration_test_libbpf.yml => integration_test_bcc.yml} (91%) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index aa5ce36b23..810f4a80b4 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -25,14 +25,14 @@ jobs: username: ${{ secrets.username }} password: ${{ secrets.password }} - - name: Build and push kepler latest + - name: Build and push kepler latest (bcc) uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64 push: true - tags: quay.io/sustainable_computing_io/kepler:latest - labels: latest + tags: quay.io/sustainable_computing_io/kepler:latest-bcc + labels: latest-bcc file: build/Dockerfile - name: Build and push kepler latest (libbpf) @@ -41,6 +41,6 @@ jobs: context: . platforms: linux/amd64 push: true - tags: quay.io/sustainable_computing_io/kepler:latest-libbpf - labels: latest-libbpf - file: build/Dockerfile.libbpf.kepler \ No newline at end of file + tags: quay.io/sustainable_computing_io/kepler:latest + labels: latest + file: build/Dockerfile.libbpf.kepler diff --git a/.github/workflows/image_pr.yml b/.github/workflows/image_pr.yml index 107417c03d..6292c3dfae 100644 --- a/.github/workflows/image_pr.yml +++ b/.github/workflows/image_pr.yml @@ -35,4 +35,4 @@ jobs: push: true tags: quay.io/sustainable_computing_io/kepler labels: ${{ github.event.inputs.commitSHA }} - file: build/Dockerfile \ No newline at end of file + file: build/Dockerfile.libbpf.kepler diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 0b760734a4..f74dc21203 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -5,7 +5,7 @@ on: env: OUTPUT_DIR: "_output/" - FILE_NAME: "kepler.tar.gz" + FILE_NAME: "kepler_libbpf.tar.gz" ARTIFACT_DIR: "/tmp/artifacts" jobs: @@ -24,7 +24,7 @@ jobs: - name: install libbpf uses: sustainable-computing-io/kepler-action@v0.0.3 with: - ebpfprovider: bcc + ebpfprovider: libbpf # build kepler image - name: build and export Kepler image run: | @@ -32,21 +32,21 @@ jobs: make save-image env: IMAGE_REPO: "localhost:5001" - IMAGE_TAG: "devel" IMAGE_NAME: "kepler" + IMAGE_TAG: "devel" CTR_CMD: docker IMAGE_OUTPUT_PATH: ${{env.OUTPUT_DIR}}${{env.FILE_NAME}} # save kepler image - name: save Kepler image as artifact uses: actions/upload-artifact@v3 with: - name: kepler + name: keplerlibbpf path: ${{env.OUTPUT_DIR}}${{env.FILE_NAME}} retention-days: 1 # ref https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts # as PR or Push event, we don't keep artifact in 90 days hence use 1 day here to save resources. - integration_test: + integration_test_with_libbpf: needs: [build-kepler] runs-on: ubuntu-latest strategy: @@ -59,7 +59,7 @@ jobs: - name: download Kepler image artifact uses: actions/download-artifact@v3 with: - name: kepler + name: keplerlibbpf - name: build manifest run: make build-manifest OPTS="CI_DEPLOY" @@ -81,7 +81,7 @@ jobs: - name: use Kepler action to deploy cluster uses: sustainable-computing-io/kepler-action@v0.0.3 with: - ebpfprovider: bcc + ebpfprovider: libbpf cluster_provider: ${{matrix.cluster_provider}} local_dev_cluster_version: v0.0.3 diff --git a/.github/workflows/integration_test_libbpf.yml b/.github/workflows/integration_test_bcc.yml similarity index 91% rename from .github/workflows/integration_test_libbpf.yml rename to .github/workflows/integration_test_bcc.yml index e7e8e4eec9..10d136900e 100644 --- a/.github/workflows/integration_test_libbpf.yml +++ b/.github/workflows/integration_test_bcc.yml @@ -1,15 +1,15 @@ -name: Integration test with libbpf +name: Integration test with bcc on: workflow_call: env: OUTPUT_DIR: "_output/" - FILE_NAME: "kepler_libbpf.tar.gz" + FILE_NAME: "kepler-bcc.tar.gz" ARTIFACT_DIR: "/tmp/artifacts" jobs: - build-kepler_with_libbpf: + build-kepler-with-bcc: runs-on: ubuntu-latest steps: # checkout source code @@ -21,10 +21,10 @@ jobs: with: go-version-file: go.mod # set up ebpf - - name: install libbpf + - name: install bcc uses: sustainable-computing-io/kepler-action@v0.0.3 with: - ebpfprovider: libbpf + ebpfprovider: bcc # build kepler image - name: build and export Kepler image run: | @@ -32,22 +32,22 @@ jobs: make save-image env: IMAGE_REPO: "localhost:5001" - IMAGE_NAME: "kepler" IMAGE_TAG: "devel" + IMAGE_NAME: "kepler" CTR_CMD: docker IMAGE_OUTPUT_PATH: ${{env.OUTPUT_DIR}}${{env.FILE_NAME}} # save kepler image - name: save Kepler image as artifact uses: actions/upload-artifact@v3 with: - name: keplerlibbpf + name: kepler path: ${{env.OUTPUT_DIR}}${{env.FILE_NAME}} retention-days: 1 # ref https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts # as PR or Push event, we don't keep artifact in 90 days hence use 1 day here to save resources. - integration_test_with_libbpf: - needs: [build-kepler_with_libbpf] + integration_test: + needs: [build-kepler-with-bcc] runs-on: ubuntu-latest strategy: matrix: @@ -59,7 +59,7 @@ jobs: - name: download Kepler image artifact uses: actions/download-artifact@v3 with: - name: keplerlibbpf + name: kepler - name: build manifest run: make build-manifest OPTS="CI_DEPLOY" @@ -81,7 +81,7 @@ jobs: - name: use Kepler action to deploy cluster uses: sustainable-computing-io/kepler-action@v0.0.3 with: - ebpfprovider: libbpf + ebpfprovider: bcc cluster_provider: ${{matrix.cluster_provider}} local_dev_cluster_version: v0.0.3 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 5859ed4056..975b7acd0c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -19,10 +19,10 @@ jobs: developer_local: uses: ./.github/workflows/developer_local.yml # for each PR run integration test + integration_test_bcc: + uses: ./.github/workflows/integration_test_bcc.yml + # for each PR run integration test integration_test: uses: ./.github/workflows/integration_test.yml - # for each PR run integration test - integration_test_libbpf: - uses: ./.github/workflows/integration_test_libbpf.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 747dcb5d04..12d08a1567 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -130,17 +130,17 @@ jobs: context: . platforms: linux/amd64 push: true - tags: quay.io/sustainable_computing_io/kepler:latest, quay.io/sustainable_computing_io/kepler:${{ github.event.inputs.release }} + tags: quay.io/sustainable_computing_io/kepler:latest, quay.io/sustainable_computing_io/kepler:${{ github.event.inputs.release }}-bcc labels: latest, ${{ github.event.inputs.release }}, bcc file: build/Dockerfile - - name: Build and push kepler libbpf latest image + - name: Build and push kepler latest libbpf image uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64 push: true - tags: quay.io/sustainable_computing_io/kepler:latest, quay.io/sustainable_computing_io/kepler:${{ github.event.inputs.release }}-libbpf + tags: quay.io/sustainable_computing_io/kepler:latest, quay.io/sustainable_computing_io/kepler:${{ github.event.inputs.release }} labels: latest, ${{ github.event.inputs.release }}, libbpf file: build/Dockerfile.libbpf.kepler diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index 31b3ba8d41..3a75b11577 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -27,10 +27,10 @@ jobs: env: GOPATH: /home/runner/go GOBIN: /home/runner/go/bin - - name: install bcc + - name: install libbpf uses: sustainable-computing-io/kepler-action@v0.0.3 with: - ebpfprovider: bcc + ebpfprovider: libbpf - name: Prepare environment run: | sudo apt-get install -y cpuid @@ -38,7 +38,16 @@ jobs: git config --global --add safe.directory /kepler - name: Run run: | - make test-verbose + sudo apt remove libbpf-dev + mkdir temp-libbpf + cd temp-libbpf + git clone https://github.com/libbpf/libbpf + cd libbpf/src + sudo make install_headers + sudo make install_uapi_headers + sudo prefix=/usr BUILD_STATIC_ONLY=y make install + cd ../../../ + ATTACHER_TAG=libbpf make test-verbose go tool cover -func=coverage.out -o=coverage.out - name: Go Coverage Badge # Pass the `coverage.out` output to this action uses: tj-actions/coverage-badge-go@v2 diff --git a/Makefile b/Makefile index d95cd9fb2d..e666152ccd 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ ifdef ATTACHER_TAG ifeq ($(ATTACHER_TAG),libbpf) LIBBPF_HEADERS := /usr/include/bpf KEPLER_OBJ_SRC := $(SRC_ROOT)/bpfassets/libbpf/bpf.o/$(GOARCH)_kepler.bpf.o - LIBBPF_OBJ := /usr/lib64/libbpf.a + LIBBPF_OBJ ?= /usr/lib64/libbpf.a endif else # auto determine @@ -277,6 +277,7 @@ test: ginkgo-set tidy-vendor test-verbose: ginkgo-set tidy-vendor @echo TAGS=$(GO_BUILD_TAGS) + @echo GOENV=$(GOENV) @$(GOENV) go test -tags $(GO_BUILD_TAGS) -covermode=atomic -coverprofile=coverage.out -v $$(go list ./... | grep pkg | grep -v bpfassets) --race --bench=. -cover --count=1 --vet=all test-mac-verbose: ginkgo-set diff --git a/packaging/rpm/kepler.spec b/packaging/rpm/kepler.spec index 56a0c7aee8..15b7748d66 100644 --- a/packaging/rpm/kepler.spec +++ b/packaging/rpm/kepler.spec @@ -33,7 +33,7 @@ CROSS_BUILD_BINDIR=_output/bin GOARCH=amd64 %endif -make _build_local GOOS=${GOOS} GOARCH=${GOARCH} +make _build_local GOOS=${GOOS} GOARCH=${GOARCH} ATTACHER_TAG=libbpf cp ./${CROSS_BUILD_BINDIR}/${GOOS}_${GOARCH}/kepler ./_output/kepler From e04259cf2b50883396aba2c091874ca607fcd557 Mon Sep 17 00:00:00 2001 From: Vimal Kumar Date: Fri, 24 Nov 2023 15:01:49 +0530 Subject: [PATCH 2/2] fix(build): use correct cpus data file Updated following files to not use normalized_cpu_arch.csv, and use cpus.yaml - updated build/Dockerfile - doc/dev/prepare_dev_env.sh Signed-off-by: Vimal Kumar --- build/Dockerfile | 5 +++-- doc/dev/prepare_dev_env.sh | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 2fa77eaf6f..3a7fd154db 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -28,7 +28,8 @@ FROM quay.io/sustainable_computing_io/kepler_base:ubi-9-bcc-0.26 COPY --from=builder /opt/app-root/src/github.com/sustainable-computing-io/kepler/_output/bin/kepler /usr/bin/kepler RUN mkdir -p /var/lib/kepler/data -COPY --from=builder /opt/app-root/src/github.com/sustainable-computing-io/kepler/data/normalized_cpu_arch.csv /var/lib/kepler/data/normalized_cpu_arch.csv +COPY --from=builder /opt/app-root/src/github.com/sustainable-computing-io/kepler/data/cpus.yaml /var/lib/kepler/data/cpus.yaml + # copy model weight COPY --from=builder /opt/app-root/src/github.com/sustainable-computing-io/kepler/data/model_weight/acpi_AbsPowerModel.json /var/lib/kepler/data/acpi_AbsPowerModel.json @@ -41,4 +42,4 @@ RUN mkdir -p /usr/share/kepler/kernel_sources COPY --from=quay.io/sustainable_computing_io/kepler_kernel_source_images:ubi9 /usr/src/kernels /usr/share/kepler/kernel_sources -ENTRYPOINT ["/usr/bin/kepler"] \ No newline at end of file +ENTRYPOINT ["/usr/bin/kepler"] diff --git a/doc/dev/prepare_dev_env.sh b/doc/dev/prepare_dev_env.sh index 90899f652f..a78c7ee1c9 100755 --- a/doc/dev/prepare_dev_env.sh +++ b/doc/dev/prepare_dev_env.sh @@ -5,10 +5,10 @@ echo "copy data files" DATAPATH="/var/lib/kepler/data/" mkdir -p ${DATAPATH} -cp ../data/normalized_cpu_arch.csv ${DATAPATH} +cp ../data/cpus.yaml ${DATAPATH} mkdir -p /var/lib/kepler/data/ cp ../data/model_weight/acpi_AbsPowerModel.json ${DATAPATH}/acpi_AbsPowerModel.json cp ../data/model_weight/acpi_DynPowerModel.json ${DATAPATH}/acpi_DynPowerModel.json cp ../data/model_weight/rapl_AbsPowerModel.json ${DATAPATH}/rapl_AbsPowerModel.json -cp ../data/model_weight/rapl_DynPowerModel.json ${DATAPATH}/rapl_DynPowerModel.json \ No newline at end of file +cp ../data/model_weight/rapl_DynPowerModel.json ${DATAPATH}/rapl_DynPowerModel.json