-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support UTF-8 label matchers: Add compat package with feature flag and use in amtool #3483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ed5998d
2c311db
5fde3a0
7516580
075bd06
f958675
9282da4
8744682
cdab2c4
4ec38da
86f0851
2278d78
846a933
6e76633
d2e0b07
b1f8e9c
0fa923e
c8691b4
794361d
5371e4a
9dbd07d
9543033
40d3e53
f85a75e
1efe79b
5f49101
ff1c279
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -18,9 +18,13 @@ import ( | |||||||
"net/url" | ||||||||
"os" | ||||||||
"path" | ||||||||
"strings" | ||||||||
"time" | ||||||||
|
||||||||
"github.com/alecthomas/kingpin/v2" | ||||||||
"github.com/go-kit/log" | ||||||||
"github.com/go-kit/log/level" | ||||||||
clientruntime "github.com/go-openapi/runtime/client" | ||||||||
"github.com/go-openapi/strfmt" | ||||||||
promconfig "github.com/prometheus/common/config" | ||||||||
"github.com/prometheus/common/version" | ||||||||
|
@@ -29,8 +33,8 @@ import ( | |||||||
"github.com/prometheus/alertmanager/api/v2/client" | ||||||||
"github.com/prometheus/alertmanager/cli/config" | ||||||||
"github.com/prometheus/alertmanager/cli/format" | ||||||||
|
||||||||
clientruntime "github.com/go-openapi/runtime/client" | ||||||||
"github.com/prometheus/alertmanager/featurecontrol" | ||||||||
"github.com/prometheus/alertmanager/matchers/compat" | ||||||||
) | ||||||||
|
||||||||
var ( | ||||||||
|
@@ -40,11 +44,27 @@ var ( | |||||||
timeout time.Duration | ||||||||
httpConfigFile string | ||||||||
versionCheck bool | ||||||||
featureFlags string | ||||||||
|
||||||||
configFiles = []string{os.ExpandEnv("$HOME/.config/amtool/config.yml"), "/etc/amtool/config.yml"} | ||||||||
legacyFlags = map[string]string{"comment_required": "require-comment"} | ||||||||
) | ||||||||
|
||||||||
func initMatchersCompat(_ *kingpin.ParseContext) error { | ||||||||
grobinson-grafana marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
logger := log.NewLogfmtLogger(os.Stdout) | ||||||||
if verbose { | ||||||||
logger = level.NewFilter(logger, level.AllowDebug()) | ||||||||
} else { | ||||||||
logger = level.NewFilter(logger, level.AllowInfo()) | ||||||||
} | ||||||||
featureConfig, err := featurecontrol.NewFlags(logger, featureFlags) | ||||||||
if err != nil { | ||||||||
kingpin.Fatalf("error parsing the feature flag list: %v\n", err) | ||||||||
} | ||||||||
compat.InitFromFlags(logger, featureConfig) | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
func requireAlertManagerURL(pc *kingpin.ParseContext) error { | ||||||||
// Return without error if any help flag is set. | ||||||||
for _, elem := range pc.Elements { | ||||||||
|
@@ -137,6 +157,7 @@ func Execute() { | |||||||
app.Flag("timeout", "Timeout for the executed command").Default("30s").DurationVar(&timeout) | ||||||||
app.Flag("http.config.file", "HTTP client configuration file for amtool to connect to Alertmanager.").PlaceHolder("<filename>").ExistingFileVar(&httpConfigFile) | ||||||||
app.Flag("version-check", "Check alertmanager version. Use --no-version-check to disable.").Default("true").BoolVar(&versionCheck) | ||||||||
app.Flag("enable-feature", fmt.Sprintf("Experimental features to enable. The flag can be repeated to enable multiple features. Valid options: %s", strings.Join(featurecontrol.AllowedFlags, ", "))).Default("").StringVar(&featureFlags) | ||||||||
grobinson-grafana marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
app.Version(version.Print("amtool")) | ||||||||
app.GetFlag("help").Short('h') | ||||||||
|
@@ -154,6 +175,8 @@ func Execute() { | |||||||
configureConfigCmd(app) | ||||||||
configureTemplateCmd(app) | ||||||||
|
||||||||
app.Action(initMatchersCompat) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more or less documented in the doc comments for
If you still want it to be documented here I'm happy to make that change, but just wanted to share this information in case it changes your opinion. |
||||||||
|
||||||||
err = resolver.Bind(app, os.Args[1:]) | ||||||||
if err != nil { | ||||||||
kingpin.Fatalf("%v\n", err) | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.