refactor: move models to their own package to use the same as in the importer
This commit is contained in:
parent
553a85562b
commit
9aa1b7384d
14 changed files with 170 additions and 152 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
"tixel_watch/models"
|
||||
|
||||
"github.com/elastic/go-elasticsearch/v8"
|
||||
)
|
||||
|
|
@ -50,8 +51,8 @@ func TestElasticsearchConnection(es *elasticsearch.Client) error {
|
|||
}
|
||||
|
||||
type ElasticsearchSender interface {
|
||||
SendBatch(baseIndex string, entries []LogEntry) error
|
||||
SendSystemMetrics(baseIndex string, metrics SystemResources) error
|
||||
SendBatch(baseIndex string, entries []models.LogMessage) error
|
||||
SendSystemMetrics(baseIndex string, metrics models.SystemResources) error
|
||||
}
|
||||
|
||||
type ElasticsearchClient struct {
|
||||
|
|
@ -62,7 +63,7 @@ func NewElasticsearchSender(client *elasticsearch.Client) ElasticsearchSender {
|
|||
return &ElasticsearchClient{client: client}
|
||||
}
|
||||
|
||||
func (esc *ElasticsearchClient) SendBatch(baseIndex string, entries []LogEntry) error {
|
||||
func (esc *ElasticsearchClient) SendBatch(baseIndex string, entries []models.LogMessage) error {
|
||||
if len(entries) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -105,8 +106,8 @@ func (esc *ElasticsearchClient) SendBatch(baseIndex string, entries []LogEntry)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (esc *ElasticsearchClient) SendSystemMetrics(baseIndex string, metrics SystemResources) error {
|
||||
msg := LogEntry{
|
||||
func (esc *ElasticsearchClient) SendSystemMetrics(baseIndex string, metrics models.SystemResources) error {
|
||||
msg := models.LogMessage{
|
||||
Service: "system-metrics",
|
||||
Timestamp: time.Now(),
|
||||
LogLevel: "Info",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue