Skip to content

Commit

Permalink
feat!: Remove support for legacy flags
Browse files Browse the repository at this point in the history
  • Loading branch information
timonwong committed Aug 17, 2021
1 parent eb98175 commit a65636d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 142 deletions.
23 changes: 2 additions & 21 deletions cmd/prometheus-webhook-dingtalk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"gopkg.in/alecthomas/kingpin.v2"

"github.com/timonwong/prometheus-webhook-dingtalk/config"
"github.com/timonwong/prometheus-webhook-dingtalk/internal/compat030"
"github.com/timonwong/prometheus-webhook-dingtalk/template"
"github.com/timonwong/prometheus-webhook-dingtalk/web"
)
Expand All @@ -44,12 +43,11 @@ func run() int {
configFile = kingpin.Flag(
"config.file",
"Path to the configuration file.",
).Default("config.yml").String()
).Default("config.yml").ExistingFile()
)

// DO NOT REMOVE. For compatibility purpose
kingpin.Flag("web.ui-enabled", "").Hidden().BoolVar(enableWebUI)
compat030Builder := compat030.NewBuilder(kingpin.CommandLine)

promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
Expand Down Expand Up @@ -93,25 +91,8 @@ func run() int {
Flags: flagsMap,
})

var compatConf *config.Config
if compat030Builder.IsCompatibleMode() {
var err error
compatConf, err = compat030Builder.BuildConfig()
if err != nil {
level.Error(logger).Log("msg", "Failed to build configuration from legacy commandline flags", "err", err)
return 1
}

level.Warn(logger).Log("msg", "DEPRECATION: Detected one of the following flags: --ding.profile, --ding.timeout, --template.file")
level.Warn(logger).Log("msg", "DEPRECATION: Now working in compatibility mode, please consider upgrading your configurations")
}

configLogger := log.With(logger, "component", "configuration")
configCoordinator := config.NewCoordinator(
*configFile,
compatConf,
configLogger,
)
configCoordinator := config.NewCoordinator(*configFile, configLogger)
configCoordinator.Subscribe(func(conf *config.Config) error {
// Parse templates
level.Info(configLogger).Log("msg", "Loading templates", "templates", strings.Join(conf.Templates, ";"))
Expand Down
31 changes: 12 additions & 19 deletions config/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ type Coordinator struct {
logger log.Logger

// Protects config and subscribers
mutex sync.Mutex
config *Config
frozenConfig *Config
subscribers []func(*Config) error
mutex sync.Mutex
config *Config
subscribers []func(*Config) error
}

// NewCoordinator returns a new coordinator with the given configuration file
// path. It does not yet load the configuration from file. This is done in
// `Reload()`.
func NewCoordinator(configFilePath string, frozenConfig *Config, l log.Logger) *Coordinator {
func NewCoordinator(configFilePath string, l log.Logger) *Coordinator {
c := &Coordinator{
configFilePath: configFilePath,
logger: l,
frozenConfig: frozenConfig,
}

return c
Expand Down Expand Up @@ -82,20 +80,15 @@ func (c *Coordinator) Reload() error {
defer c.mutex.Unlock()

logger := log.With(c.logger, "file", c.configFilePath)
if c.frozenConfig != nil {
logger = c.logger
c.config = c.frozenConfig
} else {
level.Info(logger).Log("msg", "Loading configuration file")
if err := c.loadFromFile(); err != nil {
level.Error(logger).Log(
"msg", "Loading configuration file failed",
"err", err,
)
return err
}
level.Info(logger).Log("msg", "Completed loading of configuration file")
level.Info(logger).Log("msg", "Loading configuration file")
if err := c.loadFromFile(); err != nil {
level.Error(logger).Log(
"msg", "Loading configuration file failed",
"err", err,
)
return err
}
level.Info(logger).Log("msg", "Completed loading of configuration file")

if err := c.notifySubscribers(); err != nil {
logger.Log("msg", "one or more config change subscribers failed to apply new config", "err", err)
Expand Down
52 changes: 0 additions & 52 deletions internal/compat030/builder.go

This file was deleted.

50 changes: 0 additions & 50 deletions internal/compat030/flag.go

This file was deleted.

0 comments on commit a65636d

Please sign in to comment.