Skip to content

Commit

Permalink
Add toyamlconfig package (#1)
Browse files Browse the repository at this point in the history
* add toyamlconfig translator that converts json config to yaml to be used for otel adapted telegraf plugins
  • Loading branch information
aateeqi authored Jun 29, 2022
1 parent aa5ae9b commit 47b81f1
Show file tree
Hide file tree
Showing 105 changed files with 1,495 additions and 959 deletions.
17 changes: 12 additions & 5 deletions cmd/config-translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"flag"
"fmt"
"log"
"os"
"os/user"
Expand All @@ -18,9 +19,11 @@ import (
)

const (
exitErrorMessage = "Configuration validation first phase failed. Agent version: %v. Verify the JSON input is only using features supported by this version.\n"
version = "1.0"
envConfigFileName = "env-config.json"
exitErrorMessage = "Configuration validation first phase failed. Agent version: %v. Verify the JSON input is only using features supported by this version.\n"
exitSuccessMessage = "Configuration validation first phase succeeded"
version = "1.0"
envConfigFileName = "env-config.json"
yamlConfigFileName = "amazon-cloudwatch-config.yaml"
)

func initFlags() {
Expand Down Expand Up @@ -105,8 +108,12 @@ func main() {
}

tomlConfigPath := cmdutil.GetTomlConfigPath(ctx.OutputTomlFilePath())
cmdutil.TranslateJsonMapToTomlFile(mergedJsonConfigMap, tomlConfigPath)
// Put env config into the same folder as the toml config.
yamlConfigPath := filepath.Join(filepath.Dir(tomlConfigPath), yamlConfigFileName)
config := cmdutil.TranslateJsonMapToConfig(mergedJsonConfigMap)
cmdutil.ConfigToTomlFile(config, tomlConfigPath)
cmdutil.ConfigToYamlFile(config, yamlConfigPath)
fmt.Println(exitSuccessMessage)
// Put env config into the same folder as the toml config
envConfigPath := filepath.Join(filepath.Dir(tomlConfigPath), envConfigFileName)
cmdutil.TranslateJsonMapToEnvConfigFile(mergedJsonConfigMap, envConfigPath)
}
8 changes: 4 additions & 4 deletions cmd/config-translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ func TestInvalidLogFilterConfig(t *testing.T) {

// Validate all sampleConfig files schema
func TestSampleConfigSchema(t *testing.T) {
if files, err := ioutil.ReadDir("../../translator/totomlconfig/sampleConfig/"); err == nil {
if files, err := ioutil.ReadDir("../../translator/tocwconfig/sampleConfig/"); err == nil {
re := regexp.MustCompile(".json")
for _, file := range files {
if re.MatchString(file.Name()) {
t.Logf("Validating ../../translator/totomlconfig/sampleConfig/%s\n", file.Name())
checkIfSchemaValidateAsExpected(t, "../../translator/totomlconfig/sampleConfig/"+file.Name(), true, map[string]int{})
t.Logf("Validated ../../translator/totomlconfig/sampleConfig/%s\n", file.Name())
t.Logf("Validating ../../translator/tocwconfig/sampleConfig/%s\n", file.Name())
checkIfSchemaValidateAsExpected(t, "../../translator/tocwconfig/sampleConfig/"+file.Name(), true, map[string]int{})
t.Logf("Validated ../../translator/tocwconfig/sampleConfig/%s\n", file.Name())
}
}
} else {
Expand Down
56 changes: 29 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ require (
github.com/kardianos/service v1.2.1
github.com/kr/pretty v0.3.0
github.com/mesos/mesos-go v0.0.7-0.20180413204204-29de6ff97b48
github.com/mitchellh/mapstructure v1.5.0
github.com/oklog/run v1.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/common v0.34.0
github.com/prometheus/prometheus v1.8.2-0.20210430082741-2a4b8e12bbf2
github.com/shirou/gopsutil/v3 v3.22.3
github.com/shirou/gopsutil/v3 v3.22.5
github.com/stretchr/testify v1.7.1
github.com/xeipuuv/gojsonschema v1.2.0
go.opentelemetry.io/collector v0.53.0
golang.org/x/net v0.0.0-20220412020605-290c469a71a5
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
Expand All @@ -89,6 +91,7 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.1.0
k8s.io/api v0.23.6
k8s.io/apimachinery v0.23.6
Expand All @@ -99,8 +102,8 @@ require (
require (
cloud.google.com/go/compute v1.6.0 // indirect
collectd.org v0.4.0 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.1 // indirect
github.com/Azure/azure-sdk-for-go v63.0.0+incompatible // indirect
github.com/Azure/go-amqp v0.17.4 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.25 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
Expand All @@ -109,25 +112,20 @@ require (
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e // indirect
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/alecthomas/participle v0.4.1 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/antchfx/jsonquery v1.1.5 // indirect
github.com/antchfx/xmlquery v1.3.9 // indirect
github.com/antchfx/xpath v1.2.0 // indirect
github.com/apache/thrift v0.16.0 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.10 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.3 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.26.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.3 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
Expand Down Expand Up @@ -156,19 +154,17 @@ require (
github.com/envoyproxy/protoc-gen-validate v0.6.7 // indirect
github.com/euank/go-kmsg-parser v2.0.0+incompatible // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/frankban/quicktest v1.14.2 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 // indirect
github.com/go-zookeeper/zk v1.0.2 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand All @@ -188,26 +184,28 @@ require (
github.com/hashicorp/serf v0.9.6 // indirect
github.com/hetznercloud/hcloud-go v1.33.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/influxdata/line-protocol/v2 v2.2.1 // indirect
github.com/jaegertracing/jaeger v1.33.0 // indirect
github.com/jhump/protoreflect v1.8.3-0.20210616212123-6cc1efa697ca // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/knadh/koanf v1.4.1 // indirect
github.com/kolo/xmlrpc v0.0.0-20201022064351-38db28db192b // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/ragel-machinery v0.0.0-20190525184631-5f46317e436b // indirect
github.com/linode/linodego v1.4.1 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/miekg/dns v1.1.48 // indirect
github.com/mindprince/gonvml v0.0.0-20190828220739-9ebdce4bb989 // indirect
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/sys/mountinfo v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -219,23 +217,23 @@ require (
github.com/opencontainers/runc v1.1.0 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opencontainers/selinux v1.10.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/philhofer/fwd v1.1.1 // indirect
github.com/pierrec/lz4/v4 v4.1.14 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/statsd_exporter v0.21.0 // indirect
github.com/rogpeppe/go-internal v1.6.2 // indirect
github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1 // indirect
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9 // indirect
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921 // indirect
github.com/shirou/gopsutil v3.21.5+incompatible // indirect
github.com/signalfx/com_signalfx_metrics_protobuf v0.0.3 // indirect
github.com/signalfx/sapm-proto v0.9.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sleepinggenius2/gosmi v0.4.4 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
Expand All @@ -249,17 +247,22 @@ require (
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
github.com/vjeantet/grok v1.0.1 // indirect
github.com/wavefronthq/wavefront-sdk-go v0.9.10 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yuin/gopher-lua v0.0.0-20220413183635-c841877397d8 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/collector/model v0.48.0 // indirect
go.opentelemetry.io/collector/pdata v0.53.0 // indirect
go.opentelemetry.io/collector/semconv v0.53.0 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.30.0 // indirect
go.opentelemetry.io/otel/metric v0.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.30.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
Expand All @@ -270,15 +273,14 @@ require (
google.golang.org/api v0.77.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4 // indirect
google.golang.org/grpc v1.46.0 // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
modernc.org/ccgo/v3 v3.16.2 // indirect
modernc.org/libc v1.15.0 // indirect
modernc.org/cc/v3 v3.35.26 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.0.7 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
Expand Down
Loading

0 comments on commit 47b81f1

Please sign in to comment.