From dea01a188c64e72943fb1cd88c68aa8fd4d02367 Mon Sep 17 00:00:00 2001 From: hardy Date: Fri, 10 Jan 2025 09:08:17 +0800 Subject: [PATCH 01/10] test: code fmt and lint --- .../workflows/{unit_test.yml => pr_check.yml} | 0 config/config.go | 1 + lib/process/discover.go | 23 ++--- lib/process/discover_test.go | 10 +- lib/reader/commom/dtfmt/doc.go | 96 +++++++++---------- lib/reader/commom/dtfmt/util.go | 16 ++-- lib/reader/linenumber/line_number.go | 6 +- lib/reader/linenumber/line_number_config.go | 12 +-- lib/reader/linenumber/line_reader.go | 8 +- lib/reader/message.go | 6 +- lib/reader/readjson/json.go | 1 - lib/util/elastic.go | 14 +-- lib/util/network.go | 2 +- main.go | 2 +- plugin/api/log.go | 14 +-- plugin/api/model.go | 11 +-- plugin/elastic/logging/es_logs.go | 2 +- .../metric/cluster_health/cluster_health.go | 8 +- .../metric/cluster_stats/cluster_stats.go | 12 +-- .../elastic/metric/index_stats/index_stats.go | 18 ++-- plugin/elastic/metric/metric.go | 2 +- .../elastic/metric/node_stats/node_stats.go | 26 ++--- plugin/logs/file_detect_unix.go | 6 +- plugin/logs/file_detect_windows.go | 10 +- 24 files changed, 153 insertions(+), 153 deletions(-) rename .github/workflows/{unit_test.yml => pr_check.yml} (100%) diff --git a/.github/workflows/unit_test.yml b/.github/workflows/pr_check.yml similarity index 100% rename from .github/workflows/unit_test.yml rename to .github/workflows/pr_check.yml diff --git a/config/config.go b/config/config.go index 5b11cfe..3e9a4bc 100644 --- a/config/config.go +++ b/config/config.go @@ -1,4 +1,5 @@ package config + // //import ( // "encoding/json" diff --git a/lib/process/discover.go b/lib/process/discover.go index afebeb5..d0f69d7 100644 --- a/lib/process/discover.go +++ b/lib/process/discover.go @@ -16,12 +16,13 @@ import ( type FilterFunc func(cmdline string) bool -var searchEngineRegx = regexp.MustCompile( "(?i)org.(easy|elastic|open)search.bootstrap.(Easy|Elastic|Open)Search") +var searchEngineRegx = regexp.MustCompile("(?i)org.(easy|elastic|open)search.bootstrap.(Easy|Elastic|Open)Search") + func ElasticFilter(cmdline string) bool { return searchEngineRegx.MatchString(cmdline) } -func DiscoverESProcessors(filter FilterFunc)(map[int]model.ProcessInfo, error){ +func DiscoverESProcessors(filter FilterFunc) (map[int]model.ProcessInfo, error) { if filter == nil { return nil, fmt.Errorf("process filter func must not be empty") } @@ -39,12 +40,12 @@ func DiscoverESProcessors(filter FilterFunc)(map[int]model.ProcessInfo, error){ envPort := os.Getenv("http.port") port, _ := strconv.Atoi(envPort) processInfo := model.ProcessInfo{ - PID: int(p.Pid), - Name: processName, + PID: int(p.Pid), + Name: processName, Cmdline: cmdline, ListenAddresses: []model.ListenAddr{ { - IP: util.GetLocalIPs()[0], + IP: util.GetLocalIPs()[0], Port: port, }, }, @@ -68,18 +69,18 @@ func DiscoverESProcessors(filter FilterFunc)(map[int]model.ProcessInfo, error){ for _, connection := range connections { if connection.Status == "LISTEN" { addresses = append(addresses, model.ListenAddr{ - IP: connection.Laddr.IP, + IP: connection.Laddr.IP, Port: int(connection.Laddr.Port), }) } } if len(addresses) > 0 { processInfo := model.ProcessInfo{ - PID: int(p.Pid), - Name: processName, - Cmdline: cmdline, + PID: int(p.Pid), + Name: processName, + Cmdline: cmdline, ListenAddresses: addresses, - Status: "N/A", + Status: "N/A", } status, _ := p.Status() if len(status) > 0 { @@ -92,4 +93,4 @@ func DiscoverESProcessors(filter FilterFunc)(map[int]model.ProcessInfo, error){ } } return resultProcesses, nil -} \ No newline at end of file +} diff --git a/lib/process/discover_test.go b/lib/process/discover_test.go index 4803b5a..9587585 100644 --- a/lib/process/discover_test.go +++ b/lib/process/discover_test.go @@ -11,7 +11,7 @@ import ( "testing" ) -func TestDiscover(t *testing.T){ +func TestDiscover(t *testing.T) { pinfos, err := DiscoverESProcessors(ElasticFilter) if err != nil { t.Fatal(err) @@ -19,10 +19,10 @@ func TestDiscover(t *testing.T){ fmt.Println(pinfos) } -func TestTryGetESClusterInfo(t *testing.T) { +func TestTryGetESClusterInfo(t *testing.T) { addr := model.ListenAddr{ Port: 9206, - IP: "*", + IP: "*", } _, info, err := tryGetESClusterInfo(addr) fmt.Println(info, err) @@ -34,7 +34,7 @@ func TestParsePathValue(t *testing.T) { fmt.Println(p) } -func TestElasticFilter(t *testing.T){ +func TestElasticFilter(t *testing.T) { cmds := []string{ "/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", "/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){ for _, cmd := range cmds { assert.Equal(t, true, ElasticFilter(cmd)) } -} \ No newline at end of file +} diff --git a/lib/reader/commom/dtfmt/doc.go b/lib/reader/commom/dtfmt/doc.go index 749b2db..f68ee9b 100644 --- a/lib/reader/commom/dtfmt/doc.go +++ b/lib/reader/commom/dtfmt/doc.go @@ -19,64 +19,62 @@ // similar to joda DateTimeFormat. The pattern syntax supported is a subset // (mostly compatible) with joda DateTimeFormat. // -// -// Symbol Meaning Type Supported Examples -// ------ ------- ------- --------- ------- -// G era text no AD -// C century of era (>=0) number no 20 -// Y year of era (>=0) year yes 1996 -// -// x weekyear year yes 1996 -// w week of weekyear number yes 27 -// e day of week number yes 2 -// E day of week text yes Tuesday; Tue -// -// y year year yes 1996 -// D day of year number yes 189 -// M month of year month yes July; Jul; 07 -// d day of month number yes 10 -// -// a halfday of day text yes PM -// K hour of halfday (0~11) number yes 0 -// h clockhour of halfday (1~12) number yes 12 -// -// H hour of day (0~23) number yes 0 -// k clockhour of day (1~24) number yes 24 -// m minute of hour number yes 30 -// s second of minute number yes 55 -// S fraction of second nanoseconds yes 978000 -// f fraction of seconds nanoseconds yes 123456789 -// multiple of 3 -// z time zone text no Pacific Standard Time; PST -// Z time zone offset/id zone no -0800; -08:00; America/Los_Angeles -// -// ' escape for text delimiter -// '' single quote literal +// Symbol Meaning Type Supported Examples +// ------ ------- ------- --------- ------- +// G era text no AD +// C century of era (>=0) number no 20 +// Y year of era (>=0) year yes 1996 +// +// x weekyear year yes 1996 +// w week of weekyear number yes 27 +// e day of week number yes 2 +// E day of week text yes Tuesday; Tue +// +// y year year yes 1996 +// D day of year number yes 189 +// M month of year month yes July; Jul; 07 +// d day of month number yes 10 +// +// a halfday of day text yes PM +// K hour of halfday (0~11) number yes 0 +// h clockhour of halfday (1~12) number yes 12 +// +// H hour of day (0~23) number yes 0 +// k clockhour of day (1~24) number yes 24 +// m minute of hour number yes 30 +// s second of minute number yes 55 +// S fraction of second nanoseconds yes 978000 +// f fraction of seconds nanoseconds yes 123456789 +// multiple of 3 +// z time zone text no Pacific Standard Time; PST +// Z time zone offset/id zone no -0800; -08:00; America/Los_Angeles +// +// ' escape for text delimiter +// '' single quote literal // // The format is based on pattern letter count. Any character not in the range // [a-z][A-Z] is interpreted as literal and copied into final string as is. // Arbitrary Literals can also be written using single quotes `'` // -// Types: Notes: -// ------ ------ -// text Use full form if number of letters is >= 4. -// Otherwise a short form is used (if available). -// -// number Minimum number of digits depends on number of letters. -// Shorter numbers are zero-padded. +// Types: Notes: +// ------ ------ +// text Use full form if number of letters is >= 4. +// Otherwise a short form is used (if available). // -// year mostly like number. If Pattern length is 2, -// the year will be displayed as zero-based year -// of the century (modulo 100) +// number Minimum number of digits depends on number of letters. +// Shorter numbers are zero-padded. // -// month If pattern length >= 3, formatting is according to -// text type. Otherwise number type -// formatting rules are applied. +// year mostly like number. If Pattern length is 2, +// the year will be displayed as zero-based year +// of the century (modulo 100) // -// millis Not yet supported +// month If pattern length >= 3, formatting is according to +// text type. Otherwise number type +// formatting rules are applied. // -// zone Not yet supported +// millis Not yet supported // -// literal Literals are copied as is into formatted string +// zone Not yet supported // +// literal Literals are copied as is into formatted string package dtfmt diff --git a/lib/reader/commom/dtfmt/util.go b/lib/reader/commom/dtfmt/util.go index 4341bc5..4473298 100644 --- a/lib/reader/commom/dtfmt/util.go +++ b/lib/reader/commom/dtfmt/util.go @@ -32,8 +32,9 @@ func appendUnpadded(bs []byte, i int) []byte { // 'digits' bytes. // // for example: -// appendPadded(..., 10, 5) -> 00010 -// appendPadded(..., 12345, 5) -> 12345 +// +// appendPadded(..., 10, 5) -> 00010 +// appendPadded(..., 12345, 5) -> 12345 func appendPadded(bs []byte, val, digits int) []byte { if val < 0 { bs = append(bs, '-') @@ -86,11 +87,12 @@ func appendPadded(bs []byte, val, digits int) []byte { // be printed. // // for example: -// appendFractPadded(..., 0, 9, 3) -> "000" -// appendFractPadded(..., 123000, 9, 3) -> "000123" -// appendFractPadded(..., 120000, 9, 3) -> "000120" -// appendFractPadded(..., 120000010, 9, 3) -> "000120010" -// appendFractPadded(..., 123456789, 6, 3) -> "123456" +// +// appendFractPadded(..., 0, 9, 3) -> "000" +// appendFractPadded(..., 123000, 9, 3) -> "000123" +// appendFractPadded(..., 120000, 9, 3) -> "000120" +// appendFractPadded(..., 120000010, 9, 3) -> "000120010" +// appendFractPadded(..., 123456789, 6, 3) -> "123456" func appendFractPadded(bs []byte, val, digits, fractSz int) []byte { if fractSz == 0 || digits <= fractSz { return appendPadded(bs, val, digits) diff --git a/lib/reader/linenumber/line_number.go b/lib/reader/linenumber/line_number.go index f959345..66e7f50 100644 --- a/lib/reader/linenumber/line_number.go +++ b/lib/reader/linenumber/line_number.go @@ -16,9 +16,9 @@ type LineNumberReader struct { reader reader.Reader cfg *Config currentOffset int64 - scanner *bufio.Scanner - currentLine int64 - innerFile *os.File + scanner *bufio.Scanner + currentLine int64 + innerFile *os.File } func NewLineNumberReader(r reader.Reader, config *Config) *LineNumberReader { diff --git a/lib/reader/linenumber/line_number_config.go b/lib/reader/linenumber/line_number_config.go index e75023d..5c0add2 100644 --- a/lib/reader/linenumber/line_number_config.go +++ b/lib/reader/linenumber/line_number_config.go @@ -7,15 +7,15 @@ package linenumber import "os" type Config struct { - Offset int64 - file *os.File - whence int //io.SeekStart / io.SeekEnd + Offset int64 + file *os.File + whence int //io.SeekStart / io.SeekEnd } func NewConfig(offset int64, f *os.File, whence int) *Config { return &Config{ - Offset: offset, - file: f, - whence: whence, + Offset: offset, + file: f, + whence: whence, } } diff --git a/lib/reader/linenumber/line_reader.go b/lib/reader/linenumber/line_reader.go index 0dc86e0..8f71625 100644 --- a/lib/reader/linenumber/line_reader.go +++ b/lib/reader/linenumber/line_reader.go @@ -13,10 +13,10 @@ import ( type LinePlainTextReader struct { currentOffset int64 - scanner *bufio.Scanner - currentLine int64 - innerFile *os.File - startLine int64 + scanner *bufio.Scanner + currentLine int64 + innerFile *os.File + startLine int64 } func NewLinePlainTextReader(filePath string, startLineNumber int64, whence int) (*LinePlainTextReader, error) { diff --git a/lib/reader/message.go b/lib/reader/message.go index d5e170b..8da9ec0 100644 --- a/lib/reader/message.go +++ b/lib/reader/message.go @@ -11,11 +11,11 @@ import ( type Message struct { Ts time.Time // timestamp the content was read - Content []byte `json:"content"` // actual content read - Bytes int `json:"bytes,omitempty"` // total number of bytes read to generate the message + Content []byte `json:"content"` // actual content read + Bytes int `json:"bytes,omitempty"` // total number of bytes read to generate the message Fields util.MapStr // optional fields that can be added by reader Meta util.MapStr // deprecated - LineNumbers []int64 `json:"line_numbers"` // line numbers of current content + LineNumbers []int64 `json:"line_numbers"` // line numbers of current content Offset int64 `json:"offset"` // content offset in file } diff --git a/lib/reader/readjson/json.go b/lib/reader/readjson/json.go index 1f99c1f..3e6e8b2 100644 --- a/lib/reader/readjson/json.go +++ b/lib/reader/readjson/json.go @@ -26,7 +26,6 @@ import ( common "infini.sh/agent/lib/reader/commom" "infini.sh/framework/core/util" "time" - //"github.com/elastic/elastic-agent-libs/logp" //"github.com/elastic/elastic-agent-libs/mapstr" ) diff --git a/lib/util/elastic.go b/lib/util/elastic.go index 6798159..fc5d9df 100644 --- a/lib/util/elastic.go +++ b/lib/util/elastic.go @@ -13,11 +13,11 @@ import ( "time" ) -func GetLocalNodeInfo(endpoint string, auth *model.BasicAuth)(string, *elastic.NodesInfo, error) { +func GetLocalNodeInfo(endpoint string, auth *model.BasicAuth) (string, *elastic.NodesInfo, error) { url := fmt.Sprintf("%s/_nodes/_local", endpoint) req := util.Request{ Method: util.Verb_GET, - Url: url, + Url: url, } if auth != nil { req.SetBasicAuth(auth.Username, auth.Password.Get()) @@ -35,7 +35,7 @@ func GetLocalNodeInfo(endpoint string, auth *model.BasicAuth)(string, *elastic.N } node := elastic.NodesResponse{} - err=util.FromJSONBytes(resp.Body,&node) + err = util.FromJSONBytes(resp.Body, &node) if err != nil { return "", nil, err } @@ -45,10 +45,10 @@ func GetLocalNodeInfo(endpoint string, auth *model.BasicAuth)(string, *elastic.N return "", nil, fmt.Errorf("node not found") } -func GetClusterVersion(endpoint string, auth *model.BasicAuth)(*elastic.ClusterInformation, error) { +func GetClusterVersion(endpoint string, auth *model.BasicAuth) (*elastic.ClusterInformation, error) { req := util.Request{ Method: util.Verb_GET, - Url: endpoint, + Url: endpoint, } if auth != nil { req.SetBasicAuth(auth.Username, auth.Password.Get()) @@ -59,7 +59,7 @@ func GetClusterVersion(endpoint string, auth *model.BasicAuth)(*elastic.ClusterI resp, err := util.ExecuteRequest(&req) if err != nil { - return nil, err + return nil, err } if resp.StatusCode != 200 { return nil, fmt.Errorf(string(resp.Body)) @@ -71,4 +71,4 @@ func GetClusterVersion(endpoint string, auth *model.BasicAuth)(*elastic.ClusterI return nil, err } return &version, nil -} \ No newline at end of file +} diff --git a/lib/util/network.go b/lib/util/network.go index 63937cc..efb0dbe 100644 --- a/lib/util/network.go +++ b/lib/util/network.go @@ -35,4 +35,4 @@ func GetClientIp(filter string) (string, error) { } } return ipStr, nil -} \ No newline at end of file +} diff --git a/main.go b/main.go index bab8350..de68a6f 100755 --- a/main.go +++ b/main.go @@ -70,7 +70,7 @@ func main() { if global.Env().SystemConfig.Configs.AllowGeneratedMetricsTasks { taskID := util.GetUUID() task2.RegisterScheduleTask(task2.ScheduleTask{ - ID: taskID, + ID: taskID, Description: "generated metrics tasks for agent", Type: "interval", Interval: "20s", diff --git a/plugin/api/log.go b/plugin/api/log.go index 2b2ae40..c421e07 100644 --- a/plugin/api/log.go +++ b/plugin/api/log.go @@ -56,7 +56,7 @@ func (handler *AgentAPI) getElasticLogFiles(w http.ResponseWriter, req *http.Req "name": fInfo.Name(), "size_in_bytes": fInfo.Size(), "modify_time": fInfo.ModTime(), - "total_rows": totalRows, + "total_rows": totalRows, }) } } @@ -102,7 +102,7 @@ func (handler *AgentAPI) readElasticLogFile(w http.ResponseWriter, req *http.Req log.Error("error on exit disk_queue,", v) } } - if r!=nil{ + if r != nil { r.Close() } }() @@ -122,20 +122,20 @@ func (handler *AgentAPI) readElasticLogFile(w http.ResponseWriter, req *http.Req } } msgs = append(msgs, util.MapStr{ - "content": string(msg.Content), - "bytes": msg.Bytes, - "offset": msg.Offset, + "content": string(msg.Content), + "bytes": msg.Bytes, + "offset": msg.Offset, "line_number": coverLineNumbers(msg.LineNumbers), }) } handler.WriteJSON(w, util.MapStr{ "result": msgs, "success": true, - "EOF": isEOF, + "EOF": isEOF, }, http.StatusOK) } -func coverLineNumbers(numbers []int64) interface{}{ +func coverLineNumbers(numbers []int64) interface{} { if len(numbers) == 1 { return numbers[0] } else { diff --git a/plugin/api/model.go b/plugin/api/model.go index acdf2fc..9096be9 100644 --- a/plugin/api/model.go +++ b/plugin/api/model.go @@ -9,10 +9,9 @@ type GetElasticLogFilesReq struct { } type ReadElasticLogFileReq struct { - LogsPath string `json:"logs_path"` - FileName string `json:"file_name"` - Offset int64 `json:"offset"` - Lines int `json:"lines"` - StartLineNumber int64 `json:"start_line_number"` + LogsPath string `json:"logs_path"` + FileName string `json:"file_name"` + Offset int64 `json:"offset"` + Lines int `json:"lines"` + StartLineNumber int64 `json:"start_line_number"` } - diff --git a/plugin/elastic/logging/es_logs.go b/plugin/elastic/logging/es_logs.go index 1613e57..f4bfa6e 100644 --- a/plugin/elastic/logging/es_logs.go +++ b/plugin/elastic/logging/es_logs.go @@ -100,7 +100,7 @@ func (p *EsLogsProcessor) Process(c *pipeline.Context) error { for _, cfg := range p.configs { - if cfg ==nil{ + if cfg == nil { continue } diff --git a/plugin/elastic/metric/cluster_health/cluster_health.go b/plugin/elastic/metric/cluster_health/cluster_health.go index c414228..b63e9d8 100644 --- a/plugin/elastic/metric/cluster_health/cluster_health.go +++ b/plugin/elastic/metric/cluster_health/cluster_health.go @@ -38,8 +38,8 @@ func newProcessor(c *config.Config) (pipeline.Processor, error) { } type Config struct { - Elasticsearch string `config:"elasticsearch,omitempty"` - Labels map[string]interface{} `config:"labels,omitempty"` + Elasticsearch string `config:"elasticsearch,omitempty"` + Labels map[string]interface{} `config:"labels,omitempty"` } type ClusterHealth struct { @@ -72,7 +72,7 @@ func (p *ClusterHealth) Collect(k string, v *elastic.ElasticsearchMetadata) erro } labels := util.MapStr{ - "cluster_id": v.Config.ID, + "cluster_id": v.Config.ID, "cluster_uuid": v.Config.ClusterUUID, } if len(p.config.Labels) > 0 { @@ -85,7 +85,7 @@ func (p *ClusterHealth) Collect(k string, v *elastic.ElasticsearchMetadata) erro Category: "elasticsearch", Name: "cluster_health", Datatype: "snapshot", - Labels: labels, + Labels: labels, }, } item.Fields = util.MapStr{ diff --git a/plugin/elastic/metric/cluster_stats/cluster_stats.go b/plugin/elastic/metric/cluster_stats/cluster_stats.go index 8614ffb..5992be8 100644 --- a/plugin/elastic/metric/cluster_stats/cluster_stats.go +++ b/plugin/elastic/metric/cluster_stats/cluster_stats.go @@ -38,8 +38,8 @@ func newProcessor(c *config.Config) (pipeline.Processor, error) { } type Config struct { - Elasticsearch string `config:"elasticsearch,omitempty"` - Labels map[string]interface{} `config:"labels,omitempty"` + Elasticsearch string `config:"elasticsearch,omitempty"` + Labels map[string]interface{} `config:"labels,omitempty"` } type ClusterStats struct { @@ -66,13 +66,13 @@ func (p *ClusterStats) Collect(k string, v *elastic.ElasticsearchMetadata) error var stats *elastic.ClusterStats var err error - stats, err = client.GetClusterStatsSpecEndpoint(nil,"", v.Config.GetAnyEndpoint()) + stats, err = client.GetClusterStatsSpecEndpoint(nil, "", v.Config.GetAnyEndpoint()) if err != nil { log.Error(v.Config.Name, " get cluster stats error: ", err) return err } labels := util.MapStr{ - "cluster_id": v.Config.ID, + "cluster_id": v.Config.ID, "cluster_uuid": v.Config.ClusterUUID, } if len(p.config.Labels) > 0 { @@ -85,7 +85,7 @@ func (p *ClusterStats) Collect(k string, v *elastic.ElasticsearchMetadata) error Category: "elasticsearch", Name: "cluster_stats", Datatype: "snapshot", - Labels: labels, + Labels: labels, }, } @@ -96,4 +96,4 @@ func (p *ClusterStats) Collect(k string, v *elastic.ElasticsearchMetadata) error } return event.Save(&item) -} \ No newline at end of file +} diff --git a/plugin/elastic/metric/index_stats/index_stats.go b/plugin/elastic/metric/index_stats/index_stats.go index 5a84856..290f70c 100644 --- a/plugin/elastic/metric/index_stats/index_stats.go +++ b/plugin/elastic/metric/index_stats/index_stats.go @@ -23,9 +23,9 @@ func init() { func newProcessor(c *config.Config) (pipeline.Processor, error) { cfg := Config{ - AllIndexStats: true, + AllIndexStats: true, IndexPrimaryStats: true, - IndexTotalStats: true, + IndexTotalStats: true, } if err := c.Unpack(&cfg); err != nil { log.Error(err) @@ -42,11 +42,11 @@ func newProcessor(c *config.Config) (pipeline.Processor, error) { } type Config struct { - Elasticsearch string `config:"elasticsearch,omitempty"` - AllIndexStats bool `config:"all_index_stats,omitempty"` - IndexPrimaryStats bool `config:"index_primary_stats"` - IndexTotalStats bool `config:"index_total_stats"` - Labels map[string]interface{} `config:"labels,omitempty"` + Elasticsearch string `config:"elasticsearch,omitempty"` + AllIndexStats bool `config:"all_index_stats,omitempty"` + IndexPrimaryStats bool `config:"index_primary_stats"` + IndexTotalStats bool `config:"index_total_stats"` + Labels map[string]interface{} `config:"labels,omitempty"` } type IndexStats struct { @@ -65,7 +65,7 @@ func (p *IndexStats) Process(c *pipeline.Context) error { func (p *IndexStats) Collect(k string, v *elastic.ElasticsearchMetadata) error { var ( shards []elastic.CatShardResponse - err error + err error ) client := elastic.GetClientNoPanic(k) if client == nil { @@ -145,7 +145,7 @@ func (p *IndexStats) SaveIndexStats(clusterId, clusterUUID, indexID, indexName s Category: "elasticsearch", Name: "index_stats", Datatype: "snapshot", - Labels: labels, + Labels: labels, }, } diff --git a/plugin/elastic/metric/metric.go b/plugin/elastic/metric/metric.go index 63bddb0..fee86ed 100644 --- a/plugin/elastic/metric/metric.go +++ b/plugin/elastic/metric/metric.go @@ -6,4 +6,4 @@ package metric import ( _ "infini.sh/agent/plugin/elastic/metric/node_stats" -) \ No newline at end of file +) diff --git a/plugin/elastic/metric/node_stats/node_stats.go b/plugin/elastic/metric/node_stats/node_stats.go index ff8b082..504deae 100644 --- a/plugin/elastic/metric/node_stats/node_stats.go +++ b/plugin/elastic/metric/node_stats/node_stats.go @@ -38,7 +38,7 @@ func newProcessor(c *config.Config) (pipeline.Processor, error) { } _, err := adapter.GetClusterUUID(processor.config.Elasticsearch) if err != nil { - log.Errorf(" get cluster uuid %v error: %v", processor.config.Elasticsearch,err) + log.Errorf(" get cluster uuid %v error: %v", processor.config.Elasticsearch, err) } return &processor, nil } @@ -111,7 +111,7 @@ func (p *NodeStats) Collect(k string, v *elastic.ElasticsearchMetadata) error { clusterUUID := v.Config.ClusterUUID - timestamp:=time.Now() + timestamp := time.Now() host := v.GetActiveHost() nodeUUID := strings.Join(p.config.NodeUUIDs, ",") @@ -126,7 +126,7 @@ func (p *NodeStats) Collect(k string, v *elastic.ElasticsearchMetadata) error { if p.config.Level == "shards" { nodeData, ok := nodeStats.(map[string]interface{}) if ok { - nodeHost:=nodeData["host"].(string) + nodeHost := nodeData["host"].(string) indexData, ok := nodeData["indices"].(map[string]interface{}) if ok { //shards @@ -136,7 +136,7 @@ func (p *NodeStats) Collect(k string, v *elastic.ElasticsearchMetadata) error { for indexName, f := range x { //e is index name //f is shards in array type - indexUUID:="" //TODO get index uuid + indexUUID := "" //TODO get index uuid u, ok := f.([]interface{}) if ok { for _, g := range u { @@ -145,7 +145,7 @@ func (p *NodeStats) Collect(k string, v *elastic.ElasticsearchMetadata) error { for shardID, i := range m { shardsCount++ - p.SaveShardStats(v.Config.ID, clusterUUID, nodeID,nodeHost,indexName,indexUUID, shardID, i,timestamp) + p.SaveShardStats(v.Config.ID, clusterUUID, nodeID, nodeHost, indexName, indexUUID, shardID, i, timestamp) } } } @@ -167,7 +167,7 @@ func (p *NodeStats) Collect(k string, v *elastic.ElasticsearchMetadata) error { } shardInfo = shardInfos[nodeID] } - p.SaveNodeStats(v.Config.ID, clusterUUID, nodeID, nodeStats, shardInfo,timestamp) + p.SaveNodeStats(v.Config.ID, clusterUUID, nodeID, nodeStats, shardInfo, timestamp) } } return nil @@ -242,9 +242,9 @@ func (p *NodeStats) SaveShardStats(clusterId, clusterUUID, nodeID, host, indexNa "node_id": nodeID, "index_name": indexName, "index_id": newIndexID, - "ip": host, - "shard": shardID, - "shard_id": fmt.Sprintf("%s:%s:%s", nodeID, indexName, shardID), + "ip": host, + "shard": shardID, + "shard_id": fmt.Sprintf("%s:%s:%s", nodeID, indexName, shardID), } if clusterUUID != "" { @@ -255,10 +255,10 @@ func (p *NodeStats) SaveShardStats(clusterId, clusterUUID, nodeID, host, indexNa labels["index_uuid"] = indexUUID } - if y,ok:=x["segments"];ok{ - if m,ok:=y.(map[string]interface{});ok{ - m["max_unsafe_auto_id_timestamp"]=nil - x["segments"]=m + if y, ok := x["segments"]; ok { + if m, ok := y.(map[string]interface{}); ok { + m["max_unsafe_auto_id_timestamp"] = nil + x["segments"] = m } } diff --git a/plugin/logs/file_detect_unix.go b/plugin/logs/file_detect_unix.go index 052afdd..7dfed97 100644 --- a/plugin/logs/file_detect_unix.go +++ b/plugin/logs/file_detect_unix.go @@ -1,9 +1,9 @@ +//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris + /* Copyright © INFINI Ltd. All rights reserved. * Web: https://infinilabs.com * Email: hello#infini.ltd */ -//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris - package logs import ( @@ -48,4 +48,4 @@ func LoadFileID(fi os.FileInfo, path string) (map[string]interface{}, error) { "Ino": st.Ino, } return id, nil -} \ No newline at end of file +} diff --git a/plugin/logs/file_detect_windows.go b/plugin/logs/file_detect_windows.go index d3ed28f..fce8626 100644 --- a/plugin/logs/file_detect_windows.go +++ b/plugin/logs/file_detect_windows.go @@ -54,11 +54,11 @@ func LoadFileID(fi os.FileInfo, path string) (map[string]interface{}, error) { var i syscall.ByHandleFileInformation err = syscall.GetFileInformationByHandle(h, &i) if err != nil { - return nil, err + return nil, err } return map[string]interface{}{ - "VolumeSerialNumber": i.VolumeSerialNumber, - "FileIndexHigh": i.FileIndexHigh, - "FileIndexLow": i.FileIndexLow, + "VolumeSerialNumber": i.VolumeSerialNumber, + "FileIndexHigh": i.FileIndexHigh, + "FileIndexLow": i.FileIndexLow, }, nil -} \ No newline at end of file +} From 0d3c54252fc965d64255d565c155cb8fb703c8bc Mon Sep 17 00:00:00 2001 From: hardy Date: Fri, 10 Jan 2025 09:42:19 +0800 Subject: [PATCH 02/10] test: remove unused code --- .github/workflows/pr_check.yml | 63 ++++++++++- config/config.go | 190 --------------------------------- 2 files changed, 60 insertions(+), 193 deletions(-) diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml index 47ef401..a8ec2c8 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr_check.yml @@ -1,4 +1,4 @@ -name: Unit Test +name: PR Check on: pull_request: @@ -9,7 +9,7 @@ defaults: shell: bash jobs: - build: + unit_test: runs-on: ubuntu-latest env: GO_VERSION: 1.23.4 @@ -64,4 +64,61 @@ jobs: # for unit test cd $WORK echo Testing code at $PWD ... - make test \ No newline at end of file + make test + + code_lint: + runs-on: ubuntu-latest + env: + GO_VERSION: 1.23.4 + steps: + - name: Checkout current repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + path: agent + + - name: Checkout framework repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + repository: infinilabs/framework + path: framework + + - name: Checkout framework-vendor + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + repository: infinilabs/framework-vendor + path: vendor + + - name: Set up go toolchain + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + check-latest: false + cache: true + + - name: Check go toolchain + run: go version + + - name: Code lint + env: + GOFLAGS: -tags=ci + run: | + echo Home path is $HOME + export WORKBASE=$HOME/go/src/infini.sh + export WORK=$WORKBASE/agent + + # for test workspace + mkdir -p $HOME/go/src/ + ln -s $GITHUB_WORKSPACE $WORKBASE + + # check work folder + ls -lrt $WORKBASE/ + ls -alrt $WORK + + # for unit test + cd $WORK + echo Linting code at $PWD ... + make lint \ No newline at end of file diff --git a/config/config.go b/config/config.go index 3e9a4bc..d912156 100644 --- a/config/config.go +++ b/config/config.go @@ -1,191 +1 @@ package config - -// -//import ( -// "encoding/json" -// "errors" -// log "github.com/cihub/seelog" -// "infini.sh/agent/model" -// "infini.sh/framework/core/env" -// "infini.sh/framework/core/event" -// "infini.sh/framework/core/global" -// "infini.sh/framework/core/kv" -// "infini.sh/framework/core/model" -// "strconv" -// "strings" -// "sync" -// "time" -//) -// -//type ManagedConfig struct { -// Manager *Manager `config:"manager"` -//} -// -//type Manager struct { -// Endpoint string `config:"endpoint"` -//} -// -//var agentConfig *ManagedConfig -//var hostInfo *model.Instance -//var hostInfoObserver []func(newHostInfo *model.Instance) -//var instanceLock sync.RWMutex -// -//const ( -// UrlUploadInstanceInfo string = "/agent/instance" -// UrlUpdateInstanceInfo = "/agent/instance/:instance_id" -// UrlHearBeat = "/agent/instance/:instance_id/_heartbeat" -// UrlGetInstanceInfo = "/agent/instance/:instance_id" -//) -// -//func InitConfig() { -// appConfig := &ManagedConfig{} -// ok, err := env.ParseConfig("configs", appConfig) -// if err != nil { -// panic(err) -// } -// if !ok { -// panic("config.InitConfig: can not find agent config") -// } -// agentConfig = appConfig -// hostInfoObserver = make([]func(newHostInfo *model.Instance), 1) -//} -// -//func RegisterHostInfoObserver(fn func(newHostInfo *model.Instance)) { -// hostInfoObserver = append(hostInfoObserver, fn) -//} -// -//func NotifyHostInfoObserver(newHostInfo *model.Instance) { -// for i := 0; i < len(hostInfoObserver); i++ { -// if hostInfoObserver[i] != nil { -// hostInfoObserver[i](newHostInfo) -// } -// } -//} -// -//func GetManagerEndpoint() string { -// if agentConfig == nil || agentConfig.Manager == nil { -// return "" -// } -// endPoint := agentConfig.Manager.Endpoint -// if strings.HasSuffix(endPoint, "/") { -// endPoint = endPoint[:len(endPoint)-1] -// } -// return agentConfig.Manager.Endpoint -//} -// -//func GetListenPort() uint { -// bindAddress := global.Env().SystemConfig.APIConfig.NetworkConfig.Binding -// if strings.Contains(bindAddress, ":") { -// temps := strings.Split(bindAddress, ":") -// port, _ := strconv.Atoi(temps[1]) -// return uint(port) -// } -// return 0 -//} -// -//func IsHTTPS() bool { -// return global.Env().SystemConfig.APIConfig.TLSConfig.TLSEnabled -//} -// -//func IsAgentActivated() bool { -// instanceInfo := GetInstanceInfo() -// if instanceInfo == nil || !instanceInfo.IsRunning { -// return false -// } -// return true -//} -// -//func GetInstanceInfo() *model.Instance { -// if hostInfo != nil { -// return hostInfo -// } -// hostInfo = getInstanceInfoFromKV() -// return hostInfo -//} -// -////func GetOrInitInstanceInfo() *model.Instance { -//// if hostInfo != nil { -//// return hostInfo -//// } -//// hostInfo = getInstanceInfoFromKV() -//// if hostInfo == nil { -//// hostInfo = &model.Instance{ -//// IPs: util.GetLocalIPs(), -//// Host: agent.HostInfo{}, -//// } -//// _, majorIp, _, err := util.GetPublishNetworkDeviceInfo(agentConfig.MajorIpPattern) -//// if err != nil { -//// log.Error(err) -//// } -//// hostInfo.MajorIP = majorIp -//// } -//// SetInstanceInfo(hostInfo) -//// return hostInfo -////} -// -//func UpdateAgentBootTime() { -// instanceInfo := GetInstanceInfo() -// instanceInfo.BootTime = time.Now().UnixMilli() -// SetInstanceInfo(instanceInfo) -//} -// -//func SetInstanceInfo(host *model.Instance) error { -// if host == nil { -// return errors.New("host info can not be nil") -// } -// instanceLock.Lock() -// defer instanceLock.Unlock() -// hostInfo = host -// event.UpdateAgentID(hostInfo.AgentID) -// hostByte, _ := json.Marshal(host) -// if host.IsRunning { -// NotifyHostInfoObserver(hostInfo) -// } -// return kv.AddValue(model.KVInstanceBucket, []byte(model.KVInstanceInfo), hostByte) -//} -// -//func SetInstanceInfoNoNotify(host *model.Instance) error { -// if host == nil { -// return errors.New("host info can not be nil") -// } -// -// instanceLock.Lock() -// defer instanceLock.Unlock() -// hostInfo = host -// event.UpdateAgentID(hostInfo.AgentID) -// hostByte, _ := json.Marshal(host) -// return kv.AddValue(model.KVInstanceBucket, []byte(model.KVInstanceInfo), hostByte) -//} -// -//func DeleteInstanceInfo() error { -// hostInfo = nil -// return kv.DeleteKey(model.KVInstanceBucket, []byte(model.KVInstanceInfo)) -//} -// -//func ReloadHostInfo() { -// hostInf := getInstanceInfoFromKV() -// if hostInf == nil { -// return -// } -// ret, _ := json.Marshal(hostInf) -// log.Debugf(string(ret)) -//} -// -//var host *model.Instance -// -//func getInstanceInfoFromKV() *model.Instance { -// hs, err := kv.GetValue(model.KVInstanceBucket, []byte(model.KVInstanceInfo)) -// if err != nil { -// log.Error(err) -// return nil -// } -// if hs == nil { -// return nil -// } -// err = json.Unmarshal(hs, &host) -// if err != nil { -// log.Errorf("config.getInstanceInfoFromKV: %v\n", err) -// return nil -// } -// return host -//} From d051c8196edd88fa76b6e73554acb7aa9c78a9c5 Mon Sep 17 00:00:00 2001 From: hardy Date: Fri, 10 Jan 2025 10:27:29 +0800 Subject: [PATCH 03/10] test: reflactor env define --- .github/workflows/pr_check.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml index a8ec2c8..22fa974 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr_check.yml @@ -8,17 +8,19 @@ defaults: run: shell: bash +env: + GO_VERSION: 1.23.4 + PNAME: agent + jobs: unit_test: runs-on: ubuntu-latest - env: - GO_VERSION: 1.23.4 steps: - name: Checkout current repository uses: actions/checkout@v4 with: fetch-depth: 0 - path: agent + path: ${{ env.PNAME }} - name: Checkout framework repository uses: actions/checkout@v4 @@ -51,7 +53,7 @@ jobs: run: | echo Home path is $HOME export WORKBASE=$HOME/go/src/infini.sh - export WORK=$WORKBASE/agent + export WORK=$WORKBASE/$PNAME # for test workspace mkdir -p $HOME/go/src/ @@ -68,14 +70,12 @@ jobs: code_lint: runs-on: ubuntu-latest - env: - GO_VERSION: 1.23.4 steps: - name: Checkout current repository uses: actions/checkout@v4 with: fetch-depth: 0 - path: agent + path: ${{ env.PNAME }} - name: Checkout framework repository uses: actions/checkout@v4 @@ -108,7 +108,7 @@ jobs: run: | echo Home path is $HOME export WORKBASE=$HOME/go/src/infini.sh - export WORK=$WORKBASE/agent + export WORK=$WORKBASE/$PNAME # for test workspace mkdir -p $HOME/go/src/ From 30132ec5fa7b9b9377c40295ff744dfd0bf4c8c4 Mon Sep 17 00:00:00 2001 From: hardy Date: Fri, 10 Jan 2025 10:30:25 +0800 Subject: [PATCH 04/10] test: typo fo file --- .github/workflows/{pr_check.yml => pr-check.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{pr_check.yml => pr-check.yml} (99%) diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr-check.yml similarity index 99% rename from .github/workflows/pr_check.yml rename to .github/workflows/pr-check.yml index 22fa974..bc92077 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr-check.yml @@ -1,4 +1,4 @@ -name: PR Check +name: PR-Check on: pull_request: From 0c3bac970cb13355f2769b53d99be994407374ef Mon Sep 17 00:00:00 2001 From: hardy Date: Tue, 14 Jan 2025 12:35:17 +0800 Subject: [PATCH 05/10] chore: code format --- .github/workflows/pr-check.yml | 62 ++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index bc92077..afd5064 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -13,19 +13,73 @@ env: PNAME: agent jobs: + format_check: + runs-on: ubuntu-latest + steps: + - name: Checkout current repository + uses: actions/checkout@v4 + with: + path: ${{ env.PNAME }} + + - name: Checkout framework repository + uses: actions/checkout@v4 + with: + repository: infinilabs/framework + path: framework + + - name: Checkout framework-vendor + uses: actions/checkout@v4 + with: + ref: main + repository: infinilabs/framework-vendor + path: vendor + + - name: Set up go toolchain + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + check-latest: false + cache: true + + - name: Check go toolchain + run: go version + + - name: Run make format + shell: bash + run: | + make format + if [ $? -ne 0 ]; then + echo "make format failed, please check make output" + exit 1 + fi + + - name: Check for changes after format + id: check-changes + shell: bash + run: | + if [[ $(git status --porcelain | grep -c " M .*\.go$") -gt 0 ]]; then + echo "go format detected formatting changes" + echo "::set-output name=changes::true" + else + echo "go format no changes found" + echo "::set-output name=changes::false" + fi + + - name: Fail workflow if changes after format + if: steps.check-changes.outputs.changes == 'true' + run: exit 1 + unit_test: runs-on: ubuntu-latest steps: - name: Checkout current repository uses: actions/checkout@v4 with: - fetch-depth: 0 path: ${{ env.PNAME }} - name: Checkout framework repository uses: actions/checkout@v4 with: - fetch-depth: 0 repository: infinilabs/framework path: framework @@ -33,7 +87,6 @@ jobs: uses: actions/checkout@v4 with: ref: main - fetch-depth: 0 repository: infinilabs/framework-vendor path: vendor @@ -74,13 +127,11 @@ jobs: - name: Checkout current repository uses: actions/checkout@v4 with: - fetch-depth: 0 path: ${{ env.PNAME }} - name: Checkout framework repository uses: actions/checkout@v4 with: - fetch-depth: 0 repository: infinilabs/framework path: framework @@ -88,7 +139,6 @@ jobs: uses: actions/checkout@v4 with: ref: main - fetch-depth: 0 repository: infinilabs/framework-vendor path: vendor From f320e855d370a830f5bbe7535f0d254f2f371919 Mon Sep 17 00:00:00 2001 From: hardy Date: Tue, 14 Jan 2025 12:43:36 +0800 Subject: [PATCH 06/10] fix: format error --- .github/workflows/pr-check.yml | 20 ++++++++++++++++++++ .gitignore | 4 +++- config/generated.go | 10 ---------- 3 files changed, 23 insertions(+), 11 deletions(-) delete mode 100755 config/generated.go diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index afd5064..05c9617 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -47,6 +47,21 @@ jobs: - name: Run make format shell: bash run: | + echo Home path is $HOME + export WORKBASE=$HOME/go/src/infini.sh + export WORK=$WORKBASE/$PNAME + + # for test workspace + mkdir -p $HOME/go/src/ + ln -s $GITHUB_WORKSPACE $WORKBASE + + # check work folder + ls -lrt $WORKBASE/ + ls -alrt $WORK + + # for unit test + cd $WORK + echo Formating code at $PWD ... make format if [ $? -ne 0 ]; then echo "make format failed, please check make output" @@ -57,6 +72,11 @@ jobs: id: check-changes shell: bash run: | + export WORKBASE=$HOME/go/src/infini.sh + export WORK=$WORKBASE/$PNAME + + # for foramt check + cd $WORK if [[ $(git status --porcelain | grep -c " M .*\.go$") -gt 0 ]]; then echo "go format detected formatting changes" echo "::set-output name=changes::true" diff --git a/.gitignore b/.gitignore index 4c368f7..d18dce8 100755 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,8 @@ vendor trash *.so .public -plugin/generated_plugins.go +generated_*.go +config/generated.go +config/generat*.go config/*.tpl config/*.yml diff --git a/config/generated.go b/config/generated.go deleted file mode 100755 index f52e02d..0000000 --- a/config/generated.go +++ /dev/null @@ -1,10 +0,0 @@ -package config - -const LastCommitLog = "N/A" -const BuildDate = "N/A" - -const EOLDate = "N/A" - -const Version = "0.0.1-SNAPSHOT" - -const BuildNumber = "001" From 430e279c01fd86b94740ddae1f324121a05d7404 Mon Sep 17 00:00:00 2001 From: hardy Date: Tue, 14 Jan 2025 12:46:49 +0800 Subject: [PATCH 07/10] fix: action workflow warn --- .github/workflows/pr-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 05c9617..1877bdc 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -79,10 +79,10 @@ jobs: cd $WORK if [[ $(git status --porcelain | grep -c " M .*\.go$") -gt 0 ]]; then echo "go format detected formatting changes" - echo "::set-output name=changes::true" + echo "changes=true" >> $GITHUB_OUTPUT else echo "go format no changes found" - echo "::set-output name=changes::false" + echo "changes=false" >> $GITHUB_OUTPUT fi - name: Fail workflow if changes after format From 49563a5f6e72f9cda8477c502aff2f134ebc4297 Mon Sep 17 00:00:00 2001 From: hardy Date: Tue, 14 Jan 2025 15:30:15 +0800 Subject: [PATCH 08/10] chore: remove unused code and typo --- .github/workflows/pr-check.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 1877bdc..4df8298 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -44,14 +44,14 @@ jobs: - name: Check go toolchain run: go version - - name: Run make format + - name: Code format shell: bash run: | echo Home path is $HOME export WORKBASE=$HOME/go/src/infini.sh export WORK=$WORKBASE/$PNAME - # for test workspace + # for format workspace mkdir -p $HOME/go/src/ ln -s $GITHUB_WORKSPACE $WORKBASE @@ -59,14 +59,10 @@ jobs: ls -lrt $WORKBASE/ ls -alrt $WORK - # for unit test + # for code format cd $WORK echo Formating code at $PWD ... make format - if [ $? -ne 0 ]; then - echo "make format failed, please check make output" - exit 1 - fi - name: Check for changes after format id: check-changes @@ -180,7 +176,7 @@ jobs: export WORKBASE=$HOME/go/src/infini.sh export WORK=$WORKBASE/$PNAME - # for test workspace + # for lint workspace mkdir -p $HOME/go/src/ ln -s $GITHUB_WORKSPACE $WORKBASE @@ -188,7 +184,7 @@ jobs: ls -lrt $WORKBASE/ ls -alrt $WORK - # for unit test + # for code lint cd $WORK echo Linting code at $PWD ... make lint \ No newline at end of file From 233343ece370dd8281b031f6832967977a0abdc7 Mon Sep 17 00:00:00 2001 From: hardy Date: Tue, 14 Jan 2025 16:14:39 +0800 Subject: [PATCH 09/10] chore: typo not format files message out --- .github/workflows/pr-check.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 4df8298..6c46b57 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -83,7 +83,17 @@ jobs: - name: Fail workflow if changes after format if: steps.check-changes.outputs.changes == 'true' - run: exit 1 + run: | + export WORKBASE=$HOME/go/src/infini.sh + export WORK=$WORKBASE/$PNAME + + # for foramt check + cd $WORK && echo + git status --porcelain | grep " M .*\.go$" + echo "----------------------------------------------------------------------------------" + echo "IMPORTANT: Above files are not formatted, please run 'make format' to format them." + echo "----------------------------------------------------------------------------------" + exit 1 unit_test: runs-on: ubuntu-latest From 87f7ea1b25f0fc6719082b1d40b6777954ce97c1 Mon Sep 17 00:00:00 2001 From: hardy Date: Wed, 15 Jan 2025 14:58:07 +0800 Subject: [PATCH 10/10] chore: restore generated file --- config/generated.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 config/generated.go diff --git a/config/generated.go b/config/generated.go new file mode 100644 index 0000000..baf4979 --- /dev/null +++ b/config/generated.go @@ -0,0 +1,11 @@ +package config + +const LastCommitLog = "N/A" + +const BuildDate = "N/A" + +const EOLDate = "N/A" + +const Version = "0.0.1-SNAPSHOT" + +const BuildNumber = "001"