-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into elasticsearch
- Loading branch information
Showing
18 changed files
with
269 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package writer | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/testutils" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testutils.VerifyGoLeaks(m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package printconfig | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func printDivider(cmd *cobra.Command, n int) { | ||
fmt.Fprint(cmd.OutOrStdout(), strings.Repeat("-", n), "\n") | ||
} | ||
|
||
func printConfigurations(cmd *cobra.Command, v *viper.Viper, includeEmpty bool) { | ||
keys := v.AllKeys() | ||
sort.Strings(keys) | ||
|
||
maxKeyLength, maxValueLength := len("Configuration Option Name"), len("Value") | ||
maxSourceLength := len("user-assigned") | ||
for _, key := range keys { | ||
value := v.GetString(key) | ||
if len(key) > maxKeyLength { | ||
maxKeyLength = len(key) | ||
} | ||
if len(value) > maxValueLength { | ||
maxValueLength = len(value) | ||
} | ||
} | ||
maxRowLength := maxKeyLength + maxValueLength + maxSourceLength + 6 | ||
|
||
printDivider(cmd, maxRowLength) | ||
fmt.Fprintf(cmd.OutOrStdout(), | ||
"| %-*s %-*s %-*s |\n", | ||
maxKeyLength, "Configuration Option Name", | ||
maxValueLength, "Value", | ||
maxSourceLength, "Source") | ||
printDivider(cmd, maxRowLength) | ||
|
||
for _, key := range keys { | ||
value := v.GetString(key) | ||
source := "default" | ||
if v.IsSet(key) { | ||
source = "user-assigned" | ||
} | ||
|
||
if includeEmpty || value != "" { | ||
fmt.Fprintf(cmd.OutOrStdout(), | ||
"| %-*s %-*s %-*s |\n", | ||
maxKeyLength, key, | ||
maxValueLength, value, | ||
maxSourceLength, source) | ||
} | ||
} | ||
printDivider(cmd, maxRowLength) | ||
} | ||
|
||
func Command(v *viper.Viper) *cobra.Command { | ||
allFlag := true | ||
cmd := &cobra.Command{ | ||
Use: "print-config", | ||
Short: "Print names and values of configuration options", | ||
Long: "Print names and values of configuration options, distinguishing between default and user-assigned values", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
printConfigurations(cmd, v, allFlag) | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().BoolVarP(&allFlag, "all", "a", false, "Print all configuration options including those with empty values") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package printconfig | ||
|
||
import ( | ||
"bytes" | ||
"flag" | ||
"testing" | ||
"time" | ||
|
||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/config" | ||
"github.com/jaegertracing/jaeger/pkg/config/tlscfg" | ||
"github.com/jaegertracing/jaeger/pkg/tenancy" | ||
) | ||
|
||
const ( | ||
testPluginBinary = "test-plugin.binary" | ||
testPluginConfigurationFile = "test-plugin.configuration-file" | ||
testPluginLogLevel = "test-plugin.log-level" | ||
testRemotePrefix = "test-remote" | ||
testRemoteServer = testRemotePrefix + ".server" | ||
testRemoteConnectionTimeout = testRemotePrefix + ".connection-timeout" | ||
defaultTestPluginLogLevel = "warn" | ||
defaultTestConnectionTimeout = time.Duration(5 * time.Second) | ||
) | ||
|
||
func addFlags(flagSet *flag.FlagSet) { | ||
tlscfg.ClientFlagsConfig{ | ||
Prefix: "test", | ||
}.AddFlags(flagSet) | ||
|
||
flagSet.String(testPluginBinary, "", "") | ||
flagSet.String(testPluginConfigurationFile, "", "") | ||
flagSet.String(testPluginLogLevel, defaultTestPluginLogLevel, "") | ||
flagSet.String(testRemoteServer, "", "") | ||
flagSet.Duration(testRemoteConnectionTimeout, defaultTestConnectionTimeout, "") | ||
} | ||
|
||
func setConfig(t *testing.T) *viper.Viper { | ||
v, command := config.Viperize(addFlags, tenancy.AddFlags) | ||
err := command.ParseFlags([]string{ | ||
"--test-plugin.binary=noop-test-plugin", | ||
"--test-plugin.configuration-file=config.json", | ||
"--test-plugin.log-level=debug", | ||
"--multi-tenancy.header=x-scope-orgid", | ||
}) | ||
|
||
require.NoError(t, err) | ||
|
||
return v | ||
} | ||
|
||
func runPrintConfigCommand(v *viper.Viper, t *testing.T, allFlag bool) string { | ||
buf := new(bytes.Buffer) | ||
printCmd := Command(v) | ||
printCmd.SetOut(buf) | ||
|
||
if allFlag { | ||
err := printCmd.Flags().Set("all", "true") | ||
require.NoError(t, err, "printCmd.Flags() returned the error %v", err) | ||
} | ||
|
||
_, err := printCmd.ExecuteC() | ||
require.NoError(t, err, "printCmd.ExecuteC() returned the error %v", err) | ||
|
||
return buf.String() | ||
} | ||
|
||
func TestAllFlag(t *testing.T) { | ||
expected := `----------------------------------------------------------------- | ||
| Configuration Option Name Value Source | | ||
----------------------------------------------------------------- | ||
| multi-tenancy.enabled false default | | ||
| multi-tenancy.header x-scope-orgid user-assigned | | ||
| multi-tenancy.tenants default | | ||
| test-plugin.binary noop-test-plugin user-assigned | | ||
| test-plugin.configuration-file config.json user-assigned | | ||
| test-plugin.log-level debug user-assigned | | ||
| test-remote.connection-timeout 5s default | | ||
| test-remote.server default | | ||
| test.tls.ca default | | ||
| test.tls.cert default | | ||
| test.tls.enabled false default | | ||
| test.tls.key default | | ||
| test.tls.server-name default | | ||
| test.tls.skip-host-verify false default | | ||
----------------------------------------------------------------- | ||
` | ||
|
||
v := setConfig(t) | ||
actual := runPrintConfigCommand(v, t, true) | ||
assert.Equal(t, expected, actual) | ||
} | ||
|
||
func TestPrintConfigCommand(t *testing.T) { | ||
expected := `----------------------------------------------------------------- | ||
| Configuration Option Name Value Source | | ||
----------------------------------------------------------------- | ||
| multi-tenancy.enabled false default | | ||
| multi-tenancy.header x-scope-orgid user-assigned | | ||
| test-plugin.binary noop-test-plugin user-assigned | | ||
| test-plugin.configuration-file config.json user-assigned | | ||
| test-plugin.log-level debug user-assigned | | ||
| test-remote.connection-timeout 5s default | | ||
| test.tls.enabled false default | | ||
| test.tls.skip-host-verify false default | | ||
----------------------------------------------------------------- | ||
` | ||
v := setConfig(t) | ||
actual := runPrintConfigCommand(v, t, false) | ||
assert.Equal(t, expected, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.