Skip to content

Default group is always monitored #1093

@0xgouda

Description

@0xgouda

If you run pgwatch with --group group1, it will monitor/connect to sources with the group1 tag, as well as sources with default or empty group tags.

Shouldn't we be strict and only monitor sources with the group1 tag?

This weird behaviour already has tests:

t.Run("Test group limited sources", func(t *testing.T) {
source1 := sources.Source{Name: "Source 1", IsEnabled: true, Kind: sources.SourcePostgres, Group: ""} // Empty group should not filter
source2 := sources.Source{Name: "Source 2", IsEnabled: true, Kind: sources.SourcePostgres, Group: "group1"}
source3 := sources.Source{Name: "Source 3", IsEnabled: true, Kind: sources.SourcePostgres, Group: "group2"}
source4 := sources.Source{Name: "Source 4", IsEnabled: true, Kind: sources.SourcePostgres, Group: "default"} // Default group should not filter
newReader := &testutil.MockSourcesReaderWriter{
GetSourcesFunc: func() (sources.Sources, error) {
return sources.Sources{source1, source2, source3, source4}, nil
},
}
r := NewReaper(ctx, &cmdopts.Options{SourcesReaderWriter: newReader, Sources: sources.CmdOpts{Groups: []string{"group1", "group2"}}})
assert.NoError(t, r.LoadSources())
assert.Equal(t, 4, len(r.monitoredSources), "Expected four monitored sources after load")

As you can see, it limits the monitored groups to group1 and group2, but the "" and "default" groups are not filtered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedsourcesWhat sources and in what way to monitor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions