grafana/pkg/tsdb/cloudwatch/logs.go
Arve Knudsen b79e61656a
Introduce TSDB service (#31520)
* Introduce TSDB service

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
Co-authored-by: Will Browne <will.browne@grafana.com>
Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
2021-03-08 07:02:49 +01:00

64 lines
1.5 KiB
Go

package cloudwatch
import (
"fmt"
"sync"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/registry"
)
func init() {
registry.RegisterService(&LogsService{})
}
// LogsService provides methods for querying CloudWatch Logs.
type LogsService struct {
channelMu sync.Mutex
responseChannels map[string]chan plugins.DataResponse
queues map[string](chan bool)
queueLock sync.Mutex
}
// Init is called by the DI framework to initialize the instance.
func (s *LogsService) Init() error {
s.responseChannels = make(map[string]chan plugins.DataResponse)
s.queues = make(map[string](chan bool))
return nil
}
func (s *LogsService) AddResponseChannel(name string, channel chan plugins.DataResponse) 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
}
func (s *LogsService) GetResponseChannel(name string) (chan plugins.DataResponse, 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")
}