refactor: make codebase more modular and use a single index for all services, tools and metics
This commit is contained in:
parent
25dffecb43
commit
491eeaabd7
8 changed files with 343 additions and 130 deletions
|
|
@ -66,7 +66,8 @@ func (esc *ElasticsearchClient) SendBatch(baseIndex string, entries []LogEntry)
|
|||
|
||||
var body strings.Builder
|
||||
for _, entry := range entries {
|
||||
indexName := determineIndexName(baseIndex, entry)
|
||||
// indexName := determineIndexName(baseIndex, entry)
|
||||
indexName := "tixel"
|
||||
|
||||
indexLine := fmt.Sprintf(`{"index":{"_index":"%s"}}`, indexName)
|
||||
body.WriteString(indexLine)
|
||||
|
|
@ -102,7 +103,7 @@ func (esc *ElasticsearchClient) SendBatch(baseIndex string, entries []LogEntry)
|
|||
}
|
||||
|
||||
func (esc *ElasticsearchClient) SendSystemMetrics(baseIndex string, metrics SystemResources) error {
|
||||
msg := LogMessage{
|
||||
msg := LogEntry{
|
||||
Service: "system-metrics",
|
||||
Timestamp: time.Now(),
|
||||
LogLevel: "Info",
|
||||
|
|
@ -142,13 +143,13 @@ func (esc *ElasticsearchClient) SendSystemMetrics(baseIndex string, metrics Syst
|
|||
return nil
|
||||
}
|
||||
|
||||
func determineIndexName(baseIndex string, entry LogEntry) string {
|
||||
switch entry.Type {
|
||||
case "system_metrics":
|
||||
return fmt.Sprintf("%s-system", baseIndex)
|
||||
case "service_log":
|
||||
return fmt.Sprintf("%s-service-%s", baseIndex, entry.Service)
|
||||
default:
|
||||
return fmt.Sprintf("%s-%s", baseIndex, entry.Tool)
|
||||
}
|
||||
}
|
||||
// func determineIndexName(baseIndex string, entry LogEntry) string {
|
||||
// switch entry.Type {
|
||||
// case "system_metrics":
|
||||
// return fmt.Sprintf("%s-system", baseIndex)
|
||||
// case "service_log":
|
||||
// return fmt.Sprintf("%s-service-%s", baseIndex, entry.Service)
|
||||
// default:
|
||||
// return fmt.Sprintf("%s-%s", baseIndex, entry.Tool)
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue