-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat: expose the fleet manager version #1321
feat: expose the fleet manager version #1321
Conversation
c8f9438
to
e0f2d86
Compare
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.
thanks @valeriiashapoval for this.
I've added some suggestions. Let me know what you think?
can we also add an integration test?
pkg/api/metadata.go
Outdated
if ok != nil { | ||
version = ok.Error() | ||
} |
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.
Maybe we could send the error instead as a 500
http code error?
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.
Should we rename the ok
return to err
here? That's the default name for an error returned from a function. ok
makes it sounds like it's a boolean.
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.
@machi1990 what do you think about returning 500 from the endpoint if fetching the version failed? Returning the error reason in the response is a bit leaky and could lead to problems for whoever is parsing the response: they would have to know to be able to tell an error string from a commit hash string.
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.
Thanks @pb82 @machi1990. Applied the changes!
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.
what do you think about returning 500 from the endpoint if fetching the version failed?
The 500 response is returned as an error in json format so it can parsed.
Concretely, my suggestion is when an error occurs is to call
https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/ce9749f3a293242d72def0349a8e19d67fa65672/pkg/shared/handle_error.go#L11
and return
So the code here will look like
if err != nil {
shared.HandleError(r,w,err)
return
}
11e945f
to
ce9749f
Compare
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.
Please see #1321 (comment)
7d14e4f
to
922bfac
Compare
ID: v.ID, | ||
Kind: "APIVersion", | ||
HREF: r.URL.Path, | ||
ServerVersion: 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.
According to the getCommitSha
implementation, version
here could be an empty string. Is that correct?
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.
@machi1990 WDYT?
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.
That's a good question.
It should never happen in our case ™️ but it is theoretically possible to not receive a commit sha: If the binary is built without the directory containing the git directory then the commit information would not be there. I don't know however in that case if ReadBuildInfo
would return an error or not. I suspect it wouldn't return an error and simply the vcs.revision
key would not exist or be empty.
I think it's a decision up to us. Should we always expect that vcs information be available/non-empty to be able start the server or we just set it as empty in that case ( which shouldn't happen in our use case).
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.
It is acceptable that this is set to empty when we can't find the vcs info, this shouldn't happen for our case as @miguelsorianod pointed out since we copy the git directory in our binary building step in the dockerfile: https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/Dockerfile#L12.
We could of course verify this and or add an integration test for this.
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.
+1
"github.com/getsentry/sentry-go" | ||
"github.com/golang/glog" | ||
) | ||
|
||
func getCommitSha() (string, error) { |
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.
Mind adding a comment explaining what this command does? (which commit sha it returns, when empty string is returned)
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.
@valeriiashapoval can this method be documented as suggested in the previous comment?
5621144
to
be120ce
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1321 +/- ##
=======================================
Coverage 83.65% 83.66%
=======================================
Files 139 139
Lines 12434 12436 +2
=======================================
+ Hits 10402 10404 +2
Misses 1666 1666
Partials 366 366
Flags with carried forward coverage won't be shown. Click here to find out more.
|
openapi/kas-fleet-manager.yaml
Outdated
- id | ||
- href | ||
type: object | ||
properties: |
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.
There is no need to duplicate the kind, id and href properties. The VersionMetadata
object can be defined as a Composition of the ObjectReference
object and a custom object inline that has the server_version and the collections attributes
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.
Thanks @miguelsorianod ! The changes were implemented in the last commit.
TODO when the issue is resolved. | ||
*/ | ||
|
||
g.Expect(version.ServerVersion).To(gomega.BeEmpty()) |
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.
I think there is no value in testing that it is empty so I think we can omit this check and keep the comment
7b21397
to
04d940d
Compare
- $ref: "#/components/schemas/ObjectReference" | ||
- $ref: "#/components/schemas/ObjectReference" | ||
- type: object | ||
example: |
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.
The example should be updated to include server_version with an example value
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.
Thanks a million @miguelsorianod ! Just committed the requested change.
37d96ea
to
9923b3c
Compare
bfc1ade
to
e113a57
Compare
pkg/api/metadata.go
Outdated
"github.com/getsentry/sentry-go" | ||
"github.com/golang/glog" | ||
) | ||
|
||
// getCommitSha() returns the current version (vcs.revision attribute of BuildInfo struct) using a built-in debug package and its ReadBuildInfo() function. | ||
// Upon error, an empty string is returned along with a GeneralError, as well as when vsc.revision is empty/unavailable. |
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.
// Upon error, an empty string is returned along with a GeneralError, as well as when vsc.revision is empty/unavailable.
This is not accurate.
When ReadBuildInfo returns successfully but vcs.revision
is empty/unavailable then no error is returned
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.
Thanks @miguelsorianod . Fixed now!
85b8803
to
4fdc083
Compare
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.
Looks good to me. Great work 👍
/* Unable to test for a specific version as for now due to the debug package issue: https://github.com/golang/go/issues/33976, | ||
TODO when the issue is resolved. | ||
*/ |
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.
Can we create a JIRA out of this?
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.
Thanks @machi1990 ! Will create a Jira for it.
@@ -1966,4 +1969,4 @@ components: | |||
for cluster id: 1g5d88q0lrcdv4g7alb7slfgnj3dhbsj%!(EXTRA *errors.Error=identifier | |||
is '404', code is 'CLUSTERS-MGMT-404' and operation identifier is '1g5or50viu07oealuehrkc26dgftj1ac': | |||
Cluster '1g5d88q0lrcdv4g7alb7slfgnj3dhbsj' not found)" | |||
operation_id: "1iYTsWry6nsqb2sNmFj5bXpD7Ca" | |||
operation_id: "1iYTsWry6nsqb2sNmFj5bXpD7Ca" |
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.
operation_id: "1iYTsWry6nsqb2sNmFj5bXpD7Ca" | |
operation_id: "1iYTsWry6nsqb2sNmFj5bXpD7Ca" | |
nit adding newline at end of file
// Get the version: | ||
version, err := getCommitSha() | ||
if err != nil { | ||
shared.HandleError(r, w, err.(*errors.ServiceError)) |
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.
the err.(*errors.ServiceError)
cast assumes all errors from getCommitSha
will be service error. It is fine for now since only the GeneralError is returned. To be on the safe side I'd have used errors.ToServiceError(err)
here.
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.
lgtm
left some minor comments for future considerations.
Let's also create a JIRA out of the TODO comment.
Thanks for the superb work @valeriiashapoval
Thanks @miguelsorianod @machi1990 ! |
Thanks @valeriiashapoval and @miguelsorianod When testing this change against a built KFM docker image, I see that the server_version is always empty. |
As potentially useful information: build VCS information is only included if the |
…is read during build This follows up on bf2fc6cc711aee1a0c2a#1321, notably bf2fc6cc711aee1a0c2a#1321 (comment)
Yes, this is the case already: Line 12 in 27db8c5
I've found the missing piece, please have a look at #1333 |
Description
(https://issues.redhat.com/browse/MGDSTRM-9585)
Verification Steps
make run
from the rootcurl -H "Authorization: Bearer $(ocm token)" http://localhost:8000/api/kafkas_mgmt/v1 | jq .
Checklist (Definition of Done)