Skip to content

Conversation

vine2024
Copy link

No description provided.

feat:日志添加时间类型
@kevwan
Copy link
Owner

kevwan commented Jul 12, 2024

Thanks for your contribution!

Would you please add details on what problems this PR fix?

@vine2024
Copy link
Author

Thanks for your contribution!

Would you please add details on what problems this PR fix?

修复问题:

if isSupportType(w.esVersion) && len(w.docType) > 0 {
req = req.Type(w.docType)
}

es版本使用的是6.8.18,需要传入typ参数,但是目前版本号比较有点问题导致一直不会传入改参数。调用semver.Compare()比较方法传入的参数必须带“v”字符串才能正确比对。

另外,kibana创建日志查询需要根据time类型来排序,但目前日志内容转成一个string整体,导致拿不到time类型的字段,所以我把写入的参数val string类型改成了map[string]interface{}并加上了m["timestamp"] = time.Now()

@kevwan kevwan requested a review from Copilot September 26, 2025 14:25
Copy link

@Copilot Copilot AI left a 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()
Copy link
Preview

Copilot AI Sep 26, 2025

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.

Suggested change
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"
Copy link
Preview

Copilot AI Sep 26, 2025

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),
Copy link
Preview

Copilot AI Sep 26, 2025

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

Suggested change
esVersion: fmt.Sprintf("v%s", version),
esVersion: "v" + version,

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants