Skip to content
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

enhancement(agentctl): add inspect flag in test-logs cmd #6836

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ v0.41.0 (2024-05-31)

### Enhancements

- Add `--inspect` flag in ``grafana-agentctl test-logs` cmd. (@fgouteroux)

- Add support for importing folders as single module to `import.file`. (@wildum)

- Add support for importing directories as single module to `import.git`. (@wildum)
Expand Down
2 changes: 1 addition & 1 deletion cmd/grafana-agent/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewEntrypoint(logger *server.Logger, cfg *config.Config, reloader Reloader)
return nil, err
}

ep.lokiLogs, err = logs.New(reg, cfg.Logs, logger, false)
ep.lokiLogs, err = logs.New(reg, cfg.Logs, logger, false, false)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/grafana-agentctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func filterAgentOwners(refs []meta_v1.OwnerReference) (filtered []meta_v1.OwnerR
}

func testLogs() *cobra.Command {
var inspect bool
cmd := &cobra.Command{
Use: "test-logs [config file]",
Short: "Collect logs but print entries instead of sending them to Loki.",
Expand All @@ -452,7 +453,7 @@ func testLogs() *cobra.Command {
}

logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
l, err := logs.New(prometheus.NewRegistry(), cfg.Logs, logger, true)
l, err := logs.New(prometheus.NewRegistry(), cfg.Logs, logger, true, inspect)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to start log collection: %s\n", err)
os.Exit(1)
Expand All @@ -466,6 +467,7 @@ func testLogs() *cobra.Command {
fmt.Fprintf(os.Stderr, "received shutdown %v signal, stopping...", sig)
},
}
cmd.Flags().BoolVarP(&inspect, "inspect", "i", false, "Allows for detailed inspection of pipeline stages.")

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion internal/component/loki/source/file/legacy_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ configs:
require.NoError(t, dec.Decode(&cfg))
require.NoError(t, cfg.ApplyDefaults())
logger := logkit.NewNopLogger()
l, err := logs.New(prometheus.NewRegistry(), &cfg, logger, false)
l, err := logs.New(prometheus.NewRegistry(), &cfg, logger, false, false)
require.NoError(t, err)
//
// Write a log line and wait for it to come through.
Expand Down
4 changes: 2 additions & 2 deletions static/logs/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ configs:
var cfg Config

logger := util.TestLogger(t)
l, err := New(prometheus.NewRegistry(), &cfg, logger, false)
l, err := New(prometheus.NewRegistry(), &cfg, logger, false, false)
require.NoError(t, err)
defer l.Stop()

Expand Down Expand Up @@ -72,7 +72,7 @@ configs:
require.NoError(t, dec.Decode(&cfg))

logger := util.TestLogger(t)
l, err := New(prometheus.NewRegistry(), &cfg, logger, false)
l, err := New(prometheus.NewRegistry(), &cfg, logger, false, false)
require.NoError(t, err)
defer l.Stop()

Expand Down
6 changes: 5 additions & 1 deletion static/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/grafana/agent/internal/agentseed"
"github.com/grafana/agent/internal/useragent"
"github.com/grafana/agent/internal/util"
"github.com/grafana/loki/clients/pkg/logentry/stages"
"github.com/grafana/loki/clients/pkg/promtail"
"github.com/grafana/loki/clients/pkg/promtail/api"
"github.com/grafana/loki/clients/pkg/promtail/client"
Expand All @@ -40,12 +41,15 @@ type Logs struct {
}

// New creates and starts Loki log collection.
func New(reg prometheus.Registerer, c *Config, l log.Logger, dryRun bool) (*Logs, error) {
func New(reg prometheus.Registerer, c *Config, l log.Logger, dryRun, inspect bool) (*Logs, error) {
logs := &Logs{
instances: make(map[string]*Instance),
reg: reg,
l: log.With(l, "component", "logs"),
}

stages.Inspect = inspect

if err := logs.ApplyConfig(c, dryRun); err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions static/logs/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func TestLogs_NilConfig(t *testing.T) {
l, err := New(prometheus.NewRegistry(), nil, util.TestLogger(t), false)
l, err := New(prometheus.NewRegistry(), nil, util.TestLogger(t), false, false)
require.NoError(t, err)
require.NoError(t, l.ApplyConfig(nil, false))

Expand Down Expand Up @@ -88,7 +88,7 @@ configs:
require.NoError(t, dec.Decode(&cfg))
require.NoError(t, cfg.ApplyDefaults())
logger := log.NewSyncLogger(log.NewNopLogger())
l, err := New(prometheus.NewRegistry(), &cfg, logger, false)
l, err := New(prometheus.NewRegistry(), &cfg, logger, false, false)
require.NoError(t, err)
defer l.Stop()

Expand Down Expand Up @@ -195,7 +195,7 @@ configs:
require.NoError(t, dec.Decode(&cfg))
require.NoError(t, cfg.ApplyDefaults())
logger := util.TestLogger(t)
l, err := New(prometheus.NewRegistry(), &cfg, logger, false)
l, err := New(prometheus.NewRegistry(), &cfg, logger, false, false)
require.NoError(t, err)
defer l.Stop()

Expand Down
Loading