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

feat: expose the fleet manager version #1321

Conversation

valeriiashapoval
Copy link
Contributor

Description

(https://issues.redhat.com/browse/MGDSTRM-9585)

Verification Steps

  1. run make run from the root
  2. run curl -H "Authorization: Bearer $(ocm token)" http://localhost:8000/api/kafkas_mgmt/v1 | jq .

Checklist (Definition of Done)

  • All acceptance criteria specified in JIRA have been completed
  • Unit and integration tests added that prove the fix is effective or the feature works (tested against emulated and non-emulated OCM environment)
  • Documentation added for the feature
  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer
  • All PR comments are resolved either by addressing them or creating follow up tasks
  • Required metrics/dashboards/alerts have been added (or PR created).
  • Required Standard Operating Procedure (SOP) is added.
  • JIRA has been created for changes required on the client side

Copy link
Contributor

@machi1990 machi1990 left a 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 Show resolved Hide resolved
pkg/api/metadata.go Outdated Show resolved Hide resolved
pkg/api/metadata.go Outdated Show resolved Hide resolved
pkg/api/metadata.go Outdated Show resolved Hide resolved
Comment on lines 89 to 96
if ok != nil {
version = ok.Error()
}
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor

@machi1990 machi1990 Sep 21, 2022

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
}

@pb82 @valeriiashapoval

pkg/api/metadata.go Outdated Show resolved Hide resolved
pkg/api/metadata.go Outdated Show resolved Hide resolved
@miguelsorianod
Copy link
Contributor

miguelsorianod commented Sep 21, 2022

The changes seem to have an impact on the connectors code test. cc @valdar @dhirajsb.

This will also impact the connectors API.

Copy link
Contributor

@machi1990 machi1990 left a 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)

@valeriiashapoval valeriiashapoval force-pushed the expose-the-kfm-version branch 2 times, most recently from 7d14e4f to 922bfac Compare September 21, 2022 11:32
ID: v.ID,
Kind: "APIVersion",
HREF: r.URL.Path,
ServerVersion: version,
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

@machi1990 WDYT?

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 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).

Copy link
Contributor

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.

Copy link
Contributor

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) {
Copy link
Contributor

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)

Copy link
Contributor

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?

pkg/api/metadata.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 27, 2022

Codecov Report

Merging #1321 (85b8803) into main (9595c5d) will increase coverage by 0.00%.
The diff coverage is n/a.

❗ Current head 85b8803 differs from pull request most recent head 4fdc083. Consider uploading reports for the commit 4fdc083 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@           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           
Flag Coverage Δ
unittests 83.66% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ernal/workers/cluster_mgrs/dynamic_scale_up_mgr.go 66.66% <0.00%> (+0.29%) ⬆️

- id
- href
type: object
properties:
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 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

Copy link
Contributor Author

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())
Copy link
Contributor

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

- $ref: "#/components/schemas/ObjectReference"
- $ref: "#/components/schemas/ObjectReference"
- type: object
example:
Copy link
Contributor

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

Copy link
Contributor Author

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.

@valeriiashapoval valeriiashapoval force-pushed the expose-the-kfm-version branch 2 times, most recently from bfc1ade to e113a57 Compare September 30, 2022 11:50
"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.
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @miguelsorianod . Fixed now!

Copy link
Contributor

@miguelsorianod miguelsorianod left a 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 👍

Comment on lines +37 to +39
/* 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.
*/
Copy link
Contributor

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?

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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))
Copy link
Contributor

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.

Copy link
Contributor

@machi1990 machi1990 left a 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

@valeriiashapoval
Copy link
Contributor Author

Thanks @miguelsorianod @machi1990 !
The JIRA for the TODO comment: https://issues.redhat.com/browse/MGDSTRM-9842

@miguelsorianod miguelsorianod merged commit 27db8c5 into bf2fc6cc711aee1a0c2a:main Sep 30, 2022
@machi1990
Copy link
Contributor

Thanks @valeriiashapoval and @miguelsorianod

When testing this change against a built KFM docker image, I see that the server_version is always empty.
However, the make run command works. I am current looking if it is just my setup or there is something missing on the current PR.

@valeriiashapoval valeriiashapoval deleted the expose-the-kfm-version branch September 30, 2022 15:42
@miguelsorianod
Copy link
Contributor

miguelsorianod commented Sep 30, 2022

Thanks @valeriiashapoval and @miguelsorianod

When testing this change against a built KFM docker image, I see that the server_version is always empty. However, the make run command works. I am current looking if it is just my setup or there is something missing on the current PR.

As potentially useful information: build VCS information is only included if the .git directory is available when doing the build

@machi1990
Copy link
Contributor

machi1990 commented Sep 30, 2022

Thanks @valeriiashapoval and @miguelsorianod
When testing this change against a built KFM docker image, I see that the server_version is always empty. However, the make run command works. I am current looking if it is just my setup or there is something missing on the current PR.

As potentially useful information: build VCS information is only included if the .git directory is available when doing the build

Yes, this is the case already:

COPY . ./

I've found the missing piece, please have a look at #1333
@miguelsorianod @valeriiashapoval

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants