Skip to content

Commit

Permalink
chore(go-client-ci): build the server instead of downloading it from …
Browse files Browse the repository at this point in the history
…external site (#1790)

#1779

- separate format and lint jobs
- build Pegasus server binaries in the CI procedure instead of downloading it from any site
- fix lint and test failures
- improve readme
  • Loading branch information
acelyc111 authored Dec 26, 2023
1 parent a397c07 commit 28df30e
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 151 deletions.
116 changes: 94 additions & 22 deletions .github/workflows/lint_and_test_go-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,103 @@ on:
# for manually triggering workflow
workflow_dispatch:

env:
ARTIFACT_NAME: release_for_go_client

# workflow tasks
jobs:
build:
name: Test and Lint
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Format
working-directory: ./go-client
run: |
gofmt -d .
test -z "$(gofmt -d .)"
lint:
name: Lint
needs: format
# go-client imports thrift package of 0.13.0, so we must use thrift-compiler 0.13.0
# to generate code as well. The thrift-compiler version on ubuntu-20.04 is 0.13.0
runs-on: ubuntu-20.04
steps:
- name: Install thrift
# go-client imports thrift package of 0.13.0, so we must use thrift-compiler 0.13.0
# to generate code as well. The thrift-compiler version on ubuntu-20.04 is 0.13.0
run: sudo apt-get install -y thrift-compiler
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Run Test
run: ./test.sh
working-directory: ./go-client
- uses: codecov/codecov-action@v2
with:
- name: Install thrift
run: sudo apt-get install -y thrift-compiler
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Build
working-directory: ./go-client
# because some files are generated after building, so lint after that at last
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
run: make build
# because some files are generated after building, so lint after the build step
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
working-directory: ./go-client

build_server:
name: Build server
needs: lint
runs-on: ubuntu-latest
env:
USE_JEMALLOC: OFF
BUILD_OPTIONS: -t release
container:
image: apache/pegasus:thirdparties-bin-test-ubuntu2204-${{ github.base_ref }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/rebuild_thirdparty_if_needed"
- uses: "./.github/actions/build_pegasus"
- uses: "./.github/actions/upload_artifact"

test_go_client:
name: Test Go client
needs: build_server
runs-on: ubuntu-latest
container:
image: apache/pegasus:thirdparties-bin-test-ubuntu2204-${{ github.base_ref }}
steps:
# go-client imports thrift package of 0.13.0, so we must use thrift-compiler 0.13.0
# to generate code as well. The thrift-compiler version on ubuntu-22.04 is 0.16.0, so
# build and install thrift-compiler 0.13.0 manually.
- name: Install thrift
run: |
export THRIFT_VERSION=0.13.0
wget --progress=dot:giga https://github.com/apache/thrift/archive/refs/tags/v${THRIFT_VERSION}.tar.gz
tar -xzf v${THRIFT_VERSION}.tar.gz
cd thrift-${THRIFT_VERSION}
./bootstrap.sh
./configure --enable-libs=no
make -j $(nproc)
make install
cd - && rm -rf thrift-${THRIFT_VERSION} v${THRIFT_VERSION}.tar.gz
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
- uses: "./.github/actions/download_artifact"
- name: Start Pegasus cluster
run: |
export LD_LIBRARY_PATH=$(pwd)/thirdparty/output/lib:${JAVA_HOME}/jre/lib/amd64/server
ulimit -s unlimited
./run.sh start_onebox
- name: Run Go client tests
working-directory: ./go-client
run: |
GO111MODULE=on make build
./bin/echo > /dev/null 2>&1 &
GO111MODULE=on make ci
24 changes: 22 additions & 2 deletions go-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,31 @@ under the License.

## Requirement

Go1.18+.
- Go1.18+
- thrift 0.13

## Development

Build the pegasus-go-client:
```bash
make build
```

Format the code:
```bash
make fmt
```

It requires the Pegasus [onebox](https://pegasus.apache.org/overview/onebox/) has been started.

Then run tests:
```bash
make ci
```

## Logging

By default pegasus-go-client logs to "./pegasus.log" on where your application runs.
By default, pegasus-go-client logs to "./pegasus.log" on where your application runs.
You can customize the logging rules as follows:

```go
Expand Down
6 changes: 3 additions & 3 deletions go-client/admin/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ func TestAdmin_CreateTableMustAvailable(t *testing.T) {
const tableName = "admin_table_test"

c := NewClient(Config{
MetaServers: []string{"0.0.0.0:34601"},
MetaServers: []string{"0.0.0.0:34601", "0.0.0.0:34602", "0.0.0.0:34603"},
})

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

err := c.CreateTable(context.Background(), tableName, 1)
err := c.CreateTable(context.Background(), tableName, 8)
if !assert.NoError(t, err) {
assert.Fail(t, err.Error())
}

// ensures the created table must be available for read and write
rwClient := pegasus.NewClient(pegasus.Config{
MetaServers: []string{"0.0.0.0:34601"},
MetaServers: []string{"0.0.0.0:34601", "0.0.0.0:34602", "0.0.0.0:34603"},
})
defer func() {
err = rwClient.Close()
Expand Down
2 changes: 1 addition & 1 deletion go-client/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {
for t := 0; t < 10; t++ {
var sortKeys [][]byte
for i := 0; i < 10; i++ {
sortKeys = append(sortKeys, []byte("sort"+string(i)))
sortKeys = append(sortKeys, []byte("sort"+fmt.Sprint(i)))
}
for i := 0; i < 10; i++ {
err = tb.Set(context.Background(), []byte("hash"), sortKeys[i], value)
Expand Down
70 changes: 28 additions & 42 deletions go-client/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ func generateAdminRPC(rpcCode, rpcName, reqName, respName string) string {
return s
}

func generateHeader() {
fmt.Print(`/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Code generated by "generator -i=admin.csv > admin_rpc_types.go"; DO NOT EDIT.
package session
`)
}

func generateAllAdminRPC() {
content, err := ioutil.ReadFile(inputFilePath)
if err != nil {
Expand All @@ -77,28 +103,8 @@ func generateAllAdminRPC() {
os.Exit(1)
}

fmt.Print(`/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/`)
generateHeader()
fmt.Print(`
// Code generated by "generator -i=admin.csv > admin_rpc_types.go"; DO NOT EDIT.
package session
import (
"context"
"fmt"
Expand Down Expand Up @@ -153,28 +159,8 @@ func generateAllRAdminRPC() {
os.Exit(1)
}

fmt.Print(`/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/`)
generateHeader()
fmt.Print(`
// Code generated by "generator -i=admin.csv > admin_rpc_types.go"; DO NOT EDIT.
package session
import (
"context"
"fmt"
Expand Down
1 change: 0 additions & 1 deletion go-client/idl/base/dsn_err_string.go

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

35 changes: 18 additions & 17 deletions go-client/session/admin_rpc_types.go

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

35 changes: 18 additions & 17 deletions go-client/session/radmin_rpc_types.go

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

Loading

0 comments on commit 28df30e

Please sign in to comment.