Skip to content

Commit

Permalink
Show Server Version in Yorkie CLI (#938)
Browse files Browse the repository at this point in the history
This commit adds the functionality to display the version of connected
Yorkie server in the version command.

The version information can be viewed by converting it into yaml or
json format using the --output, -o flag. This flag accepts json and
yaml strings and converts them to the appropriate format for display.
In order to solely check the version of the client CLI without
considering the server's version, the --client flag has been included.
The development of this feature was inspired by examining the kubectl.
  • Loading branch information
hyun98 authored and hackerwins committed Aug 9, 2024
1 parent db9da1e commit fbc6098
Show file tree
Hide file tree
Showing 12 changed files with 579 additions and 129 deletions.
14 changes: 14 additions & 0 deletions admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,20 @@ func (c *Client) ListChangeSummaries(
return summaries, nil
}

// GetServerVersion gets the server version.
func (c *Client) GetServerVersion(ctx context.Context) (*types.VersionDetail, error) {
response, err := c.client.GetServerVersion(ctx, connect.NewRequest(&api.GetServerVersionRequest{}))
if err != nil {
return nil, err
}

return &types.VersionDetail{
YorkieVersion: response.Msg.YorkieVersion,
GoVersion: response.Msg.GoVersion,
BuildDate: response.Msg.BuildDate,
}, nil
}

/**
* withShardKey returns a context with the given shard key in metadata.
*/
Expand Down
56 changes: 56 additions & 0 deletions api/docs/yorkie/v1/admin.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ paths:
$ref: '#/components/responses/connect.error'
tags:
- yorkie.v1.AdminService
/yorkie.v1.AdminService/GetServerVersion:
post:
description: ""
requestBody:
$ref: '#/components/requestBodies/yorkie.v1.AdminService.GetServerVersion.yorkie.v1.GetServerVersionRequest'
responses:
"200":
$ref: '#/components/responses/yorkie.v1.AdminService.GetServerVersion.yorkie.v1.GetServerVersionResponse'
default:
$ref: '#/components/responses/connect.error'
tags:
- yorkie.v1.AdminService
/yorkie.v1.AdminService/GetSnapshotMeta:
post:
description: ""
Expand Down Expand Up @@ -246,6 +258,15 @@ components:
schema:
$ref: '#/components/schemas/yorkie.v1.GetProjectRequest'
required: true
yorkie.v1.AdminService.GetServerVersion.yorkie.v1.GetServerVersionRequest:
content:
application/json:
schema:
$ref: '#/components/schemas/yorkie.v1.GetServerVersionRequest'
application/proto:
schema:
$ref: '#/components/schemas/yorkie.v1.GetServerVersionRequest'
required: true
yorkie.v1.AdminService.GetSnapshotMeta.yorkie.v1.GetSnapshotMetaRequest:
content:
application/json:
Expand Down Expand Up @@ -391,6 +412,15 @@ components:
schema:
$ref: '#/components/schemas/yorkie.v1.GetProjectResponse'
description: ""
yorkie.v1.AdminService.GetServerVersion.yorkie.v1.GetServerVersionResponse:
content:
application/json:
schema:
$ref: '#/components/schemas/yorkie.v1.GetServerVersionResponse'
application/proto:
schema:
$ref: '#/components/schemas/yorkie.v1.GetServerVersionResponse'
description: ""
yorkie.v1.AdminService.GetSnapshotMeta.yorkie.v1.GetSnapshotMetaResponse:
content:
application/json:
Expand Down Expand Up @@ -868,6 +898,32 @@ components:
type: object
title: GetProjectResponse
type: object
yorkie.v1.GetServerVersionRequest:
additionalProperties: false
description: ""
title: GetServerVersionRequest
type: object
yorkie.v1.GetServerVersionResponse:
additionalProperties: false
description: ""
properties:
buildDate:
additionalProperties: false
description: ""
title: build_date
type: string
goVersion:
additionalProperties: false
description: ""
title: go_version
type: string
yorkieVersion:
additionalProperties: false
description: ""
title: yorkie_version
type: string
title: GetServerVersionResponse
type: object
yorkie.v1.GetSnapshotMetaRequest:
additionalProperties: false
description: ""
Expand Down
22 changes: 22 additions & 0 deletions api/types/version_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package types

// VersionInfo represents information of version.
type VersionInfo struct {
// ClientVersion is the yorkie cli version.
ClientVersion *VersionDetail `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"`

// ServerVersion is the yorkie server version.
ServerVersion *VersionDetail `json:"serverVersion,omitempty" yaml:"serverVersion,omitempty"`
}

// VersionDetail represents detail information of version.
type VersionDetail struct {
// YorkieVersion
YorkieVersion string `json:"yorkieVersion" yaml:"yorkieVersion"`

// GoVersion
GoVersion string `json:"goVersion" yaml:"goVersion"`

// BuildDate
BuildDate string `json:"buildDate" yaml:"buildDate"`
}
386 changes: 265 additions & 121 deletions api/yorkie/v1/admin.pb.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions api/yorkie/v1/admin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ service AdminService {
rpc SearchDocuments (SearchDocumentsRequest) returns (SearchDocumentsResponse) {}

rpc ListChanges (ListChangesRequest) returns (ListChangesResponse) {}

rpc GetServerVersion (GetServerVersionRequest) returns (GetServerVersionResponse) {}
}

message SignUpRequest {
Expand Down Expand Up @@ -184,3 +186,11 @@ message ListChangesRequest {
message ListChangesResponse {
repeated Change changes = 1;
}

message GetServerVersionRequest {}

message GetServerVersionResponse {
string yorkie_version = 1;
string go_version = 2;
string build_date = 3;
}
27 changes: 27 additions & 0 deletions api/yorkie/v1/v1connect/admin.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/yorkie/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func LoadAuth(addr string) (Auth, error) {

auth, ok := config.Auths[addr]
if !ok {
return Auth{}, fmt.Errorf("auth for %s does not exist", addr)
return Auth{}, fmt.Errorf("auth for '%s' does not exist", addr)
}

return auth, nil
Expand Down
Loading

0 comments on commit fbc6098

Please sign in to comment.