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

Update version.go to fix running a server built from source #4170

Closed
wants to merge 4 commits into from

Conversation

js-ts
Copy link
Contributor

@js-ts js-ts commented Jun 29, 2024

currently when you try to run a server using the binary built from source and try to run any command it throws this error, this error can be fixed by stripping the metadata from version before parsing

To run test jobs against the local cluster which uses the build from source binary without getting this error everytime a job is run this error needs to be fixed

bin/darwin/amd64/bacalhau serve --node-type compute --node-type requester

bin/darwin/amd64/bacalhau node list

Error: failed request: Unexpected response code: 403 ({
  "Error": "Client version is outdated. Update your client",
  "MinVersion": "1.4.0",
  "ClientVersion": "1.4.0-6-g081eabfba",
  "ServerVersion": "1.4.0-6-g081eabfba"
})

currently when you try to run a server using the binary built from 
source and try to run any command it throws this error, this error can be fixed by  stripping the metadata from version before parsing

bin/darwin/amd64/bacalhau serve --node-type compute --node-type requester

bin/darwin/amd64/bacalhau node list
```
Error: failed request: Unexpected response code: 403 ({
  "Error": "Client version is outdated. Update your client",
  "MinVersion": "1.4.0",
  "ClientVersion": "1.4.0-6-g081eabfba",
  "ServerVersion": "1.4.0-6-g081eabfba"
})
```
Copy link
Contributor

coderabbitai bot commented Jun 29, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@frrist frrist left a comment

Choose a reason for hiding this comment

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

The problem here is that versions with a pre-release are considered less than versions without a prerelease all other fields equal. i.e. v1.4.0 > v1.4.0-abc123. I believe the correct change here is to strip the pre-release tag from the client before doing the comparison. @wdbaruni wdyt?

pkg/publicapi/middleware/version.go Outdated Show resolved Hide resolved
pkg/publicapi/middleware/version.go Outdated Show resolved Hide resolved
@js-ts js-ts requested a review from frrist July 17, 2024 04:13
@js-ts
Copy link
Contributor Author

js-ts commented Jul 29, 2024

@frrist

Comment on lines +82 to +93

// Strip the pre-release tag
strippedClientVersion, err := stripPreRelease(clientVersion)
if err != nil {
notif.Message = fmt.Sprintf("error stripping pre-release tag from client version: %s", err)
return nil
}

// extract parsed client version for comparison
notif.ClientVersion = clientVersion.String()
notif.ClientVersion = strippedClientVersion.String()

diff := serverVersion.Compare(clientVersion)
diff := serverVersion.Compare(strippedClientVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't want to strip the client version here, this method is for logging the version of the request received from the client. Please revert this change.

Comment on lines +32 to +40
func stripPreRelease(version *semver.Version) (*semver.Version, error) {
newVersion, _ := semver.NewVersion(version.String())
_, err := newVersion.SetPrerelease("")
if err != nil {
return nil, err
}
return newVersion, nil
}

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
func stripPreRelease(version *semver.Version) (*semver.Version, error) {
newVersion, _ := semver.NewVersion(version.String())
_, err := newVersion.SetPrerelease("")
if err != nil {
return nil, err
}
return newVersion, nil
}
func stripPreRelease(versionStr string) (*semver.Version, error) {
v, err := semver.NewVersion(versionStr)
if err != nil {
return version.Unknown, fmt.Errorf("failed to parse client version: %w", err)
}
strippedVersion, err := v.SetPrerelease("")
if err != nil {
return version.Unknown, fmt.Errorf("failed to strip pre-release version from client: %w", err)
}
return &strippedVersion, nil
}

please move this utility method to the bottom of the file.

@@ -109,12 +126,20 @@ func VersionCheckMiddleware(serverVersion, minVersion semver.Version) echo.Middl
})
}

if clientVersion.LessThan(&minVersion) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use the suggested implementation of stripPreRelease here to both parse and strip the client version, i.e.

// VersionCheckMiddleware returns a middleware that checks if the client version is at least minVersion.
func VersionCheckMiddleware(serverVersion, minVersion semver.Version) echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			clientVersionStr := c.Request().Header.Get(apimodels.HTTPHeaderBacalhauGitVersion)
			if clientVersionStr == "" ||
				clientVersionStr == version.DevelopmentGitVersion ||
				clientVersionStr == version.UnknownGitVersion {
				// allow the request to pass through
				return next(c)
			}

			clientVersion, err := stripPreRelease(clientVersionStr)
			if err != nil {
				return c.JSON(http.StatusBadRequest, map[string]string{
					"Error": "Invalid client version " + clientVersionStr,
				})
			}

			if clientVersion.LessThan(&minVersion) {
				// Client version is less than the minimum required version
				return c.JSON(http.StatusForbidden, VersionCheckError{
					Error:         "Client version is outdated. Update your client",
					MinVersion:    minVersion.String(),
					ClientVersion: clientVersion.String(),
					ServerVersion: serverVersion.String(),
				})
			}

			// Client version is acceptable, proceed with the request
			return next(c)
		}
	}
}

@wdbaruni
Copy link
Member

I don't think this is an issue anymore

@wdbaruni wdbaruni closed this Sep 24, 2024
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