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
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f7aecdd
Add transformation test make target and docs
braydonk May 23, 2024
33a760b
remove unintended function
braydonk May 23, 2024
73e5155
use target dependencies instead of wildcard
braydonk May 23, 2024
79127e9
change error name from cmdErr to err
braydonk May 23, 2024
dbb99ab
factor out cmake arguments into a separate file
braydonk May 23, 2024
91c0397
Just kidding that doesn't work
braydonk May 23, 2024
cfcc68f
consolidate build scripts
braydonk May 23, 2024
a4b98df
reword gitignore comments
braydonk May 23, 2024
65cfc75
reword transformation-tests.md intro paragraph
braydonk May 23, 2024
f1d154e
add LOCAL_ONLY variable support
braydonk May 24, 2024
e87fa1e
remove unnecessary var
braydonk May 24, 2024
0572082
move shared lib comment
braydonk May 24, 2024
6d2aeac
changed CMAKE_ARGS to an array
braydonk May 24, 2024
34654d8
properly quote ldflag
braydonk May 24, 2024
e1164e0
set me free from bash hell
braydonk May 24, 2024
78fbf64
Change build scripts to full install
braydonk May 27, 2024
b94c571
fix paths for new full install builds, update some out of date bits
braydonk May 27, 2024
ea76294
change P variable to FILE
braydonk May 29, 2024
c66ca2d
fix outdated comment
braydonk May 29, 2024
4ed4297
revert fluent bit build script back to the way it was
braydonk May 31, 2024
d0194ea
use target-specific variables for update targets
braydonk May 31, 2024
0800d03
remove redundant DESTDIR assignment
braydonk May 31, 2024
0db4c79
clarify java skip in transformation test docs and add way to do java …
braydonk May 31, 2024
eb5d8ef
merge master
braydonk Nov 14, 2024
2853765
update some goldens
braydonk Nov 14, 2024
6e0c84a
fix dev-doc grammar
braydonk Nov 14, 2024
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Ignore a file actually called Makefile. The presence of this file interferes
# with our Linux package building processes. To make a local symlink called
# "Makefile" for development convenience, use this command:
# make -f tasks.mak makefile_symlink
Makefile

# Ignore generated credentials from google-github-actions/auth
gha-creds-*.json

# This is a folder used to hold local builds of fluent-bit and otelopscol
# when running transformation tests locally.
dist/
14 changes: 14 additions & 0 deletions builds/agent_wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -x -e
DESTDIR=$1
mkdir -p "$DESTDIR/opt/google-cloud-ops-agent/libexec"
Expand Down
68 changes: 50 additions & 18 deletions builds/fluent_bit.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
#!/bin/bash
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -x -e
DESTDIR=$1

DESTDIR="$1"
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $DESTDIR
fluent_bit_dir=/opt/google-cloud-ops-agent/subagents/fluent-bit


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_HTTP_SERVER=ON"
"-DFLB_DEBUG=OFF"
"-DWITHOUT_HEADERS=ON"
# -DFLB_SHARED_LIB=OFF skips building libfluent-bit.so.
"-DFLB_SHARED_LIB=OFF"
"-DFLB_STREAM_PROCESSOR=OFF"
"-DFLB_MSGPACK_TO_JSON_INIT_BUFFER_SIZE=1.5"
"-DFLB_MSGPACK_TO_JSON_REALLOC_BUFFER_SIZE=.10"
"-DFLB_CONFIG_YAML=OFF"
)

cd submodules/fluent-bit
mkdir -p build
cd build
# 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 \
-DFLB_HTTP_SERVER=ON -DFLB_DEBUG=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DWITHOUT_HEADERS=ON -DFLB_SHARED_LIB=OFF -DFLB_STREAM_PROCESSOR=OFF \
-DFLB_MSGPACK_TO_JSON_INIT_BUFFER_SIZE=1.5 -DFLB_MSGPACK_TO_JSON_REALLOC_BUFFER_SIZE=.10 \
-DFLB_CONFIG_YAML=OFF
make -j8
make DESTDIR="$DESTDIR" install

# We don't want fluent-bit's service or configuration, but there are no cmake
# flags to disable them. Prune after build.
rm "${DESTDIR}/lib/systemd/system/fluent-bit.service" || true
rm "${DESTDIR}/usr/lib/systemd/system/fluent-bit.service" || true
rm -r "${DESTDIR}${fluent_bit_dir}/etc"
if [ "$LOCAL_ONLY" = "true" ]; then
# If this is a local build, we can just build and copy the binary.
cmake .. ${CMAKE_ARGS[@]}
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
make -j8
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
cmake .. -DCMAKE_INSTALL_PREFIX=$fluent_bit_dir ${CMAKE_ARGS[@]}
make -j8
make DESTDIR="$DESTDIR" install
# We don't want fluent-bit's service or configuration, but there are no cmake
# flags to disable them. Prune after build.
rm "${DESTDIR}/lib/systemd/system/fluent-bit.service" || true
rm "${DESTDIR}/usr/lib/systemd/system/fluent-bit.service" || true
rm -r "${DESTDIR}${fluent_bit_dir}/etc"
fi
14 changes: 14 additions & 0 deletions builds/ops_agent_diagnostics.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -x -e
DESTDIR=$1
mkdir -p "$DESTDIR/opt/google-cloud-ops-agent/libexec"
Expand Down
72 changes: 49 additions & 23 deletions builds/otel.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
#!/bin/bash
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -x -e
DESTDIR=$1

ROOTDIR="$1"
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
otel_dir=/opt/google-cloud-ops-agent/subagents/opentelemetry-collector
DESTDIR="${DESTDIR}${otel_dir}"

cd submodules/opentelemetry-java-contrib
mkdir -p "$DESTDIR"
./gradlew --no-daemon -Djdk.lang.Process.launchMechanism=vfork :jmx-metrics:build
cp jmx-metrics/build/libs/opentelemetry-jmx-metrics-*-alpha-SNAPSHOT.jar "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar"

# Rename LICENSE file because it causes issues with file hash consistency due to an unknown
# issue with the debuild/rpmbuild processes. Something is unzipping the jar in a case-insensitive
# environment and having a conflict between the LICENSE file and license/ directory, leading to a changed jar file
mkdir ./META-INF
unzip -j "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar" "META-INF/LICENSE" -d ./META-INF
zip -d "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar" "META-INF/LICENSE"
mv ./META-INF/LICENSE ./META-INF/LICENSE.renamed
zip -u "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar" "META-INF/LICENSE.renamed"

cd ../opentelemetry-operations-collector
# Using array assignment to drop the filename from the sha256sum output
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
JAR_SHA_256=($(sha256sum "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar"))
go build -tags=gpu -buildvcs=false -o "$DESTDIR/otelopscol" \
-ldflags "-X github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver.MetricsGathererHash=$JAR_SHA_256" \
./cmd/otelopscol
DESTDIR="${ROOTDIR}${otel_dir}"

# Default values for go build arguments.
BINARYLOCATION="$ROOTDIR/otelopscol"
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
LDFLAGS=""
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved

# If this is not a local build, then we build otel java and add it to
# the ldflags, as well as changing the binary location.
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
if [ "$LOCAL_ONLY" != "true" ]; then
cd submodules/opentelemetry-java-contrib

mkdir -p "$DESTDIR"
./gradlew --no-daemon -Djdk.lang.Process.launchMechanism=vfork :jmx-metrics:build
cp jmx-metrics/build/libs/opentelemetry-jmx-metrics-*-alpha-SNAPSHOT.jar "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar"

# Rename LICENSE file because it causes issues with file hash consistency due to an unknown
# issue with the debuild/rpmbuild processes. Something is unzipping the jar in a case-insensitive
# environment and having a conflict between the LICENSE file and license/ directory, leading to a changed jar file
mkdir ./META-INF
unzip -j "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar" "META-INF/LICENSE" -d ./META-INF
zip -d "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar" "META-INF/LICENSE"
mv ./META-INF/LICENSE ./META-INF/LICENSE.renamed
zip -u "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar" "META-INF/LICENSE.renamed"

JAR_SHA_256=($(sha256sum "$DESTDIR/opentelemetry-java-contrib-jmx-metrics.jar"))
LDFLAGS="-X github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver.MetricsGathererHash=$JAR_SHA_256"
BINARYLOCATION="$DESTDIR/otelopscol"

cd ../..
fi

cd submodules/opentelemetry-operations-collector
go build -tags=gpu -buildvcs=false -o "$BINARYLOCATION" -ldflags "$LDFLAGS" ./cmd/otelopscol
14 changes: 14 additions & 0 deletions builds/systemd.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -x -e
DESTDIR=$1

Expand Down
14 changes: 14 additions & 0 deletions cloudbuild/new-distro-detector/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# See go/sdi-new-distro-detector for details on how this script is being used.
# A short summary is that it is run periodically by GCB to file bugs when
Expand Down
14 changes: 14 additions & 0 deletions cmd/agent_wrapper/main_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
Expand Down
14 changes: 14 additions & 0 deletions confgenerator/feature_tracking_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package confgenerator

import (
Expand Down
12 changes: 6 additions & 6 deletions dev-docs/makefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ The Makefile `tasks.mak` is a Makefile for the project that is used to quickly p

We are unable to use the actual `Makefile` name in this repo; because we build the Ops Agent into a deb package, `debhelper` tries to autodetect `make` as the build system in most of its `dh_auto` steps. We do not want `debhelper` to pick up the Makfile and try picking up different targets to build and test it.

## Disclaimer

`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.
Comment on lines +10 to +11
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.


## Usage

For convenience it helps to make a symlink from `Makefile` to `tasks.mak` . There is a target to do this, to run it:
```
make -f tasks.mak makefile_symlink
```

Now you can call the targets simply with the `make` command without needing to specify the `tasks.mak` file. The file `Makefile` is gitignored, since we don't want to push it to the repo for the reasons stated in the previous section.
Now you can call the targets simply with the `make` command without needing to specify the `tasks.mak` file. The file `Makefile` is gitignored, since we don't want to push it to the repo for the reasons stated in the previous section.

To run something from the Makefile, you will need to give `make` the `-f` (file) flag with a path to `tasks.mak`. For example, to run the `test` target:
```
Expand All @@ -35,8 +39,4 @@ A new target should be added to `tasks.mak` if:
* There's a new package with Unit Tests
* There is something that developers may need to run often, especially if it's a complicated command
* There are new tasks to run in CI
* There is a new development tool to be installed and used

## Disclaimer

`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.
* There is a new development tool to be installed and used
43 changes: 43 additions & 0 deletions dev-docs/transformation-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Transformation Tests

The transformation tests are tests that will run Fluent Bit and OpenTelemetry Operations Collector (otelopscol) directly in your environment and verify the results of various logging operations by reading their output from stdout and stderr. This is to check the correctness of log parsing expectations in a more lightweight way than full integration tests.

## Makefile Usage

NOTE: It is assumed that you have followed the [makefile setup instructions](./makefile.md#usage).

For your convenience, there is a Makefile target to run transformation tests:
```bash
make transformation_test
```
You can also update the transformation test goldens:
```bash
make transformation_test_update
```
These targets are part of the `precommit` and `precommit_update` targets respectively.

Read on if you are interested in how the transformation tests actually work.

## Usage

The transformation tests take paths to Fluent Bit and otelopscol binaries to execute directly and compare expected output. To run the tests, first you will need to build both binaries. There are scripts to locally build each agent:
```bash
sh ./builds/fluent_bit_local.sh
sh ./builds/otel_local.sh
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
```
After running each script, you will have a `dist` folder that contains each binary.

The paths to each can passed into the test using environment variables or flags.
```bash
go test ./transformation_test -flb=$(pwd)/dist/fluent_bit -otelopscol=$(pwd)/dist/otelopscol
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
```
or
```bash
FLB=$(pwd)/dist/fluent_bit OTELOPSCOL=$(pwd)/dist/otelopscol go test ./transformation_test
```

If you have updated the Fluent Bit or otelopscol submodules and need to update the golden testdata, you can add the `-update` flag to the test.
braydonk marked this conversation as resolved.
Show resolved Hide resolved
```bash
FLB=$(pwd)/dist/fluent_bit OTELOPSCOL=$(pwd)/dist/otelopscol go test ./transformation_test -update
```
(Note: this is a flag to the test, not to `go test`. The flag must go after the specified package, not before.)
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions dockerfiles/compile_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
Expand Down
14 changes: 14 additions & 0 deletions integration_test/gce/zone_picker.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gce

import (
Expand Down
Loading
Loading