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

refactors logging to use annonation style #2546

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

jaxesn
Copy link
Member

@jaxesn jaxesn commented Oct 12, 2023

Issue #, if available:

Description of changes:

While working on improving the docker usage via the build targets, basically transparently using docker where necessary instead of relying on the eng to run the in-docker target, I found an interesting (probably hacky) approach for adding target variables via a secondarily expanded prereq. In that case I am using this approach to dynamically add the docker target as a prereq to the real target and then overriding the shell to true so that the on host command do not even run, since they ran in the docker container. This seems to work pretty well but I have a problem regarding how make outputs the commands before it runs them.

While trying to solve the problem of outputting these commands, even tho they were not actually going to run, I was playing with this idea of using a bash script as the shell we could better control this output. This PR introduces an approach where instead of calling log_start and log_end in the recipe a secondarily expanded prereq is added, which just adds the shell override for the specific topic. Since this is secondarily expanded, the shell is not overridden until the target is actually be executed. This along with the new wildcard target which resets the SHELL to the default, makes it so that prereq targets do not inherit this shell override, which is the default for variables of targets with respect to that target's prereqs.

There are some cases where $(shell) calls are resolved during the generation + execution of recipe, in which case those will end up using the overridden SHELL, the bash script. In this case, we use an export variable, which only applies for the target given the enable_logging prereq to determine if we should log the pre and post log message.

The output of these targets should be same as before, as an example:

------------------- 2023-10-12T18:55:10.034+0000 Starting target=_output/bin/kube-vip/linux-amd64/kube-vip -------------------
(/home/prow/go/src/github.com/aws/eks-anywhere-build-tooling/projects/kube-vip/kube-vip) $ /home/prow/go/src/github.com/aws/eks-anywhere-build-tooling/build/lib/simple_create_binaries.sh /home/prow/go/src/github.com/aws/eks-anywhere-build-tooling/projects/kube-vip/kube-vip /home/prow/go/src/github.com/aws/eks-anywhere-build-tooling/projects/kube-vip/kube-vip/_output/bin/kube-vip/linux-amd64/kube-vip kube-vip 1.19 linux/amd64 "." "build" "" "-s -w -buildid= -extldflags -static " 0 "" "." "kube-vip"
Adding /go/go1.19/bin to PATH
Building binary(s): kube-vip
GOOS: linux
GOARCH: amd64
CGO_ENABLED: 0
GOCACHE: /root/.cache/go-build/1.19
(/home/prow/go/src/github.com/aws/eks-anywhere-build-tooling/projects/kube-vip/kube-vip/kube-vip) $ go build -trimpath -a -ldflags -s -w -buildid= -extldflags -static  -o /home/prow/go/src/github.com/aws/eks-anywhere-build-tooling/projects/kube-vip/kube-vip/_output/bin/kube-vip/linux-amd64/kube-vip .
------------------- 2023-10-12T18:56:17.404+0000 Finished target=_output/bin/kube-vip/linux-amd64/kube-vip duration=67.373 seconds -------------------

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@eks-distro-bot eks-distro-bot added do-not-merge/hold size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 12, 2023
@jaxesn jaxesn force-pushed the jgw/cleaner-logging branch 2 times, most recently from 54808e5 to a9d62ea Compare October 12, 2023 18:40
@jaxesn jaxesn force-pushed the jgw/cleaner-logging branch from a9d62ea to 8216155 Compare October 12, 2023 18:52
@@ -840,7 +827,8 @@ release: $(RELEASE_TARGETS)
# Iterate over release branch versions, avoiding branches explicitly marked as skipped
.PHONY: %/release-branches/all
%/release-branches/all:
@for version in $(SUPPORTED_K8S_VERSIONS) ; do \
@set -e; \
Copy link
Member Author

Choose a reason for hiding this comment

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

on mac shellflags are not passed to the shell and missing this -e is annoying when running this locally since it ends up just continuing even if one version fails.

@@ -149,7 +152,7 @@ function build::gather_licenses() {
# data about each dependency to generate the amazon approved attribution.txt files
# go-deps is needed for module versions
# go-licenses are all the dependencies found from the module(s) that were passed in via patterns
build::common::echo_and_run go list -deps=true -json ./... | jq -s '' > "${outputdir}/attribution/go-deps.json"
build::common::echo_and_run go list -deps=true -json ./... | jq -s '.' > "${outputdir}/attribution/go-deps.json"
Copy link
Member Author

Choose a reason for hiding this comment

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

newer versions of jq do not like hte empty string. the . should be the same.

Copy link
Member

@abhay-krishna abhay-krishna left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@eks-distro-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhay-krishna

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jaxesn
Copy link
Member Author

jaxesn commented Oct 12, 2023

/unhold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants