mirror of
https://github.com/jkstack/libagent.git
synced 2025-12-24 12:11:57 +08:00
增加lint脚本
This commit is contained in:
40
.github/workflows/lint.yaml
vendored
Normal file
40
.github/workflows/lint.yaml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: libagent
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-18.04
|
||||
- ubuntu-20.04
|
||||
- ubuntu-22.04
|
||||
- windows-2019
|
||||
- windows-2022
|
||||
- macos-10.15
|
||||
- macos-11
|
||||
- macos-12
|
||||
go:
|
||||
- '1.17'
|
||||
- '1.18'
|
||||
- '1.19'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
|
||||
- name: Lint
|
||||
run: |
|
||||
go install golang.org/x/lint/golint@latest
|
||||
golint -set_exit_status ./...
|
||||
go install github.com/gordonklaus/ineffassign@latest
|
||||
ineffassign ./...
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
runtime "github.com/jkstack/jkframe/utils"
|
||||
)
|
||||
|
||||
// RewriteServer rewrite server configure
|
||||
// - use $... to set value by envionment variables
|
||||
func (cfg *Configure) RewriteServer() {
|
||||
cfg.Server = strings.TrimSpace(cfg.Server)
|
||||
if len(cfg.Server) == 0 {
|
||||
@@ -28,6 +30,10 @@ func (cfg *Configure) RewriteServer() {
|
||||
}
|
||||
}
|
||||
|
||||
// RewriteID rewrite agent id configure
|
||||
// - use $IP to set value by ip address in interface to connect server
|
||||
// - use $HOSTNAME to set value by hostname
|
||||
// - use $... to set value by envionment variables
|
||||
func (cfg *Configure) RewriteID() {
|
||||
cfg.RewriteServer()
|
||||
cfg.ID = strings.TrimSpace(cfg.ID)
|
||||
@@ -58,6 +64,7 @@ func (cfg *Configure) RewriteID() {
|
||||
logging.Info("now agent id is %s", cfg.ID)
|
||||
}
|
||||
|
||||
// SetAgentID reset agent id by value
|
||||
func (cfg *Configure) SetAgentID(id string) {
|
||||
cfg.ID = id
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func TestCGroups(t *testing.T) {
|
||||
var cfg Configure
|
||||
cfg.CpuQuota = 100 // 1core
|
||||
cfg.CPUQuota = 100 // 1core
|
||||
cfg.Memory = utils.Bytes(100 * 1024 * 1024) // 100MB
|
||||
cfg.Disks = append(cfg.Disks, DiskLimit{
|
||||
Dev: "8:0",
|
||||
|
||||
@@ -25,7 +25,7 @@ func (cfg *Configure) doV1(agentName string) {
|
||||
logging.Warning("can not create cgroup %s: %v", dir, err)
|
||||
return
|
||||
}
|
||||
limitCPUV1(group, cfg.CpuQuota)
|
||||
limitCPUV1(group, cfg.CPUQuota)
|
||||
limitMemoryV1(group, int64(cfg.Memory))
|
||||
limitDiskV1(group, cfg.Disks)
|
||||
err = group.Add(cgroups.Process{
|
||||
@@ -38,7 +38,7 @@ func (cfg *Configure) doV1(agentName string) {
|
||||
}
|
||||
|
||||
func wantCGroup(cfg *Configure) bool {
|
||||
if cfg.CpuQuota > 0 {
|
||||
if cfg.CPUQuota > 0 {
|
||||
return true
|
||||
}
|
||||
if cfg.Memory > 0 {
|
||||
|
||||
@@ -18,7 +18,7 @@ func (cfg *Configure) doV2(agentName string) {
|
||||
logging.Warning("can not create cgroup: %v", err)
|
||||
return
|
||||
}
|
||||
limitCPUV2(group, cfg.CpuQuota)
|
||||
limitCPUV2(group, cfg.CPUQuota)
|
||||
limitMemoryV2(group, int64(cfg.Memory))
|
||||
limitDiskV2(group, cfg.Disks)
|
||||
err = group.AddProc(uint64(os.Getpid()))
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
"github.com/jkstack/agent/utils"
|
||||
)
|
||||
|
||||
// DiskLimit disk limit configure
|
||||
type DiskLimit struct {
|
||||
// device version of lsblk command eg: 8:0
|
||||
// device number of lsblk command eg: 8:0
|
||||
Dev string `json:"dev" yaml:"dev" kv:"dev"`
|
||||
// read bytes
|
||||
ReadBytes uint64 `json:"read_bytes" yaml:"read_bytes" kv:"read_bytes"`
|
||||
@@ -23,7 +24,7 @@ type DiskLimit struct {
|
||||
// Configure limit configure
|
||||
type Configure struct {
|
||||
// cpu usage 100 means 1 core
|
||||
CpuQuota int64 `json:"cpu_quota" yaml:"cpu_quota" kv:"cpu_quota"`
|
||||
CPUQuota int64 `json:"cpu_quota" yaml:"cpu_quota" kv:"cpu_quota"`
|
||||
// memory size limit in bytes
|
||||
Memory utils.Bytes `json:"memory_limit" yaml:"memory_limit" kv:"memory_limit"`
|
||||
// limit of disk
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Bytes yaml bytes
|
||||
// Bytes custom bytes struct
|
||||
type Bytes uint64
|
||||
|
||||
// MarshalJSON marshal bytes by json
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Duration custom duration struct
|
||||
type Duration time.Duration
|
||||
|
||||
// MarshalKV marshal duration
|
||||
|
||||
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import "github.com/jkstack/jkframe/logging"
|
||||
|
||||
// Recover error recover
|
||||
func Recover(key string) {
|
||||
if err := recover(); err != nil {
|
||||
logging.Error("%s: %v", key, err)
|
||||
|
||||
Reference in New Issue
Block a user