-
-
Notifications
You must be signed in to change notification settings - Fork 151
修复版本比对异常,日志添加时间类型 #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
feat:日志添加时间类型
Thanks for your contribution! Would you please add details on what problems this PR fix? |
修复问题:
es版本使用的是6.8.18,需要传入typ参数,但是目前版本号比较有点问题导致一直不会传入改参数。调用semver.Compare()比较方法传入的参数必须带“v”字符串才能正确比对。 另外,kibana创建日志查询需要根据time类型来排序,但目前日志内容转成一个string整体,导致拿不到time类型的字段,所以我把写入的参数val string类型改成了map[string]interface{}并加上了m["timestamp"] = time.Now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes version comparison issues and adds timestamp data to log entries. The changes modify how Elasticsearch documents are processed and written.
- Updates version comparison by adding "v" prefix to version strings for proper semantic version comparison
- Adds automatic timestamp field to log messages using current time
- Refactors document writing to accept structured data instead of JSON strings
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
stash/handler/handler.go | Adds timestamp field to messages and removes JSON marshaling |
stash/es/writer.go | Updates version handling and changes Write method signature |
stash/config/config.go | Updates default DocType value |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
return nil | ||
} | ||
} | ||
m["timestamp"] = time.Now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding timestamp with time.Now() may cause timezone issues. Consider using time.Now().UTC() for consistent timestamps across different deployments, or make the timezone configurable.
m["timestamp"] = time.Now() | |
m["timestamp"] = time.Now().UTC() |
Copilot uses AI. Check for mistakes.
) | ||
|
||
const es8Version = "8.0.0" | ||
const es8Version = "v8.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constant name 'es8Version' suggests Elasticsearch version 8, but the value 'v8.0.0' is hardcoded. Consider renaming to reflect its actual purpose or making it configurable if it represents a minimum version requirement.
Copilot uses AI. Check for mistakes.
docType: c.DocType, | ||
client: client, | ||
esVersion: version, | ||
esVersion: fmt.Sprintf("v%s", version), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using fmt.Sprintf for simple string concatenation is inefficient. Consider using string concatenation: esVersion: "v" + version
esVersion: fmt.Sprintf("v%s", version), | |
esVersion: "v" + version, |
Copilot uses AI. Check for mistakes.
No description provided.