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

Add transformation test make target and docs #1722

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

braydonk
Copy link
Contributor

Description

This PR adds make targets for transformation tests, as well as usage docs.

Some other things were fixed incidentally:

  • Running the precommit_update target yielded numerous files missing license headers
  • Fixed warnings in transformation_test.go

Related issue

These updates will feed into updating the otelopscol version.

How has this been tested?

All make targets have been run.

Checklist:

  • Unit tests
    • Unit tests do not apply.
    • Unit tests have been added/modified and passed for this PR.
  • Integration tests
    • Integration tests do not apply.
    • Integration tests have been added/modified and passed for this PR.
  • Documentation
    • This PR introduces no user visible changes.
    • This PR introduces user visible changes and the corresponding documentation change has been made.
  • Minor version bump
    • This PR introduces no new features.
    • This PR introduces new features, and there is a separate PR to bump the minor version since the last release already.
    • This PR bumps the version.

This PR adds make targets for transformation tests, as well as usage
docs.

Some other things were fixed incidentally:
* Running the `precommit_update` target yielded numerous files missing
  license headers
* Fixed warnings in `transformation_test.go`

Signed-off-by: braydonk <[email protected]>
@braydonk braydonk requested review from a team, XuechunHou and igorpeshansky and removed request for a team and XuechunHou May 23, 2024 15:11
.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
builds/fluent_bit_local.sh Outdated Show resolved Hide resolved
Comment on lines +10 to +11

`tasks.mak` is provided without any guarantees or warranty on its targets. It is meant purely for developer convenience, and it is advised not to make any dependency on the targets since they are subject to change at any time.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional] I wonder if we should be calling it developer_tasks.mak or something…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally chose tasks.mak just cause it was shorter, and at first it seemed like we'd need to always type in -f tasks.mak so making it longer would have been a pain. We could change it now, though it really only exists to then be immediately symlinked to when you set up your environment.

dev-docs/transformation-tests.md Outdated Show resolved Hide resolved
tasks.mak Outdated Show resolved Hide resolved
transformation_test/transformation_test.go Outdated Show resolved Hide resolved
builds/fluent_bit.sh Outdated Show resolved Hide resolved
builds/fluent_bit.sh Outdated Show resolved Hide resolved
-DFLB_CONFIG_YAML=OFF
make -j8
make DESTDIR="$DESTDIR" install
if [[ "$DESTDIR" = *"dist" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder — is there any harm in actually doing a full install into ${DESTDIR} and pointing the tests to the installation path within that? That way we can fully reuse the existing build script, right?
As-is, using a DESTDIR pattern to indicate local builds seems fragile to me. I'd almost rather add a new variable (e.g., LOCAL_BUILD, or BINARY_ONLY, or some such) and use that…

Copy link
Contributor Author

@braydonk braydonk May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly we could do the install, the main reason I didn't is because it's super annoying how many folders it creates when we could just copy the binary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added LOCAL_ONLY variable in f1d154e

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, those additional folders are a small price to pay for removing the additional complexity in the build scripts. But let's see how non-invasive we can make this with LOCAL_ONLY first…

builds/fluent_bit.sh Outdated Show resolved Hide resolved
builds/otel.sh Outdated Show resolved Hide resolved
builds/otel.sh Outdated Show resolved Hide resolved
-DFLB_CONFIG_YAML=OFF
END
CMAKE_ARGS=(
"-DCMAKE_BUILD_TYPE=RelWithDebInfo"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional] These quotes are also superfluous (but harmless).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, these flags didn't use to have quotes on the command line, so it may make sense to not use quotes in the array as well… Except, maybe, for CMAKE_INSTALL_PREFIX, which could become -DCMAKE_INSTALL_PREFIX="$fluent_bit_dir"… WDYT?

-DFLB_CONFIG_YAML=OFF
make -j8
make DESTDIR="$DESTDIR" install
if [[ "$DESTDIR" = *"dist" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, those additional folders are a small price to pay for removing the additional complexity in the build scripts. But let's see how non-invasive we can make this with LOCAL_ONLY first…

builds/fluent_bit.sh Outdated Show resolved Hide resolved
Comment on lines 33 to 50

cd submodules/fluent-bit
mkdir -p build
cd build
if [[ "$DESTDIR" = *"dist" ]]; then
cmake .. $CMAKE_ARGS

if [ "$LOCAL_ONLY" = "true" ]; then
# If this is a local build, we can just build and copy the binary.
cmake .. ${CMAKE_ARGS[@]}
make -j8
mv ./bin/fluent-bit $DESTDIR
cp ./bin/fluent-bit $DESTDIR

# Otherwise, we do a full install.
else
fluent_bit_dir=/opt/google-cloud-ops-agent/subagents/fluent-bit
# CMAKE_INSTALL_PREFIX here will cause the binary to be put at
# /usr/lib/google-cloud-ops-agent/bin/fluent-bit
# Additionally, -DFLB_SHARED_LIB=OFF skips building libfluent-bit.so
cmake .. -DCMAKE_INSTALL_PREFIX=$fluent_bit_dir $CMAKE_ARGS
cmake .. -DCMAKE_INSTALL_PREFIX=$fluent_bit_dir ${CMAKE_ARGS[@]}
make -j8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can factor out the additional CMAKE_ARGS and the install step into the non-local case…

if ! [ "$LOCAL_ONLY" = "true" ]; then
  fluent_bit_dir=/opt/google-cloud-ops-agent/subagents/fluent-bit
  CMAKE_ARGS=(
    # CMAKE_INSTALL_PREFIX here will cause the binary to be put at
    # /usr/lib/google-cloud-ops-agent/bin/fluent-bit
    "-DCMAKE_INSTALL_PREFIX=$fluent_bit_dir"
    "${CMAKE_ARGS[@]}"
  )
fi

cd submodules/fluent-bit
mkdir -p build
cd build

cmake .. "${CMAKE_ARGS[@]}"
make -j8

# If this is a local build, we can just build and copy the binary.
if [ "$LOCAL_ONLY" = "true" ]; then
  cp ./bin/fluent-bit "$DESTDIR"
# Otherwise, we do a full install.
else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obsoleted by 78fbf64 which changes the script to always function with a full install.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional] Heh, we could now revert back to the original inline args, unless you want to keep the array…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually no reason for this script to change at all anymore. Reverted it to its state in the main branch in 4ed4297 (left the license header added though)

builds/fluent_bit.sh Outdated Show resolved Hide resolved
dev-docs/transformation-tests.md Outdated Show resolved Hide resolved
dev-docs/transformation-tests.md Outdated Show resolved Hide resolved
tasks.mak Outdated Show resolved Hide resolved
tasks.mak Show resolved Hide resolved
tasks.mak Outdated
test_confgenerator:
go test ./confgenerator $(if $(UPDATE),-update,)

.PHONY: test_confgenerator_update
test_confgenerator_update:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional] Would target-specific variables work in this case, e.g.:

test_confgenerator_update: UPDATE=true test_confgenerator
test_metadata_update: UPDATE=true test_metadata
…
transformation_test_update: UPDATE=true transformation_test

? We might need := instead of =, but it ought to work…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get this to work. The only way UPDATE=true was properly passed to the next target is the way I have it right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what I did wrong — the variable assignment has to be a separate dependency. This works:

test_confgenerator_update: UPDATE=true
test_confgenerator_update: test_confgenerator
test_metadata_update: UPDATE=true
test_metadata_update: test_metadata
…
transformation_test_update: UPDATE=true
transformation_test_update: transformation_test
$ cat Makefile 
t:
        echo "[$(UPDATE)]"

u: UPDATE=true
u: t
v: UPDATE=false
v: t
$ make t
echo "[]"
[]
$ make u
echo "[true]"
[true]
$ make v
echo "[false]"
[false]
$ 

But up to you…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d0194ea

builds/otel.sh Outdated
@@ -15,17 +15,17 @@

set -x -e

ROOTDIR="$1"
DESTDIR="$1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quotes around $1 are superfluous (and didn't use to be there) — want to remove them for symmetry with fluent_bit.sh?

builds/otel.sh Outdated
Comment on lines 18 to 22
DESTDIR="$1"
otel_dir=/opt/google-cloud-ops-agent/subagents/opentelemetry-collector
DESTDIR="${ROOTDIR}${otel_dir}"
DESTDIR="${DESTDIR}${otel_dir}"

mkdir -p $DESTDIR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to have a separate name for the otel binary directory, and create the original $DESTDIR separately, i.e.:

DESTDIR=$1
mkdir -p "$DESTDIR"

OTELDIR="${DESTDIR}${otel_dir}"
mkdir -p "$OTELDIR"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it anyway in 0800d03. The first assignment of DESTDIR was completely redundant. The DESTDIR is never used separately. The mkdir -p $DESTDIR that's in there now should work fine.

CMAKE_ARGS=(
# CMAKE_INSTALL_PREFIX here will cause the binary to be put at
# /usr/lib/google-cloud-ops-agent/bin/fluent-bit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized that this value is no longer accurate, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obsoleted by 4ed4297

-DFLB_CONFIG_YAML=OFF
END
CMAKE_ARGS=(
"-DCMAKE_BUILD_TYPE=RelWithDebInfo"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, these flags didn't use to have quotes on the command line, so it may make sense to not use quotes in the array as well… Except, maybe, for CMAKE_INSTALL_PREFIX, which could become -DCMAKE_INSTALL_PREFIX="$fluent_bit_dir"… WDYT?

Comment on lines 33 to 50

cd submodules/fluent-bit
mkdir -p build
cd build
if [[ "$DESTDIR" = *"dist" ]]; then
cmake .. $CMAKE_ARGS

if [ "$LOCAL_ONLY" = "true" ]; then
# If this is a local build, we can just build and copy the binary.
cmake .. ${CMAKE_ARGS[@]}
make -j8
mv ./bin/fluent-bit $DESTDIR
cp ./bin/fluent-bit $DESTDIR

# Otherwise, we do a full install.
else
fluent_bit_dir=/opt/google-cloud-ops-agent/subagents/fluent-bit
# CMAKE_INSTALL_PREFIX here will cause the binary to be put at
# /usr/lib/google-cloud-ops-agent/bin/fluent-bit
# Additionally, -DFLB_SHARED_LIB=OFF skips building libfluent-bit.so
cmake .. -DCMAKE_INSTALL_PREFIX=$fluent_bit_dir $CMAKE_ARGS
cmake .. -DCMAKE_INSTALL_PREFIX=$fluent_bit_dir ${CMAKE_ARGS[@]}
make -j8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional] Heh, we could now revert back to the original inline args, unless you want to keep the array…

builds/otel.sh Outdated Show resolved Hide resolved
dev-docs/transformation-tests.md Outdated Show resolved Hide resolved
Comment on lines +118 to +119
FLB=$(PWD)/dist/opt/google-cloud-ops-agent/subagents/fluent-bit/bin/fluent-bit \
OTELOPSCOL=$(PWD)/dist/opt/google-cloud-ops-agent/subagents/opentelemetry-collector/otelopscol \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional] Let's use $${PWD} (bash variable quoting) instead of $(PWD) (makefile quoting)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't we want to use makefile quoting in the makefile?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on whether you want the directory the make command was invoked from ($(PWD), which is a make variable), or the current directory of the shell that make is running the current set of commands in ($${PWD}, which is a shell variable). They might be the same in this case, I suppose…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I do want the working directory of make and not the working directory of the shell, although I do not change the working directory of the shell during this target.

tasks.mak Outdated
test_confgenerator:
go test ./confgenerator $(if $(UPDATE),-update,)

.PHONY: test_confgenerator_update
test_confgenerator_update:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what I did wrong — the variable assignment has to be a separate dependency. This works:

test_confgenerator_update: UPDATE=true
test_confgenerator_update: test_confgenerator
test_metadata_update: UPDATE=true
test_metadata_update: test_metadata
…
transformation_test_update: UPDATE=true
transformation_test_update: transformation_test
$ cat Makefile 
t:
        echo "[$(UPDATE)]"

u: UPDATE=true
u: t
v: UPDATE=false
v: t
$ make t
echo "[]"
[]
$ make u
echo "[true]"
[true]
$ make v
echo "[false]"
[false]
$ 

But up to you…

dev-docs/transformation-tests.md Outdated Show resolved Hide resolved
dev-docs/transformation-tests.md Outdated Show resolved Hide resolved
dev-docs/transformation-tests.md Outdated Show resolved Hide resolved
tasks.mak Show resolved Hide resolved
Comment on lines +118 to +119
FLB=$(PWD)/dist/opt/google-cloud-ops-agent/subagents/fluent-bit/bin/fluent-bit \
OTELOPSCOL=$(PWD)/dist/opt/google-cloud-ops-agent/subagents/opentelemetry-collector/otelopscol \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on whether you want the directory the make command was invoked from ($(PWD), which is a make variable), or the current directory of the shell that make is running the current set of commands in ($${PWD}, which is a shell variable). They might be the same in this case, I suppose…

@braydonk
Copy link
Contributor Author

Something that I want to do over FixIt is to clean up the Makefile and make it better since I'm much better at writing make than I was when I first made the Makefile. Also, our update to goccy/go-yaml is dependent on making some transformation_test updates, which are really hard to do right now without these make targets. So provided CI passes, I am going to merge this and address the feedback when I do the cleanup during the FixIt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants