-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Return build info under /loki/api/v1/status/buildinfo
.
#3972
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c053e6
Return build info under `/version`.
jeschkies d412f18
Update documentation.
jeschkies 7a5bf6a
Correct docs.
jeschkies a1abdb8
Format version handler code.
jeschkies 202e9c3
Ignore write error.
jeschkies c221621
Sort imports.
jeschkies c782a05
Use `PrometheusVersion` struct.
jeschkies 0882965
Set Go version.
jeschkies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package loki | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
prom "github.com/prometheus/prometheus/web/api/v1" | ||
|
||
"github.com/grafana/loki/pkg/util/build" | ||
) | ||
|
||
func versionHandler() http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
info := prom.PrometheusVersion{ | ||
Version: build.Version, | ||
Revision: build.Revision, | ||
Branch: build.Branch, | ||
BuildUser: build.BuildUser, | ||
BuildDate: build.BuildDate, | ||
GoVersion: build.GoVersion, | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
|
||
// We ignore errors here, because we cannot do anything about them. | ||
// Write will trigger sending Status code, so we cannot send a different status code afterwards. | ||
// Also this isn't internal error, but error communicating with client. | ||
_ = json.NewEncoder(w).Encode(info) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package loki | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/grafana/loki/pkg/util/build" | ||
) | ||
|
||
func TestVersionHandler(t *testing.T) { | ||
build.Version = "0.0.1" | ||
build.Branch = "main" | ||
build.Revision = "foobar" | ||
build.BuildDate = "yesterday" | ||
build.BuildUser = "Turing" | ||
build.GoVersion = "42" | ||
|
||
req := httptest.NewRequest("GET", "http://test.com/config?mode=diff", nil) | ||
w := httptest.NewRecorder() | ||
|
||
h := versionHandler() | ||
h(w, req) | ||
resp := w.Result() | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
|
||
expected := `{ | ||
"version":"0.0.1", | ||
"branch":"main", | ||
"buildDate":"yesterday", | ||
"buildUser":"Turing", | ||
"revision":"foobar", | ||
"goVersion": "42" | ||
}` | ||
body, err := ioutil.ReadAll(resp.Body) | ||
assert.NoError(t, err) | ||
assert.JSONEq(t, expected, string(body)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I access the Go version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the
runtime
package: https://golang.org/pkg/runtime/#VersionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how Prometheus does it as well: https://github.com/prometheus/common/blob/main/version/info.go#L33