Skip to content

Commit 7ee0aad

Browse files
committed
fix v2.Config -> v3.Config convert
1 parent 2027b09 commit 7ee0aad

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func unmarshal(content []byte, version int) (*v3.Config, error) {
7474
if err != nil {
7575
return nil, err
7676
}
77-
return v3.Convert(v2cfg), nil
77+
return v3.Convert(v2cfg)
7878
case 3:
7979
return v3.Unmarshal(content)
8080
default:

config/v3/configV3.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package v3
1616

1717
import (
1818
"fmt"
19+
v2 "github.com/fstab/grok_exporter/config/v2"
1920
"github.com/fstab/grok_exporter/tailer/glob"
2021
"github.com/fstab/grok_exporter/template"
2122
"gopkg.in/yaml.v2"
@@ -57,6 +58,18 @@ func Unmarshal(config []byte) (*Config, error) {
5758
return cfg, nil
5859
}
5960

61+
func Convert(v2cfg *v2.Config) (*Config, error) {
62+
v3cfg := convert(v2cfg)
63+
for _, metric := range v3cfg.OrigMetrics {
64+
v3cfg.AllMetrics = append(v3cfg.AllMetrics, metric)
65+
}
66+
err := AddDefaultsAndValidate(v3cfg)
67+
if err != nil {
68+
return nil, err
69+
}
70+
return v3cfg, nil
71+
}
72+
6073
type Config struct {
6174
Global GlobalConfig `yaml:",omitempty"`
6275
Input InputConfig `yaml:",omitempty"`

config/v3/converter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"time"
2323
)
2424

25-
func Convert(v2cfg *v2.Config) *Config {
25+
func convert(v2cfg *v2.Config) *Config {
2626
return &Config{
2727
Global: convertGlobal(v2cfg),
2828
Input: convertInput(v2cfg),

config/v3/converter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func TestConvert(t *testing.T) {
156156
if err != nil {
157157
t.Fatalf("error unmarshalling input: %v", err)
158158
}
159-
v3cfg := Convert(v2cfg)
159+
v3cfg := convert(v2cfg)
160160
err = equalsIgnoreIndentation(v3cfg.String(), test.expected)
161161
if err != nil {
162162
t.Fatalf("Expected:\n%v\nActual:\n%v\n%v", test.expected, v3cfg, err)

0 commit comments

Comments
 (0)