Skip to content

Replace vfsgen with embed for static web assets - #9719

Merged
juliusv merged 5 commits into
prometheus:mainfrom
jan--f:replace-genvfs
Nov 25, 2021
Merged

juliusv merged 5 commits into
prometheus:mainfrom
jan--f:replace-genvfs

Conversation

@jan--f

@jan--f jan--f commented Nov 11, 2021

Copy link
Copy Markdown
Contributor

This replaces #9380.

Note that this still contains a go mod replace for prometheus/common. I'll remove this once prometheus/common#343 has landed.

Signed-off-by: Jan Fajerski <[email protected]>
This requires go 1.16.

Signed-off-by: Jan Fajerski <[email protected]>
@jan--f
jan--f requested a review from juliusv as a code owner November 11, 2021 13:01
Comment thread Makefile.common Outdated
@echo ">> compressing assets"
@scripts/compress_assets.sh
@echo ">> building binaries"
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If anything goes wrong in this step, the assets stay compressed... could we decompress them not in-place, but to some alternative temporary place, and then embed them from there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

embed will only accept directives that are below or at the same level as the including file (directive may not start the / or include ..) so anything like that would have to happen in web/ui/. I think this requirement will mess with builds not built with builtinassets.
I figured the assets staying compressed is the least bad solution as git would easily be able to revert that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@juliusv How about this solution: the three steps are executed in a single sub-shell, i.e. if the build has an error, the decompress step is run regardless.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the cleanup step as a trap on EXIT. This should now always decompress the assets whether the build fails or succeeds, while returning the correct exit code.
@juliusv I'd much appreciate if you could take another look.

This commit add compression before (and decompression after) prometheus
is build. This ensures that gzipped assets are embeded in the prometheus
binary, if the builtinassets build tag is passed. If the build tag is
not passed this step is still executed but has no effect.
All this is executed in a subshell so that we can run the decompress
step even if the build step fails, but retain the exit code of promu.
This cleanup could also cover interrupts, but I left that out for now.

Signed-off-by: Jan Fajerski <[email protected]>
@juliusv

juliusv commented Nov 25, 2021

Copy link
Copy Markdown
Member

Thanks 👍 I think it's good enough for now. I'm still not super happy with introducing that much new "shell noise" into the Makefile in the long term... but I guess the native Go embedding will never support compression of assets?

@juliusv
juliusv merged commit ddaddc2 into prometheus:main Nov 25, 2021
@jan--f

jan--f commented Nov 25, 2021

Copy link
Copy Markdown
Contributor Author

Thanks, I certainly agree about the shell noise, I tried to keep it to a minimum.
embed might well gain better compression support in the future. Its specifically called out in the design proposal. I'll keep an eye on it.

@juliusv

juliusv commented Nov 25, 2021

Copy link
Copy Markdown
Member

Thanks, that's an interesting read! I hope they add it, as the tradeoffs they talk about would definitely be better with compression in our case :)

@roidelapluie

Copy link
Copy Markdown
Member

I have reverted this pull request for two reasons that we will have to address:

  • the replace in the go.mod is breaking downstream because replace are not taken into account in dependencies
  • the change in makefile.common should belong in Makefile instead

I will make those changes once common is released. thanks!

@jan--f

jan--f commented Nov 26, 2021

Copy link
Copy Markdown
Contributor Author

Thanks and apologies for the churn.

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