Use pointer to metrics instead of forwarding full metric

This commit is contained in:
Thomas Roehl
2022-01-31 14:16:50 +01:00
parent 3e329c3324
commit 7f4de77de1
34 changed files with 199 additions and 180 deletions

View File

@@ -20,7 +20,7 @@ type receiver struct {
port string
database string
organization string
sink chan lp.CCMetric
sink chan *lp.CCMetric
}
type Receiver interface {
@@ -28,14 +28,14 @@ type Receiver interface {
Start()
Close()
Name() string
SetSink(sink chan lp.CCMetric)
SetSink(sink chan *lp.CCMetric)
}
func (r *receiver) Name() string {
return r.name
}
func (r *receiver) SetSink(sink chan lp.CCMetric) {
func (r *receiver) SetSink(sink chan *lp.CCMetric) {
r.sink = sink
}

View File

@@ -3,11 +3,12 @@ package receivers
import (
"errors"
"fmt"
"time"
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
influx "github.com/influxdata/line-protocol"
nats "github.com/nats-io/nats.go"
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
"time"
)
type NatsReceiverConfig struct {
@@ -35,7 +36,7 @@ func (r *NatsReceiver) Init(config ReceiverConfig) error {
if len(r.config.Addr) == 0 ||
len(r.config.Port) == 0 ||
len(r.config.Database) == 0 {
return errors.New("Not all configuration variables set required by NatsReceiver")
return errors.New("not all configuration variables set required by NatsReceiver")
}
r.meta = map[string]string{"source": r.name}
r.addr = r.config.Addr
@@ -76,7 +77,7 @@ func (r *NatsReceiver) _NatsReceive(m *nats.Msg) {
y.AddMeta(k, v)
}
if r.sink != nil {
r.sink <- y
r.sink <- &y
}
}
}

View File

@@ -15,7 +15,7 @@ var AvailableReceivers = map[string]Receiver{
type receiveManager struct {
inputs []Receiver
output chan lp.CCMetric
output chan *lp.CCMetric
done chan bool
wg *sync.WaitGroup
config []ReceiverConfig
@@ -24,7 +24,7 @@ type receiveManager struct {
type ReceiveManager interface {
Init(wg *sync.WaitGroup, receiverConfigFile string) error
AddInput(rawConfig json.RawMessage) error
AddOutput(output chan lp.CCMetric)
AddOutput(output chan *lp.CCMetric)
Start()
Close()
}
@@ -87,7 +87,7 @@ func (rm *receiveManager) AddInput(rawConfig json.RawMessage) error {
return nil
}
func (rm *receiveManager) AddOutput(output chan lp.CCMetric) {
func (rm *receiveManager) AddOutput(output chan *lp.CCMetric) {
rm.output = output
for _, r := range rm.inputs {
r.SetSink(rm.output)