Skip to content

[WIP] feat(version): add server version endpoint and client version display#664

Draft
ilopezluna wants to merge 3 commits intomainfrom
add-server-version
Draft

[WIP] feat(version): add server version endpoint and client version display#664
ilopezluna wants to merge 3 commits intomainfrom
add-server-version

Conversation

@ilopezluna
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ilopezluna, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust versioning mechanism across the application. It ensures that version details are embedded into compiled binaries during the build process, exposes this information via a dedicated server API endpoint, and enhances the command-line interface to display both client and server version details. This provides improved transparency and diagnostic capabilities regarding the application's deployed state.

Highlights

  • Version Embedding: The build process for the Go binaries has been updated to embed version information directly into the executables using ldflags.
  • Server Version Endpoint: A new /version HTTP endpoint has been added to the server, allowing clients to query the server's running version.
  • Enhanced CLI Version Command: The docker model-runner version command now displays detailed client information (version, OS/Arch) and attempts to fetch and display the server's version.
  • Desktop Client API for Server Version: A new method ServerVersion() was added to the desktop client to facilitate fetching the server's version from the new endpoint.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • Dockerfile
    • Added build arguments for versioning.
    • Modified Go build commands to embed the version string.
  • Makefile
    • Updated the build command to embed the Git version into the binary.
  • cmd/cli/commands/version.go
    • Imported the runtime package.
    • Enhanced the version command to show client and server versions, including OS/Arch.
  • cmd/cli/desktop/desktop.go
    • Defined ServerVersionResponse struct.
    • Implemented ServerVersion() method to fetch server version via API.
  • main.go
    • Imported encoding/json.
    • Added a new /version HTTP endpoint.
  • version.go
    • Created a new file to declare the Version variable.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/release.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces versioning support by adding a /version endpoint to the server and a version command to the CLI. The version is injected at build time using ldflags, both in the Dockerfile and the local Makefile build. The CLI now displays both client and server versions. My review identifies a logic bug in the new CLI command that incorrectly reports server information in standalone mode, and a minor issue where an error is ignored in the new server endpoint. Code suggestions are provided for both issues.

Comment on lines +22 to +33
if desktopClient == nil {
cmd.Println(" Version: (not reachable)")
cmd.Println(" Engine: (not reachable)")
return
}
sv, err := desktopClient.ServerVersion()
if err != nil {
cmd.Println(" Version: (not reachable)")
} else {
cmd.Printf(" Version: %s\n", sv.Version)
}
cmd.Printf(" Engine: %s\n", modelRunner.EngineKind())
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current logic for displaying server information in the version command has a couple of issues. First, it incorrectly reports the engine as (not reachable) when running in standalone mode (when desktopClient is nil). The engine kind is a client-side property and should be available. Second, the logic is a bit repetitive and can be simplified for better readability and correctness.

I suggest refactoring this section to always display the engine kind and to determine the server version more concisely.

            serverVersion := "(not reachable)"
            if desktopClient != nil {
                if sv, err := desktopClient.ServerVersion(); err == nil {
                    serverVersion = sv.Version
                }
            }
            cmd.Printf(" Version:    %s\n", serverVersion)
            cmd.Printf(" Engine:     %s\n", modelRunner.EngineKind())

// Register /version endpoint
router.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]string{"version": Version})
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The error returned by json.NewEncoder(w).Encode() is being ignored. While errors are unlikely when writing to an http.ResponseWriter, they can occur (e.g., if the client closes the connection). It's a good practice to handle this error, for example by logging it, to aid in debugging potential network issues.

if err := json.NewEncoder(w).Encode(map[string]string{"version": Version}); err != nil {
			log.Warnf("failed to write version response: %v", err)
		}

# Conflicts:
#	.github/workflows/release.yml
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.

1 participant