Skip to content

Commit dea01a1

Browse files
committed
test: code fmt and lint
1 parent d8dcbda commit dea01a1

File tree

24 files changed

+153
-153
lines changed

24 files changed

+153
-153
lines changed
File renamed without changes.

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package config
2+
23
//
34
//import (
45
// "encoding/json"

lib/process/discover.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import (
1616

1717
type FilterFunc func(cmdline string) bool
1818

19-
var searchEngineRegx = regexp.MustCompile( "(?i)org.(easy|elastic|open)search.bootstrap.(Easy|Elastic|Open)Search")
19+
var searchEngineRegx = regexp.MustCompile("(?i)org.(easy|elastic|open)search.bootstrap.(Easy|Elastic|Open)Search")
20+
2021
func ElasticFilter(cmdline string) bool {
2122
return searchEngineRegx.MatchString(cmdline)
2223
}
2324

24-
func DiscoverESProcessors(filter FilterFunc)(map[int]model.ProcessInfo, error){
25+
func DiscoverESProcessors(filter FilterFunc) (map[int]model.ProcessInfo, error) {
2526
if filter == nil {
2627
return nil, fmt.Errorf("process filter func must not be empty")
2728
}
@@ -39,12 +40,12 @@ func DiscoverESProcessors(filter FilterFunc)(map[int]model.ProcessInfo, error){
3940
envPort := os.Getenv("http.port")
4041
port, _ := strconv.Atoi(envPort)
4142
processInfo := model.ProcessInfo{
42-
PID: int(p.Pid),
43-
Name: processName,
43+
PID: int(p.Pid),
44+
Name: processName,
4445
Cmdline: cmdline,
4546
ListenAddresses: []model.ListenAddr{
4647
{
47-
IP: util.GetLocalIPs()[0],
48+
IP: util.GetLocalIPs()[0],
4849
Port: port,
4950
},
5051
},
@@ -68,18 +69,18 @@ func DiscoverESProcessors(filter FilterFunc)(map[int]model.ProcessInfo, error){
6869
for _, connection := range connections {
6970
if connection.Status == "LISTEN" {
7071
addresses = append(addresses, model.ListenAddr{
71-
IP: connection.Laddr.IP,
72+
IP: connection.Laddr.IP,
7273
Port: int(connection.Laddr.Port),
7374
})
7475
}
7576
}
7677
if len(addresses) > 0 {
7778
processInfo := model.ProcessInfo{
78-
PID: int(p.Pid),
79-
Name: processName,
80-
Cmdline: cmdline,
79+
PID: int(p.Pid),
80+
Name: processName,
81+
Cmdline: cmdline,
8182
ListenAddresses: addresses,
82-
Status: "N/A",
83+
Status: "N/A",
8384
}
8485
status, _ := p.Status()
8586
if len(status) > 0 {
@@ -92,4 +93,4 @@ func DiscoverESProcessors(filter FilterFunc)(map[int]model.ProcessInfo, error){
9293
}
9394
}
9495
return resultProcesses, nil
95-
}
96+
}

lib/process/discover_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import (
1111
"testing"
1212
)
1313

14-
func TestDiscover(t *testing.T){
14+
func TestDiscover(t *testing.T) {
1515
pinfos, err := DiscoverESProcessors(ElasticFilter)
1616
if err != nil {
1717
t.Fatal(err)
1818
}
1919
fmt.Println(pinfos)
2020
}
2121

22-
func TestTryGetESClusterInfo(t *testing.T) {
22+
func TestTryGetESClusterInfo(t *testing.T) {
2323
addr := model.ListenAddr{
2424
Port: 9206,
25-
IP: "*",
25+
IP: "*",
2626
}
2727
_, info, err := tryGetESClusterInfo(addr)
2828
fmt.Println(info, err)
@@ -34,7 +34,7 @@ func TestParsePathValue(t *testing.T) {
3434
fmt.Println(p)
3535
}
3636

37-
func TestElasticFilter(t *testing.T){
37+
func TestElasticFilter(t *testing.T) {
3838
cmds := []string{
3939
"/opt/es/elasticsearch-8.3.3/jdk.app/Contents/Home/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -Djava.security.manager=allow -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j2.formatMsgNoLookups=true -Djava.locale.providers=SPI,COMPAT --add-opens=java.base/java.io=ALL-UNNAMED -XX:+UseG1GC -Djava.io.tmpdir=/var/folders/f6/2gqtmknx4jn357m0vv8151lc0000gn/T/elasticsearch-734978348591728761 -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -Xms8192m -Xmx8192m -XX:MaxDirectMemorySize=4294967296 -XX:InitiatingHeapOccupancyPercent=30 -XX:G1ReservePercent=25 -Des.distribution.type=tar --module-path /opt/es/elasticsearch-8.3.3/lib -m org.elasticsearch.server/org.elasticsearch.bootstrap.Elasticsearch",
4040
"/opt/opensearch/opensearch-1.0.0/jdk/bin/java -Xshare:auto -Dopensearch.networkaddress.cache.ttl=60 -Dopensearch.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -XX:+ShowCodeDetailsInExceptionMessages -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=SPI,COMPAT -Xms1g -Xmx1g -XX:+UseG1GC -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -Djava.io.tmpdir=/tmp/opensearch-2153174206831327614 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -Dclk.tck=100 -Djdk.attach.allowAttachSelf=true -Djava.security.policy=/opt/opensearch/opensearch-1.0.0/plugins/opensearch-performance-analyzer/pa_config/opensearch_security.policy -XX:MaxDirectMemorySize=536870912 -Dopensearch.path.home=/opt/opensearch/opensearch-1.0.0 -Dopensearch.path.conf=/opt/opensearch/opensearch-1.0.0/config -Dopensearch.distribution.type=tar -Dopensearch.bundled_jdk=true -cp /opt/opensearch/opensearch-1.0.0/lib/* org.opensearch.bootstrap.OpenSearch -d",
@@ -43,4 +43,4 @@ func TestElasticFilter(t *testing.T){
4343
for _, cmd := range cmds {
4444
assert.Equal(t, true, ElasticFilter(cmd))
4545
}
46-
}
46+
}

lib/reader/commom/dtfmt/doc.go

+47-49
Original file line numberDiff line numberDiff line change
@@ -19,64 +19,62 @@
1919
// similar to joda DateTimeFormat. The pattern syntax supported is a subset
2020
// (mostly compatible) with joda DateTimeFormat.
2121
//
22-
//
23-
// Symbol Meaning Type Supported Examples
24-
// ------ ------- ------- --------- -------
25-
// G era text no AD
26-
// C century of era (>=0) number no 20
27-
// Y year of era (>=0) year yes 1996
28-
//
29-
// x weekyear year yes 1996
30-
// w week of weekyear number yes 27
31-
// e day of week number yes 2
32-
// E day of week text yes Tuesday; Tue
33-
//
34-
// y year year yes 1996
35-
// D day of year number yes 189
36-
// M month of year month yes July; Jul; 07
37-
// d day of month number yes 10
38-
//
39-
// a halfday of day text yes PM
40-
// K hour of halfday (0~11) number yes 0
41-
// h clockhour of halfday (1~12) number yes 12
42-
//
43-
// H hour of day (0~23) number yes 0
44-
// k clockhour of day (1~24) number yes 24
45-
// m minute of hour number yes 30
46-
// s second of minute number yes 55
47-
// S fraction of second nanoseconds yes 978000
48-
// f fraction of seconds nanoseconds yes 123456789
49-
// multiple of 3
50-
// z time zone text no Pacific Standard Time; PST
51-
// Z time zone offset/id zone no -0800; -08:00; America/Los_Angeles
52-
//
53-
// ' escape for text delimiter
54-
// '' single quote literal
22+
// Symbol Meaning Type Supported Examples
23+
// ------ ------- ------- --------- -------
24+
// G era text no AD
25+
// C century of era (>=0) number no 20
26+
// Y year of era (>=0) year yes 1996
27+
//
28+
// x weekyear year yes 1996
29+
// w week of weekyear number yes 27
30+
// e day of week number yes 2
31+
// E day of week text yes Tuesday; Tue
32+
//
33+
// y year year yes 1996
34+
// D day of year number yes 189
35+
// M month of year month yes July; Jul; 07
36+
// d day of month number yes 10
37+
//
38+
// a halfday of day text yes PM
39+
// K hour of halfday (0~11) number yes 0
40+
// h clockhour of halfday (1~12) number yes 12
41+
//
42+
// H hour of day (0~23) number yes 0
43+
// k clockhour of day (1~24) number yes 24
44+
// m minute of hour number yes 30
45+
// s second of minute number yes 55
46+
// S fraction of second nanoseconds yes 978000
47+
// f fraction of seconds nanoseconds yes 123456789
48+
// multiple of 3
49+
// z time zone text no Pacific Standard Time; PST
50+
// Z time zone offset/id zone no -0800; -08:00; America/Los_Angeles
51+
//
52+
// ' escape for text delimiter
53+
// '' single quote literal
5554
//
5655
// The format is based on pattern letter count. Any character not in the range
5756
// [a-z][A-Z] is interpreted as literal and copied into final string as is.
5857
// Arbitrary Literals can also be written using single quotes `'`
5958
//
60-
// Types: Notes:
61-
// ------ ------
62-
// text Use full form if number of letters is >= 4.
63-
// Otherwise a short form is used (if available).
64-
//
65-
// number Minimum number of digits depends on number of letters.
66-
// Shorter numbers are zero-padded.
59+
// Types: Notes:
60+
// ------ ------
61+
// text Use full form if number of letters is >= 4.
62+
// Otherwise a short form is used (if available).
6763
//
68-
// year mostly like number. If Pattern length is 2,
69-
// the year will be displayed as zero-based year
70-
// of the century (modulo 100)
64+
// number Minimum number of digits depends on number of letters.
65+
// Shorter numbers are zero-padded.
7166
//
72-
// month If pattern length >= 3, formatting is according to
73-
// text type. Otherwise number type
74-
// formatting rules are applied.
67+
// year mostly like number. If Pattern length is 2,
68+
// the year will be displayed as zero-based year
69+
// of the century (modulo 100)
7570
//
76-
// millis Not yet supported
71+
// month If pattern length >= 3, formatting is according to
72+
// text type. Otherwise number type
73+
// formatting rules are applied.
7774
//
78-
// zone Not yet supported
75+
// millis Not yet supported
7976
//
80-
// literal Literals are copied as is into formatted string
77+
// zone Not yet supported
8178
//
79+
// literal Literals are copied as is into formatted string
8280
package dtfmt

lib/reader/commom/dtfmt/util.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ func appendUnpadded(bs []byte, i int) []byte {
3232
// 'digits' bytes.
3333
//
3434
// for example:
35-
// appendPadded(..., 10, 5) -> 00010
36-
// appendPadded(..., 12345, 5) -> 12345
35+
//
36+
// appendPadded(..., 10, 5) -> 00010
37+
// appendPadded(..., 12345, 5) -> 12345
3738
func appendPadded(bs []byte, val, digits int) []byte {
3839
if val < 0 {
3940
bs = append(bs, '-')
@@ -86,11 +87,12 @@ func appendPadded(bs []byte, val, digits int) []byte {
8687
// be printed.
8788
//
8889
// for example:
89-
// appendFractPadded(..., 0, 9, 3) -> "000"
90-
// appendFractPadded(..., 123000, 9, 3) -> "000123"
91-
// appendFractPadded(..., 120000, 9, 3) -> "000120"
92-
// appendFractPadded(..., 120000010, 9, 3) -> "000120010"
93-
// appendFractPadded(..., 123456789, 6, 3) -> "123456"
90+
//
91+
// appendFractPadded(..., 0, 9, 3) -> "000"
92+
// appendFractPadded(..., 123000, 9, 3) -> "000123"
93+
// appendFractPadded(..., 120000, 9, 3) -> "000120"
94+
// appendFractPadded(..., 120000010, 9, 3) -> "000120010"
95+
// appendFractPadded(..., 123456789, 6, 3) -> "123456"
9496
func appendFractPadded(bs []byte, val, digits, fractSz int) []byte {
9597
if fractSz == 0 || digits <= fractSz {
9698
return appendPadded(bs, val, digits)

lib/reader/linenumber/line_number.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ type LineNumberReader struct {
1616
reader reader.Reader
1717
cfg *Config
1818
currentOffset int64
19-
scanner *bufio.Scanner
20-
currentLine int64
21-
innerFile *os.File
19+
scanner *bufio.Scanner
20+
currentLine int64
21+
innerFile *os.File
2222
}
2323

2424
func NewLineNumberReader(r reader.Reader, config *Config) *LineNumberReader {

lib/reader/linenumber/line_number_config.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ package linenumber
77
import "os"
88

99
type Config struct {
10-
Offset int64
11-
file *os.File
12-
whence int //io.SeekStart / io.SeekEnd
10+
Offset int64
11+
file *os.File
12+
whence int //io.SeekStart / io.SeekEnd
1313
}
1414

1515
func NewConfig(offset int64, f *os.File, whence int) *Config {
1616
return &Config{
17-
Offset: offset,
18-
file: f,
19-
whence: whence,
17+
Offset: offset,
18+
file: f,
19+
whence: whence,
2020
}
2121
}

lib/reader/linenumber/line_reader.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313

1414
type LinePlainTextReader struct {
1515
currentOffset int64
16-
scanner *bufio.Scanner
17-
currentLine int64
18-
innerFile *os.File
19-
startLine int64
16+
scanner *bufio.Scanner
17+
currentLine int64
18+
innerFile *os.File
19+
startLine int64
2020
}
2121

2222
func NewLinePlainTextReader(filePath string, startLineNumber int64, whence int) (*LinePlainTextReader, error) {

lib/reader/message.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
type Message struct {
1313
Ts time.Time // timestamp the content was read
14-
Content []byte `json:"content"` // actual content read
15-
Bytes int `json:"bytes,omitempty"` // total number of bytes read to generate the message
14+
Content []byte `json:"content"` // actual content read
15+
Bytes int `json:"bytes,omitempty"` // total number of bytes read to generate the message
1616
Fields util.MapStr // optional fields that can be added by reader
1717
Meta util.MapStr // deprecated
18-
LineNumbers []int64 `json:"line_numbers"` // line numbers of current content
18+
LineNumbers []int64 `json:"line_numbers"` // line numbers of current content
1919
Offset int64 `json:"offset"` // content offset in file
2020
}
2121

lib/reader/readjson/json.go

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
common "infini.sh/agent/lib/reader/commom"
2727
"infini.sh/framework/core/util"
2828
"time"
29-
3029
//"github.com/elastic/elastic-agent-libs/logp"
3130
//"github.com/elastic/elastic-agent-libs/mapstr"
3231
)

lib/util/elastic.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
"time"
1414
)
1515

16-
func GetLocalNodeInfo(endpoint string, auth *model.BasicAuth)(string, *elastic.NodesInfo, error) {
16+
func GetLocalNodeInfo(endpoint string, auth *model.BasicAuth) (string, *elastic.NodesInfo, error) {
1717
url := fmt.Sprintf("%s/_nodes/_local", endpoint)
1818
req := util.Request{
1919
Method: util.Verb_GET,
20-
Url: url,
20+
Url: url,
2121
}
2222
if auth != nil {
2323
req.SetBasicAuth(auth.Username, auth.Password.Get())
@@ -35,7 +35,7 @@ func GetLocalNodeInfo(endpoint string, auth *model.BasicAuth)(string, *elastic.N
3535
}
3636

3737
node := elastic.NodesResponse{}
38-
err=util.FromJSONBytes(resp.Body,&node)
38+
err = util.FromJSONBytes(resp.Body, &node)
3939
if err != nil {
4040
return "", nil, err
4141
}
@@ -45,10 +45,10 @@ func GetLocalNodeInfo(endpoint string, auth *model.BasicAuth)(string, *elastic.N
4545
return "", nil, fmt.Errorf("node not found")
4646
}
4747

48-
func GetClusterVersion(endpoint string, auth *model.BasicAuth)(*elastic.ClusterInformation, error) {
48+
func GetClusterVersion(endpoint string, auth *model.BasicAuth) (*elastic.ClusterInformation, error) {
4949
req := util.Request{
5050
Method: util.Verb_GET,
51-
Url: endpoint,
51+
Url: endpoint,
5252
}
5353
if auth != nil {
5454
req.SetBasicAuth(auth.Username, auth.Password.Get())
@@ -59,7 +59,7 @@ func GetClusterVersion(endpoint string, auth *model.BasicAuth)(*elastic.ClusterI
5959
resp, err := util.ExecuteRequest(&req)
6060

6161
if err != nil {
62-
return nil, err
62+
return nil, err
6363
}
6464
if resp.StatusCode != 200 {
6565
return nil, fmt.Errorf(string(resp.Body))
@@ -71,4 +71,4 @@ func GetClusterVersion(endpoint string, auth *model.BasicAuth)(*elastic.ClusterI
7171
return nil, err
7272
}
7373
return &version, nil
74-
}
74+
}

lib/util/network.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ func GetClientIp(filter string) (string, error) {
3535
}
3636
}
3737
return ipStr, nil
38-
}
38+
}

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070
if global.Env().SystemConfig.Configs.AllowGeneratedMetricsTasks {
7171
taskID := util.GetUUID()
7272
task2.RegisterScheduleTask(task2.ScheduleTask{
73-
ID: taskID,
73+
ID: taskID,
7474
Description: "generated metrics tasks for agent",
7575
Type: "interval",
7676
Interval: "20s",

0 commit comments

Comments
 (0)