grafana/pkg/tsdb/cloudwatch/logs.go
Arve Knudsen 78596a6756
Migrate to Wire for dependency injection (#32289)
Fixes #30144

Co-authored-by: dsotirakis <sotirakis.dim@gmail.com>
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
Co-authored-by: spinillos <selenepinillos@gmail.com>
Co-authored-by: Karl Persson <kalle.persson@grafana.com>
Co-authored-by: Leonard Gram <leo@xlson.com>
2021-08-25 15:11:22 +02:00

63 lines
1.6 KiB
Go

package cloudwatch
import (
"fmt"
"sync"
"github.com/grafana/grafana-plugin-sdk-go/backend"
)
func ProvideLogsService() *LogsService {
return &LogsService{
// nolint:staticcheck // plugins.DataQueryResponse deprecated
responseChannels: make(map[string]chan *backend.QueryDataResponse),
queues: make(map[string](chan bool)),
}
}
// LogsService provides methods for querying CloudWatch Logs.
type LogsService struct {
channelMu sync.Mutex
// nolint:staticcheck // plugins.DataQueryResult deprecated
responseChannels map[string]chan *backend.QueryDataResponse
queues map[string](chan bool)
queueLock sync.Mutex
}
// nolint:staticcheck // plugins.DataQueryResult deprecated
func (s *LogsService) AddResponseChannel(name string, channel chan *backend.QueryDataResponse) error {
s.channelMu.Lock()
defer s.channelMu.Unlock()
if _, ok := s.responseChannels[name]; ok {
return fmt.Errorf("channel with name '%s' already exists", name)
}
s.responseChannels[name] = channel
return nil
}
// nolint:staticcheck // plugins.DataQueryResult deprecated
func (s *LogsService) GetResponseChannel(name string) (chan *backend.QueryDataResponse, error) {
s.channelMu.Lock()
defer s.channelMu.Unlock()
if responseChannel, ok := s.responseChannels[name]; ok {
return responseChannel, nil
}
return nil, fmt.Errorf("channel with name '%s' not found", name)
}
func (s *LogsService) DeleteResponseChannel(name string) {
s.channelMu.Lock()
defer s.channelMu.Unlock()
if _, ok := s.responseChannels[name]; ok {
delete(s.responseChannels, name)
return
}
plog.Warn("Channel with name '" + name + "' not found")
}