Skip to content

Commit dd1a4af

Browse files
simplify onhost<->k8s features use (#660)
* simplify onhost<->k8s features use * check features in super agent lib * run clippy and tests per project * run cargo checks per project * fix license detector ureq feature * add missing parameter * run on host tests with makefile as it uses env vars * fix super agent tests on host * specify package in root tests. Remove root tests in k8s. * fix cargo doc * fix llvm-cov job * fix tilt * add package to build process * add feature name to job * do not pass onhost flag to config migrate * allow not passing feature to build_binary * allow not passing feature to build_binary 2 * separate build per feature * don't pass empty features
1 parent d3921ad commit dd1a4af

File tree

20 files changed

+171
-67
lines changed

20 files changed

+171
-67
lines changed

.github/workflows/check.yml

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,67 @@ jobs:
3737
components: rustfmt
3838
- name: Check code formatting
3939
run: cargo fmt --check
40-
clippy:
40+
41+
clippy_packages:
4142
runs-on: ubuntu-latest
42-
name: ${{ matrix.toolchain }} / clippy
43+
name: ${{ matrix.toolchain }} / ${{ matrix.package }} / clippy
4344
permissions:
4445
contents: read
4546
checks: write
4647
strategy:
4748
fail-fast: false
4849
matrix:
4950
toolchain: [ stable, beta ]
51+
package: [ config-migrate, fs, license, nr-auth, resource-detection ]
5052
steps:
5153
- uses: actions/checkout@v4
5254
with:
5355
submodules: true
56+
5457
- name: Give GitHub Actions access to private crates
5558
uses: webfactory/[email protected]
5659
with:
5760
ssh-private-key: ${{ secrets.CAOS_RUST_CRATES }}
61+
5862
- name: Install ${{ matrix.toolchain }}
5963
uses: dtolnay/[email protected]
6064
with:
6165
toolchain: ${{ matrix.toolchain }}
6266
components: clippy
63-
- name: cargo clippy
64-
uses: actions-rs/clippy-check@v1
67+
68+
- name: cargo clippy ${{ matrix.package }}
69+
run: cargo clippy --package ${{ matrix.package }} --message-format=json --tests -- -D clippy::all
70+
71+
clippy_super_agent:
72+
runs-on: ubuntu-latest
73+
name: ${{ matrix.toolchain }} / ${{ matrix.feature }} / clippy
74+
permissions:
75+
contents: read
76+
checks: write
77+
strategy:
78+
fail-fast: false
79+
matrix:
80+
toolchain: [ stable, beta ]
81+
feature: [ onhost, k8s ]
82+
steps:
83+
- uses: actions/checkout@v4
6584
with:
66-
token: ${{ secrets.GITHUB_TOKEN }}
67-
args: --features=onhost -- -D clippy::all
68-
- name: cargo clippy
69-
uses: actions-rs/clippy-check@v1
85+
submodules: true
86+
87+
- name: Give GitHub Actions access to private crates
88+
uses: webfactory/[email protected]
7089
with:
71-
token: ${{ secrets.GITHUB_TOKEN }}
72-
args: --features=k8s --tests -- -D clippy::all
90+
ssh-private-key: ${{ secrets.CAOS_RUST_CRATES }}
91+
92+
- name: Install ${{ matrix.toolchain }}
93+
uses: dtolnay/[email protected]
94+
with:
95+
toolchain: ${{ matrix.toolchain }}
96+
components: clippy
97+
98+
- name: cargo clippy super agent (${{ matrix.feature }})
99+
run: cargo clippy --package newrelic_super_agent --features=${{ matrix.feature }} --message-format=json --tests -- -D clippy::all
100+
73101
doc:
74102
runs-on: ubuntu-latest
75103
name: stable / doc
@@ -84,36 +112,66 @@ jobs:
84112
- name: Install nightly
85113
uses: dtolnay/[email protected]
86114
- name: Create on-host documentation
87-
run: cargo doc --no-deps --features=onhost
115+
run: cargo doc --no-deps --features=onhost --package newrelic_super_agent
88116
env:
89117
RUSTDOCFLAGS: --cfg docsrs
90118
- name: Create K8s documentation
91-
run: cargo doc --no-deps --features=k8s
119+
run: cargo doc --no-deps --features=k8s --package newrelic_super_agent
92120
env:
93121
RUSTDOCFLAGS: --cfg docsrs
94-
msrv:
122+
123+
# msrv = Minimum Supported Rust Version
124+
msrv_super_agent:
125+
runs-on: ubuntu-latest
126+
strategy:
127+
matrix:
128+
msrv: [ 1.78.0 ]
129+
feature: [ onhost, k8s ]
130+
name: ubuntu / ${{ matrix.msrv }} / ${{ matrix.feature }}
131+
steps:
132+
- uses: actions/checkout@v4
133+
with:
134+
submodules: true
135+
136+
- name: Give GitHub Actions access to private crates
137+
uses: webfactory/[email protected]
138+
with:
139+
ssh-private-key: ${{ secrets.CAOS_RUST_CRATES }}
140+
141+
- name: Install ${{ matrix.msrv }}
142+
uses: dtolnay/[email protected]
143+
with:
144+
toolchain: ${{ matrix.msrv }}
145+
146+
- name: cargo +${{ matrix.msrv }} check ${{ matrix.feature }}
147+
run: cargo check --package newrelic_super_agent --features=${{ matrix.feature }}
148+
149+
# msrv = Minimum Supported Rust Version
150+
msrv_packages:
95151
runs-on: ubuntu-latest
96152
strategy:
97153
matrix:
98154
msrv: [ 1.78.0 ]
155+
package: [ config-migrate, fs, license, nr-auth, resource-detection ]
156+
99157
name: ubuntu / ${{ matrix.msrv }}
100158
steps:
101159
- uses: actions/checkout@v4
102160
with:
103161
submodules: true
162+
104163
- name: Give GitHub Actions access to private crates
105164
uses: webfactory/[email protected]
106165
with:
107166
ssh-private-key: ${{ secrets.CAOS_RUST_CRATES }}
167+
108168
- name: Install ${{ matrix.msrv }}
109169
uses: dtolnay/[email protected]
110170
with:
111171
toolchain: ${{ matrix.msrv }}
112-
- name: cargo +${{ matrix.msrv }} check onK8s
113-
run: cargo check --features=k8s
114-
- name: cargo +${{ matrix.msrv }} check onHost
115-
run: cargo check --features=onhost
116172

173+
- name: cargo +${{ matrix.msrv }} check ${{ matrix.package }}
174+
run: cargo check --package ${{ matrix.package }}
117175

118176
licenses:
119177
name: Validate third party libraries

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
if: hashFiles('Cargo.lock') == ''
3434
run: cargo generate-lockfile
3535
- name: cargo llvm-cov for k8s version
36-
run: cargo llvm-cov --locked --features=k8s --json --output-path jcov.info -- --skip as_root
36+
run: cargo llvm-cov --locked --package newrelic_super_agent --features=k8s --json --output-path jcov.info -- --skip as_root
3737
- name: Calculate and print total coverage
3838
run: |
3939
echo "Total functions coverage: $(jq '.data[].totals.functions.percent' jcov.info)"

.github/workflows/test.yml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,47 @@ jobs:
2020
- uses: actions/checkout@v4
2121
with:
2222
submodules: true
23+
2324
- name: Give GitHub Actions access to private crates
2425
uses: webfactory/[email protected]
2526
with:
2627
ssh-private-key: ${{ secrets.CAOS_RUST_CRATES }}
28+
2729
- name: Install ${{ matrix.toolchain }}
2830
uses: dtolnay/[email protected]
2931
with:
3032
toolchain: ${{ matrix.toolchain }}
33+
3134
- name: cargo generate-lockfile
3235
if: hashFiles('Cargo.lock') == ''
3336
run: cargo generate-lockfile
34-
- name: Run tests onHost excluding root-required tests
37+
38+
- name: Run tests config-migrate
39+
run: cargo test --locked --package config-migrate --all-targets
40+
41+
- name: Run tests fs
42+
run: cargo test --locked --package fs --all-targets
43+
44+
- name: Run tests license
45+
run: cargo test --locked --package license --all-targets
46+
47+
- name: Run tests nr-auth
48+
run: cargo test --locked --package nr-auth --all-targets
49+
50+
- name: Run tests resource-detection
51+
run: cargo test --locked --package resource-detection --all-targets
52+
53+
- name: Run tests super agent excluding root-required tests (on-host)
3554
run: CARGO_ARGS="--locked --features=onhost --all-targets -- --skip as_root" make super-agent
36-
- name: Run tests onK8s
37-
run: cargo test --locked --features=k8s --all-targets
55+
56+
- name: Run tests super agent (k8s)
57+
run: cargo test --locked --package newrelic_super_agent --features=k8s --all-targets
58+
3859
- name: Run documentation tests onhost
39-
run: cargo test --locked --features=onhost --doc
60+
run: cargo test --locked --package newrelic_super_agent --features=onhost --doc
61+
4062
- name: Run documentation tests k8st
41-
run: cargo test --locked --features=k8s --doc
63+
run: cargo test --locked --package newrelic_super_agent --features=k8s --doc
4264

4365
# Test using root can be troublesome to perform as usually the Rust toolchain is installed local to the user.
4466
# To test for root privileges, we can run from a container (disabling the test that fail if running non-root).
@@ -50,14 +72,19 @@ jobs:
5072
- uses: actions/checkout@v4
5173
with:
5274
submodules: true
75+
5376
- name: Give GitHub Actions access to private crates
5477
uses: webfactory/[email protected]
5578
with:
5679
ssh-private-key: ${{ secrets.CAOS_RUST_CRATES }}
57-
- name: Run k8s root-required tests only
58-
run: cargo test --locked --features=k8s --all-targets
80+
81+
- name: Install ${{ matrix.toolchain }}
82+
uses: dtolnay/[email protected]
83+
with:
84+
toolchain: ${{ matrix.toolchain }}
85+
5986
- name: Run onHost root-required tests only
60-
run: CARGO_ARGS="--locked --features=onhost --all-targets -- --skip no_root" make super-agent
87+
run: CARGO_ARGS="--locked --package newrelic_super_agent --features=onhost --all-targets -- --skip no_root" make super-agent
6188

6289
embedded:
6390
name: Unit test for embedded downloader

.goreleaser.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ builds:
1616
- BUILD_FEATURE=onhost
1717
- BIN=newrelic-super-agent
1818
- SUPER_AGENT_VERSION={{ .Version }}
19+
- PKG=newrelic_super_agent
1920
- cmd: sh ./build/scripts/replace_go_with_rust.sh
2021
env:
2122
- ARCH={{ .Arch }}
@@ -37,8 +38,8 @@ builds:
3738
- cmd: sh ./build/scripts/build_binary.sh
3839
env:
3940
- ARCH={{ .Arch }}
40-
- BUILD_FEATURE=onhost
4141
- BIN=newrelic-config-migrate
42+
- PKG=config-migrate
4243
- SUPER_AGENT_VERSION={{ .Version }}
4344
- cmd: sh ./build/scripts/replace_go_with_rust.sh
4445
env:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ BUILD_MODE ?= release
3737
# Cross-compilation only works from amd64 host.
3838
build-super-agent:
3939
@echo "Building with mode: $(BUILD_MODE) and arch: $(ARCH)"
40-
ARCH=$(ARCH) BUILD_MODE=$(BUILD_MODE) BIN="newrelic-super-agent" ./build/scripts/build_binary.sh
40+
ARCH=$(ARCH) BUILD_MODE=$(BUILD_MODE) BIN="newrelic-super-agent" PKG="newrelic_super_agent" ./build/scripts/build_binary.sh
4141

4242
# Cross-compilation only works from amd64 host.
4343
build-config-migrate:
4444
@echo "Building with mode: $(BUILD_MODE) and arch: $(ARCH)"
45-
ARCH=$(ARCH) BUILD_MODE=$(BUILD_MODE) BIN="newrelic-config-migrate" ./build/scripts/build_binary.sh
45+
ARCH=$(ARCH) BUILD_MODE=$(BUILD_MODE) BIN="newrelic-config-migrate" PKG="config-migrate" ./build/scripts/build_binary.sh
4646

4747
.PHONY: build-dev-image
4848
build-dev-image:

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ feature_branch = '<feature-branch>'
4040
if build_with == 'cargo':
4141
local_resource(
4242
'build-binary',
43-
cmd="cargo build --features=k8s && mkdir -p bin && mv target/debug/newrelic-super-agent bin/newrelic-super-agent-"+arch,
43+
cmd="cargo build --package newrelic_super_agent --features=k8s && mkdir -p bin && mv target/debug/newrelic-super-agent bin/newrelic-super-agent-"+arch,
4444
deps=[
4545
'./super-agent',
4646
]

build/rust.Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ ARG BUILD_FEATURE
4141
ENV BUILD_FEATURE_ENV=${BUILD_FEATURE}
4242
ARG BUILD_BIN
4343
ENV BUILD_BIN_ENV=${BUILD_BIN}
44+
ARG BUILD_PKG
45+
ENV BUILD_PKG_ENV=${BUILD_PKG}
4446

4547
# Execute the command dynamically at runtime
4648
CMD [ "sh", "-c", "\
4749
CMD_STRING='cargo build'; \
4850
[ \"$BUILD_MODE_ENV\" != 'debug' ] && CMD_STRING='cargo build --release'; \
49-
CMD_STRING=\"$CMD_STRING --features $BUILD_FEATURE_ENV\"; \
51+
CMD_STRING=\"$CMD_STRING --package $BUILD_PKG_ENV\"; \
52+
[ \"$BUILD_FEATURE_ENV\" != '' ] && CMD_STRING=\"$CMD_STRING --features $BUILD_FEATURE_ENV\"; \
5053
CMD_STRING=\"$CMD_STRING --target $ARCH_NAME-unknown-linux-musl\"; \
5154
CMD_STRING=\"$CMD_STRING --bin $BUILD_BIN_ENV\"; \
5255
CMD_STRING=\"$CMD_STRING --target-dir target-$BUILD_BIN_ENV\"; \

build/scripts/build_binary.sh

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,31 @@ if [ -z "${BIN}" ]; then
1818
echo "BIN not provided; defaulting to 'newrelic-super-agent'."
1919
fi
2020

21-
22-
if [ -z "${BUILD_FEATURE}" ]; then
23-
BUILD_FEATURE="onhost"
24-
echo "BUILD_FEATURE not provided; defaulting to 'onhost'."
21+
if [ -z "${PKG}" ]; then
22+
PKG="newrelic_super_agent"
23+
echo "PKG not provided; defaulting to 'newrelic_super_agent'."
2524
fi
2625

2726
echo "arch: ${ARCH}, arch_name: ${ARCH_NAME}"
2827

29-
docker build --platform linux/amd64 -t "rust-cross-${ARCH_NAME}-${BIN}" \
30-
-f ./build/rust.Dockerfile \
31-
--build-arg ARCH_NAME="${ARCH_NAME}" \
32-
--build-arg BUILD_MODE="${BUILD_MODE}" \
33-
--build-arg BUILD_FEATURE="${BUILD_FEATURE}" \
34-
--build-arg BUILD_BIN="${BIN}" \
35-
.
28+
if [ -z "${BUILD_FEATURE}" ]; then
29+
docker build --platform linux/amd64 -t "rust-cross-${ARCH_NAME}-${BIN}" \
30+
-f ./build/rust.Dockerfile \
31+
--build-arg ARCH_NAME="${ARCH_NAME}" \
32+
--build-arg BUILD_MODE="${BUILD_MODE}" \
33+
--build-arg BUILD_PKG="${PKG}" \
34+
--build-arg BUILD_BIN="${BIN}" \
35+
.
36+
else
37+
docker build --platform linux/amd64 -t "rust-cross-${ARCH_NAME}-${BIN}" \
38+
-f ./build/rust.Dockerfile \
39+
--build-arg ARCH_NAME="${ARCH_NAME}" \
40+
--build-arg BUILD_MODE="${BUILD_MODE}" \
41+
--build-arg BUILD_FEATURE="${BUILD_FEATURE}" \
42+
--build-arg BUILD_PKG="${PKG}" \
43+
--build-arg BUILD_BIN="${BIN}" \
44+
.
45+
fi
3646

3747
# Binary metadata
3848
GIT_COMMIT=$( git rev-parse HEAD )

config-migrate/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ nix = { workspace = true, features = ["signal", "user", "hostname"] }
1717
tracing-subscriber = { workspace = true, features = ["env-filter"] }
1818
tracing = { workspace = true }
1919
serde_yaml = { workspace = true }
20-
newrelic_super_agent = { path = "../super-agent" }
20+
newrelic_super_agent = { path = "../super-agent", features = ["onhost"] }
2121
fs = { path = "../fs" }
2222
semver = { workspace = true }
2323

resource-detection/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ tracing = { workspace = true }
1414
serde_json = { workspace = true }
1515
http = { workspace = true }
1616
bytes = "1.5.0"
17-
ureq = { workspace = true, features = ["http-interop"] }
18-
fs = { path = "../fs/" }
17+
ureq = { workspace = true, features = ["http-crate"] }
18+
fs = { path = "../fs" }
1919
konst = { workspace = true }
2020

2121
[dev-dependencies]

0 commit comments

Comments
 (0)