fix
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Package collector implements an OpenTelemetry consumer that stores telemetry in history
|
||||
// and broadcasts it to connected clients.
|
||||
package collector
|
||||
|
||||
import (
|
||||
@@ -18,6 +20,7 @@ import (
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
)
|
||||
|
||||
// Collector handles the collection, storage and broadcasting of telemetry data.
|
||||
type Collector struct {
|
||||
broadcaster websocket.Broadcaster
|
||||
historySize int
|
||||
@@ -28,6 +31,7 @@ type Collector struct {
|
||||
subMutex sync.Mutex
|
||||
}
|
||||
|
||||
// New creates a new Collector instance.
|
||||
func New(broadcaster websocket.Broadcaster, historySize int, store storage.Store) *Collector {
|
||||
return &Collector{
|
||||
broadcaster: broadcaster,
|
||||
@@ -38,6 +42,7 @@ func New(broadcaster websocket.Broadcaster, historySize int, store storage.Store
|
||||
}
|
||||
}
|
||||
|
||||
// SetBroadcaster updates the broadcaster used by the collector.
|
||||
func (c *Collector) SetBroadcaster(broadcaster websocket.Broadcaster) {
|
||||
c.broadcaster = broadcaster
|
||||
}
|
||||
@@ -82,6 +87,8 @@ func (c *Collector) notifySubscribers(entry websocket.HistoryEntry) {
|
||||
}
|
||||
}
|
||||
|
||||
// Subscribe adds a new history subscriber with the given filter.
|
||||
// It returns a channel for receiving filtered history entries and a cleanup function.
|
||||
func (c *Collector) Subscribe(filter func(websocket.HistoryEntry) bool) (chan websocket.HistoryEntry, func()) {
|
||||
ch := make(chan websocket.HistoryEntry, 1)
|
||||
c.subMutex.Lock()
|
||||
@@ -98,6 +105,7 @@ func (c *Collector) Subscribe(filter func(websocket.HistoryEntry) bool) (chan we
|
||||
return ch, cleanup
|
||||
}
|
||||
|
||||
// GetHistory returns the last 'limit' history entries.
|
||||
func (c *Collector) GetHistory(limit int) []websocket.HistoryEntry {
|
||||
if limit <= 0 {
|
||||
limit = c.historySize
|
||||
@@ -121,6 +129,7 @@ func (c *Collector) GetHistory(limit int) []websocket.HistoryEntry {
|
||||
return history
|
||||
}
|
||||
|
||||
// SearchHistory searches through stored telemetry data using the provided query.
|
||||
func (c *Collector) SearchHistory(ctx context.Context, query string, limit int) ([]websocket.HistoryEntry, error) {
|
||||
if limit <= 0 {
|
||||
limit = 50
|
||||
@@ -162,6 +171,7 @@ func (c *Collector) SearchHistory(ctx context.Context, query string, limit int)
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
// ConsumeTraces implements the consumer.Traces interface.
|
||||
func (c *Collector) ConsumeTraces(ctx context.Context, td ptrace.Traces) error {
|
||||
marshaler := &ptrace.JSONMarshaler{}
|
||||
buf, err := marshaler.MarshalTraces(td)
|
||||
@@ -187,6 +197,7 @@ func (c *Collector) ConsumeTraces(ctx context.Context, td ptrace.Traces) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConsumeMetrics implements the consumer.Metrics interface.
|
||||
func (c *Collector) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {
|
||||
marshaler := &pmetric.JSONMarshaler{}
|
||||
buf, err := marshaler.MarshalMetrics(md)
|
||||
@@ -212,6 +223,7 @@ func (c *Collector) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConsumeLogs implements the consumer.Logs interface.
|
||||
func (c *Collector) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
|
||||
marshaler := &plog.JSONMarshaler{}
|
||||
buf, err := marshaler.MarshalLogs(ld)
|
||||
@@ -238,7 +250,7 @@ func (c *Collector) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Implement consumer interfaces
|
||||
// Capabilities returns the capabilities of the collector.
|
||||
func (c *Collector) Capabilities() consumer.Capabilities {
|
||||
return consumer.Capabilities{MutatesData: false}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user