Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.

Installer API: Add buildTime and tectonicVersion#2915

Merged
trawler merged 1 commit intocoreos:masterfrom
trawler:master
Feb 12, 2018
Merged

Installer API: Add buildTime and tectonicVersion#2915
trawler merged 1 commit intocoreos:masterfrom
trawler:master

Conversation

@trawler
Copy link
Contributor

@trawler trawler commented Feb 8, 2018

this will add a new endpoint /releases/current to the API
which will fetch TECTONIC_VERSION from the build environment
and displays the build time in a JSON format.

@coreosbot
Copy link

Can one of the admins verify this patch?


//handlers_latest_release.go
mux.Handle("/releases/latest", logRequests(httpHandler("GET", ctx, latestReleaseHandler)))
mux.Handle("/releases/build", logRequests(httpHandler("GET", ctx, currentReleaseHandler)))
Copy link
Contributor

Choose a reason for hiding this comment

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

need to use the name build? because the other is using latest and this new endpoint is to get the current. then maybe use current instead of build

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 was deliberating between the two (I actually created the endpoint with "current" to start with). I thought that "current" sounded weird. can be changed, if you think it's better.

@trawler
Copy link
Contributor Author

trawler commented Feb 8, 2018

Output example:
image

@trawler
Copy link
Contributor Author

trawler commented Feb 8, 2018

changed endpoint from /releases/build to /releases/current per @cpanato suggestion.

alexsomesan
alexsomesan previously approved these changes Feb 8, 2018
Copy link
Contributor

@alexsomesan alexsomesan left a comment

Choose a reason for hiding this comment

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

Very cool solution, Karen! 👍

Copy link
Contributor

@squat squat left a comment

Choose a reason for hiding this comment

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

Overall looks like a fine approach. Needs a little bit of clean up

@@ -0,0 +1,7 @@
package stamp
Copy link
Contributor

Choose a reason for hiding this comment

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

What does stamp mean? Is it timestamp? It is convention to call this package version, see for example https://github.com/coreos/matchbox/blob/master/matchbox/version/version.go or https://github.com/coreos-inc/bridge/blob/master/version/version.go. Please rename for legibility and consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name was taken from a bazel example of using x_defs to add variables to compiled binaries, and they named it "stamped bin". But your suggestion is actually clearer.

package stamp

// TectonicVersion - defaults to 'dev-build' if TECTONIC_VERSION was not set
var TectonicVersion = "dev-build"
Copy link
Contributor

Choose a reason for hiding this comment

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

For simplicity can we just call this Version?

func currentReleaseHandler(w http.ResponseWriter, req *http.Request, _ *Context) error {

verMap := map[string]string{
"TectonicVersion": stamp.TectonicVersion,
Copy link
Contributor

Choose a reason for hiding this comment

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

This returns a json object with title-cased keys, which is a little odd. By convention, json keys are normally camel-cased, or sometimes snake-cased. Can you fix the casing?

// Fetch tectonic's Build version and return in JSON format
func currentReleaseHandler(w http.ResponseWriter, req *http.Request, _ *Context) error {

verMap := map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

For cases such as this where all the fields are known, we typically use an anonymous struct rather than a map. This should also be more memory-efficient

// Fetch tectonic's Build version and return in JSON format
func currentReleaseHandler(w http.ResponseWriter, req *http.Request, _ *Context) error {

verMap := map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to specify the type of this variable in the name. Please rename to just “version”

"TectonicVersion": stamp.TectonicVersion,
"BuildTime": stamp.BuildTime,
}
return writeJSONResponse(w, req, http.StatusOK, verMap)
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this API endpoint consumed in the front end? Without it, this pull request does not fully solve our issue of the reported build version being wrong

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'm planning to add that change in a separate commit

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Separate commit in this same PR or a different PR?

#!/bin/bash

# Vars exported to the build info
echo TECTONIC_VERSION ${TECTONIC_VERSION}
Copy link
Contributor

Choose a reason for hiding this comment

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

Who sets this environment variable? Please add this detail to the build documentation. For consistency, with the rest of the build process, I think that this variable should be simply VERSION

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd actually prefer to keep these environment inputs namespaced like this, with TECTONIC_*

Two reasons for this:

  1. VERSION is much too common and the probability of it affecting other tools or just being used for something else in the system seems rather high.
  2. The prefixing helps to visualize the current state of the environment much easier by piping env to sort.

Copy link
Contributor

Choose a reason for hiding this comment

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

that's fine; the main issues here are twofold:

  1. Who sets this variable? We need this documented somewhere.
  2. We need to make this consistent with the rest of the build process; if we want to go the namespaced route, then that means changing the variables used by the tarball bazel build rule so that we do not need to set two different variables.

Copy link
Contributor Author

@trawler trawler Feb 8, 2018

Choose a reason for hiding this comment

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

I agree with @alexsomesan in that using just VERSION would be too generic. We could use this api endpoint in the future, to output any kind of build information that would help us debug issues, such as go / bazel versions, etc, etc. So I'd opt for modifying the documentation and existing vars.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Please make those changes in this PR then

Copy link
Contributor

Choose a reason for hiding this comment

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

@squat Both are valid questions.
I think for 1) it's whatever RA ends up running in - most likely their Jenkins pipeline.

For 2), if there're no hard blockers, I'd prefer we align everything that's an input to the build process under TECTONIC_ or TECTONIC_BUILD_. We have to keep in mind that the CLI will also support env var overrides. We might want to make a distinction between the runtime and the buildtime inputs (namespaces). But that's mostly off-topic for this change.

buildvars.sh Outdated
@@ -0,0 +1,5 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

please add -e here

@kyoto
Copy link
Contributor

kyoto commented Feb 9, 2018

@kalmog Looks like the commit comment needs updating with the new API endpoint and JSON keys.

Let me know if you need any help with the frontend changes.


// Fetch tectonic's Build version and return in JSON format
func currentReleaseHandler(w http.ResponseWriter, req *http.Request, _ *Context) error {

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you eliminate this extra newline?

Copy link
Contributor

@squat squat left a comment

Choose a reason for hiding this comment

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

I have one small nit, otherwise looks good!

squat
squat previously approved these changes Feb 12, 2018
@trawler
Copy link
Contributor Author

trawler commented Feb 12, 2018

ok to retest

@trawler
Copy link
Contributor Author

trawler commented Feb 12, 2018

retest this please

this will add a new endpoint "/releases/current" to the API
which will fetch TECTONIC_VERSION from the build environment
and displays the build time in a JSON format.
@trawler trawler changed the title Installer API: Add BuildTime and TectonicVersion Installer API: Add buildTime and tectonicVersion Feb 12, 2018
@trawler trawler merged commit 311b0e6 into coreos:master Feb 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants