Add `-list-targets` command line flag (#4920)

* Add -list-targets flag to list available targets

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Mark user-invisible modules as such

so they are not shown as run targets when listing available targets
using the `-list-targets` flag.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Mention command line flag in configuration docs

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Add changelog entry

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* fixup! Add -list-targets flag to list available targets

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
pull/4926/head
Christian Haudum 3 years ago committed by GitHub
parent 24b4c0eed2
commit feb5d711c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 5
      cmd/loki/main.go
  3. 1
      docs/sources/configuration/_index.md
  4. 2
      pkg/loki/config_wrapper.go
  5. 35
      pkg/loki/loki.go

@ -1,5 +1,6 @@
## Main
* [4920](https://github.com/grafana/loki/pull/4920) **chaudum**: Add `-list-targets` command line flag to list all available run targets
* [4860](https://github.com/grafana/loki/pull/4860) **cyriltovena**: Add rate limiting and metrics to hedging
* [4865](https://github.com/grafana/loki/pull/4865) **taisho6339**: Fix duplicate registry.MustRegister call in Promtail Kafka
* [4845](https://github.com/grafana/loki/pull/4845) **chaudum** Return error responses consistently as JSON

@ -91,6 +91,11 @@ func main() {
t, err := loki.New(config.Config)
util_log.CheckFatal("initialising loki", err)
if config.ListTargets {
t.ListTargets()
os.Exit(0)
}
level.Info(util_log.Logger).Log("msg", "Starting Loki", "version", version.Info())
err = t.Run(loki.RunOpts{})

@ -86,6 +86,7 @@ Pass the `-config.expand-env` flag at the command line to enable this way of set
# the distributor and compactor, but all in the same process.
# Supported values: all, compactor, distributor, ingester, querier, query-scheduler,
# ingester-querier, query-frontend, index-gateway, ruler, table-manager, read, write.
# A full list of available targets can be printed when running Loki with the `-list-targets` command line flag.
[target: <string> | default = "all"]
# Enables authentication through the X-Scope-OrgID header, which must be present

@ -31,6 +31,7 @@ type ConfigWrapper struct {
PrintVersion bool
VerifyConfig bool
PrintConfig bool
ListTargets bool
LogConfig bool
ConfigFile string
ConfigExpandEnv bool
@ -40,6 +41,7 @@ func (c *ConfigWrapper) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&c.PrintVersion, "version", false, "Print this builds version information")
f.BoolVar(&c.VerifyConfig, "verify-config", false, "Verify config file and exits")
f.BoolVar(&c.PrintConfig, "print-config-stderr", false, "Dump the entire Loki config object to stderr")
f.BoolVar(&c.ListTargets, "list-targets", false, "List available targets")
f.BoolVar(&c.LogConfig, "log-config-reverse-order", false, "Dump the entire Loki config object at Info log "+
"level with the order reversed, reversing the order makes viewing the entries easier in Grafana.")
f.StringVar(&c.ConfigFile, "config.file", "", "yaml file to load")

@ -6,6 +6,8 @@ import (
"flag"
"fmt"
"net/http"
"os"
rt "runtime"
cortex_tripper "github.com/cortexproject/cortex/pkg/querier/queryrange"
cortex_ruler "github.com/cortexproject/cortex/pkg/ruler"
@ -13,6 +15,7 @@ import (
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/fakeauth"
util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/fatih/color"
"github.com/felixge/fgprof"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/flagext"
@ -295,6 +298,24 @@ func (t *Loki) bindConfigEndpoint(opts RunOpts) {
t.Server.HTTP.Path("/config").Methods("GET").HandlerFunc(configEndpointHandlerFn)
}
// ListTargets prints a list of available user visible targets and their
// dependencies
func (t *Loki) ListTargets() {
green := color.New(color.FgGreen, color.Bold)
if rt.GOOS == "windows" {
green.DisableColor()
}
for _, m := range t.ModuleManager.UserVisibleModuleNames() {
fmt.Fprintln(os.Stdout, green.Sprint(m))
for _, n := range t.ModuleManager.DependenciesForModule(m) {
if t.ModuleManager.IsUserVisibleModule(n) {
fmt.Fprintln(os.Stdout, " ", n)
}
}
}
}
// Run starts Loki running, and blocks until a Loki stops.
func (t *Loki) Run(opts RunOpts) error {
serviceMap, err := t.ModuleManager.InitModuleServices(t.Cfg.Target...)
@ -427,15 +448,15 @@ func (t *Loki) readyHandler(sm *services.Manager) http.HandlerFunc {
func (t *Loki) setupModuleManager() error {
mm := modules.NewManager(util_log.Logger)
mm.RegisterModule(Server, t.initServer)
mm.RegisterModule(RuntimeConfig, t.initRuntimeConfig)
mm.RegisterModule(MemberlistKV, t.initMemberlistKV)
mm.RegisterModule(Ring, t.initRing)
mm.RegisterModule(Overrides, t.initOverrides)
mm.RegisterModule(Server, t.initServer, modules.UserInvisibleModule)
mm.RegisterModule(RuntimeConfig, t.initRuntimeConfig, modules.UserInvisibleModule)
mm.RegisterModule(MemberlistKV, t.initMemberlistKV, modules.UserInvisibleModule)
mm.RegisterModule(Ring, t.initRing, modules.UserInvisibleModule)
mm.RegisterModule(Overrides, t.initOverrides, modules.UserInvisibleModule)
mm.RegisterModule(OverridesExporter, t.initOverridesExporter)
mm.RegisterModule(TenantConfigs, t.initTenantConfigs)
mm.RegisterModule(TenantConfigs, t.initTenantConfigs, modules.UserInvisibleModule)
mm.RegisterModule(Distributor, t.initDistributor)
mm.RegisterModule(Store, t.initStore)
mm.RegisterModule(Store, t.initStore, modules.UserInvisibleModule)
mm.RegisterModule(Ingester, t.initIngester)
mm.RegisterModule(Querier, t.initQuerier)
mm.RegisterModule(IngesterQuerier, t.initIngesterQuerier)

Loading…
Cancel
Save