Skip to content

Commit

Permalink
Add lint check for golang
Browse files Browse the repository at this point in the history
Summary: Add linter for golang.

Test Plan: Verfified by adding long lines. golint is an inbuilt linter in arc.

Reviewers: sanketh, cvankayalapati, amalyshev

Reviewed By: amalyshev

Subscribers: jenkins-bot, yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D18773
  • Loading branch information
nkhogen committed Aug 8, 2022
1 parent 3b0c447 commit 2e51a82
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 60 deletions.
19 changes: 19 additions & 0 deletions .arclint
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@
"(^python/yb/test_data/.*[.](log|out)$)"
],
"linters": {
"go-files": {
"type": "golint",
"include": "(^managed/.*\\.go$)",
"exclude": [
"(^managed/.*/third-party$)",
"(^managed/.*/generated$)"
]
},
"go-files-length": {
"type": "text",
"text.max-line-length": 100,
"include": "(^managed/.*\\.go$)",
"severity": {
"2": "disabled"
}
},
"script-and-regex.script": {
"type": "script-and-regex",
"include": "(^managed/.*\\.java$)",
Expand All @@ -29,6 +45,9 @@
"type": "text",
"text.max-line-length": 100,
"exclude": [
"(^managed/.*\\.go$)",
"(^managed/.*/go.mod)",
"(^managed/.*/go.sum)",
"(^managed/ui/)",
"(^thirdparty/thirdparty_src_checksums[.]txt$)",
"(^java/yb-client/src/test/java/org/yb/client/TestYBClient[.]java$)",
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/adapters/cli/node/configure.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package node

import (
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/adapters/cli/node/node.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package node

import (
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/adapters/cli/node/preflight_check.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package node

import (
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/adapters/cli/node/register.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package node

import (
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/adapters/cli/node_agent.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package cli

import (
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/adapters/cli/server/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package server

import (
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/app/executor/result.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package executor

//Struct that stores the result of a task executor handler.
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/app/executor/task_executor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package executor

import (
Expand Down
5 changes: 2 additions & 3 deletions managed/node-agent/app/executor/task_executor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) YugaByte, Inc.
*/
// Copyright (c) YugaByte, Inc.

package executor

import (
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/app/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package scheduler

import (
Expand Down
5 changes: 2 additions & 3 deletions managed/node-agent/app/task/http_client_task.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) YugaByte, Inc.
*/
// Copyright (c) YugaByte, Inc.

package task

import (
Expand Down
5 changes: 2 additions & 3 deletions managed/node-agent/app/task/http_client_task_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) YugaByte, Inc.
*/
// Copyright (c) YugaByte, Inc.

package task

import (
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/app/task/shell_task.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package task

import (
Expand Down
5 changes: 2 additions & 3 deletions managed/node-agent/app/task/shell_task_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) YugaByte, Inc.
*/
// Copyright (c) YugaByte, Inc.

package task

import (
Expand Down
14 changes: 3 additions & 11 deletions managed/node-agent/app/task/state_handler_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,9 @@ func (handler *stateHandlerTask) handleUpgradingState(ctx context.Context, confi
util.FileLogger.Info("Starting the node agent Upgrading process")
result, err := HandlePutAgent()(ctx)
if err != nil {
errStr := "Error while posting upgrading state to the platform -"
if data, ok := result.(*model.ResponseError); ok {
util.CliLogger.Errorf("%s %s", errStr, data.Error)
util.FileLogger.Errorf("%s %s", errStr, data.Error)
} else if data, ok := result.(*string); ok {
util.CliLogger.Errorf("%s %s", errStr, *data)
util.FileLogger.Errorf("%s %s", errStr, *data)
} else {
util.CliLogger.Errorf("%s %s", errStr, err.Error())
util.FileLogger.Errorf("%s %s", errStr, err.Error())
}
errStr := "Error while posting upgrading state to the platform"
util.CliLogger.Errorf("%s %s", errStr, err)
util.FileLogger.Errorf("%s %s", errStr, err)
return
}
// Get the latest version certs
Expand Down
91 changes: 61 additions & 30 deletions managed/node-agent/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,55 @@

set -e

GO111MODULE=on
export GO111MODULE=on

package_name='node-agent'
platforms=("darwin/amd64" "linux/amd64" "linux/arm64")
readonly go_version=1.18.2
readonly protoc_version=21.4

base_dir=$(dirname "$0")
readonly package_name='node-agent'
readonly platforms=("darwin/amd64" "linux/amd64" "linux/arm64")
readonly skip_dirs=("third-party" "proto" "generated" "build")
readonly go_dir="$go_version"
readonly protoc_dir="protoc-$protoc_version"

readonly base_dir=$(dirname "$0")
pushd "$base_dir"
project_dir=$(pwd)
readonly project_dir=$(pwd)
popd

GOPATH=$project_dir/third-party
readonly GOPATH=$project_dir/third-party
readonly GOBIN=$GOPATH/$go_dir/go/bin
readonly PROTOCBIN=$GOPATH/$protoc_dir/bin
PATH=$GOBIN:$PROTOCBIN:$PATH
export PATH

build_output_dir="${project_dir}/build"
readonly build_output_dir="${project_dir}/build"
if [[ ! -d $build_output_dir ]]; then
mkdir $build_output_dir
fi
grpc_output_dir="${project_dir}/generated"
readonly grpc_output_dir="${project_dir}/generated"
if [[ ! -d $grpc_output_dir ]]; then
mkdir $grpc_output_dir
fi
grpc_proto_dir=${project_dir}/proto
grpc_proto_files="${grpc_proto_dir}/*.proto"
readonly grpc_proto_dir=${project_dir}/proto
readonly grpc_proto_files="${grpc_proto_dir}/*.proto"

to_lower() {
out=`awk '{print tolower($0)}' <<< "$1"`
echo $out
}

readonly build_os=$(to_lower "$(uname -s)")
readonly uild_arch=$(to_lower "$(uname -m)")

generate_grpc_files() {
protoc -I$grpc_proto_dir --go_out=$grpc_output_dir --go-grpc_out=$grpc_output_dir \
--go-grpc_opt=require_unimplemented_servers=false $grpc_proto_files
}

get_executable_name() {
os=$1
arch=$2
local os=$1
local arch=$2
executable=${package_name}-${os}-${arch}
if [ $os == "windows" ]; then
executable+='.exe'
Expand All @@ -42,8 +59,8 @@ get_executable_name() {
}

build_for_platform() {
os=$1
arch=$2
local os=$1
local arch=$2
exec_name=$(get_executable_name $os $arch)
echo "Building ${exec_name}"
executable="$build_output_dir/$exec_name"
Expand All @@ -55,12 +72,11 @@ build_for_platform() {
}

build_for_platforms() {
build_output_dir=$1
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
os=${platform_split[0]}
arch=${platform_split[1]}
local os=${platform_split[0]}
local arch=${platform_split[1]}
build_for_platform $os $arch
done
}
Expand All @@ -70,25 +86,40 @@ clean_build() {
rm -rf $grpc_output_dir
}



format() {
go install github.com/segmentio/golines@latest
golines -m 100 -t 4 -w $project_dir/adapters/.
golines -m 100 -t 4 -w $project_dir/app/.
golines -m 100 -t 4 -w $project_dir/model/.
golines -m 100 -t 4 -w $project_dir/util/.
go install golang.org/x/tools/cmd/goimports@latest
pushd $project_dir
for dir in */ ; do
# Remove trailing slash.
dir=$(echo ${dir} | sed 's/\/$//')
if [[ "${skip_dirs[@]}" =~ "${dir}" ]]; then
continue
fi
golines -m 100 -t 4 -w ./$dir/.
done
popd
}

run_tests() {
go test --tags testonly -v $project_dir/adapters/...
go test --tags testonly -v $project_dir/app/...
go test --tags testonly -v $project_dir/model/...
go test --tags testonly -v $project_dir/util/...
pushd $project_dir
for dir in */ ; do
# Remove trailing slash.
dir=$(echo ${dir} | sed 's/\/$//')
if [[ "${skip_dirs[@]}" =~ "${dir}" ]]; then
continue
fi
go test --tags testonly -v ./$dir/...
done
popd
}

package_for_platform() {
os=$1
arch=$2
version=$3
local os=$1
local arch=$2
local version=$3
staging_dir_name="node-agent-${version}-${os}-${arch}"
script_dir="${build_output_dir}/${staging_dir_name}/${version}/scripts"
bin_dir="${build_output_dir}/${staging_dir_name}/${version}/bin"
Expand Down Expand Up @@ -117,7 +148,7 @@ package_for_platform() {
}

package_for_platforms() {
version=$1
local version=$1
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
Expand Down Expand Up @@ -208,7 +239,7 @@ if [ "$build" == "true" ]; then
echo "Building..."
format
# generate_grpc_files
build_for_platforms $build_output_dir
build_for_platforms
fi

if [ "$test" == "true" ]; then
Expand Down
1 change: 1 addition & 0 deletions managed/node-agent/cmd/cli/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) YugaByte, Inc.

package main

import (
Expand Down
5 changes: 2 additions & 3 deletions managed/node-agent/model/node_instance.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) YugaByte, Inc.
*/
// Copyright (c) YugaByte, Inc.

package model

import "fmt"
Expand Down
2 changes: 2 additions & 0 deletions managed/node-agent/model/node_state.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) YugaByte, Inc.

package model

type NodeState string
Expand Down
5 changes: 2 additions & 3 deletions managed/node-agent/model/register.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) YugaByte, Inc.
*/
// Copyright (c) YugaByte, Inc.

package model

import "fmt"
Expand Down
3 changes: 2 additions & 1 deletion managed/node-agent/util/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ package util
import (
"encoding/json"
"fmt"
"github.com/gorilla/mux"
"net/http"
"net/http/httptest"
"node-agent/model"
"os"
"strings"

"github.com/gorilla/mux"
)

const (
Expand Down

0 comments on commit 2e51a82

Please sign in to comment.