Change CCMetric's internal data structure (#22)

* package ccmetric rewrite

* Create deep copy in New() to avoid access conflicts

* Renamed TagMap() -> Tags(), MetaMap() -> Meta

Co-authored-by: Holger Obermaier <40787752+ho-ob@users.noreply.github.com>
This commit is contained in:
Thomas Gruber
2022-02-01 14:54:34 +01:00
committed by GitHub
parent 862630a218
commit 6ff6cb7219
4 changed files with 92 additions and 158 deletions

View File

@@ -30,16 +30,16 @@ func (s *GangliaSink) Write(point lp.CCMetric) error {
var err error = nil
var tagsstr []string
var argstr []string
for _, t := range point.TagList() {
switch t.Key {
for key, value := range point.Tags() {
switch key {
case "cluster":
argstr = append(argstr, fmt.Sprintf("--cluster=%s", t.Value))
argstr = append(argstr, fmt.Sprintf("--cluster=%s", value))
case "unit":
argstr = append(argstr, fmt.Sprintf("--units=%s", t.Value))
argstr = append(argstr, fmt.Sprintf("--units=%s", value))
case "group":
argstr = append(argstr, fmt.Sprintf("--group=%s", t.Value))
argstr = append(argstr, fmt.Sprintf("--group=%s", value))
default:
tagsstr = append(tagsstr, fmt.Sprintf("%s=%s", t.Key, t.Value))
tagsstr = append(tagsstr, fmt.Sprintf("%s=%s", key, value))
}
}
if len(tagsstr) > 0 {

View File

@@ -5,10 +5,11 @@ import (
"crypto/tls"
"errors"
"fmt"
"log"
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
influxdb2Api "github.com/influxdata/influxdb-client-go/v2/api"
"log"
)
type InfluxSink struct {
@@ -61,12 +62,12 @@ func (s *InfluxSink) Init(config sinkConfig) error {
func (s *InfluxSink) Write(point lp.CCMetric) error {
tags := map[string]string{}
fields := map[string]interface{}{}
for _, t := range point.TagList() {
tags[t.Key] = t.Value
for key, value := range point.Tags() {
tags[key] = value
}
if s.meta_as_tags {
for _, m := range point.MetaList() {
tags[m.Key] = m.Value
for key, value := range point.Meta() {
tags[key] = value
}
}
for _, f := range point.FieldList() {