Skip to content
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
9 changes: 4 additions & 5 deletions internal/cmd/cli/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,10 @@ func addEventsToArchive(
}

func addMetricsToArchive(ctx context.Context, c client.Client, logger logr.Logger, cfg *rest.Config, w *tar.Writer, opt Options) error {
ns := config.DefaultNamespace // XXX: support installation in non-default namespace, and check for services across all namespaces, by label?

var monitoringSvcs []corev1.Service
var svcs corev1.ServiceList
for {
opts := []client.ListOption{client.InNamespace(ns), client.Limit(opt.FetchLimit), client.Continue(svcs.Continue)}
opts := []client.ListOption{client.Limit(opt.FetchLimit), client.Continue(svcs.Continue)}

if err := c.List(ctx, &svcs, opts...); err != nil {
return fmt.Errorf("failed to list services for extracting metrics: %w", err)
Expand All @@ -508,7 +506,7 @@ func addMetricsToArchive(ctx context.Context, c client.Client, logger logr.Logge
}

if len(monitoringSvcs) == 0 {
logger.Info("No monitoring services found; Fleet has probably been installed with metrics disabled.", "namespace", ns)
logger.Info("No monitoring services found; Fleet has probably been installed with metrics disabled.")

return nil
}
Expand Down Expand Up @@ -553,7 +551,8 @@ func addMetricsToArchive(ctx context.Context, c client.Client, logger logr.Logge

logger.Info("Extracted metrics", "service", svc.Name)

if err := addFileToArchive(body, "metrics_"+svc.Name, w); err != nil {
fileName := fmt.Sprintf("metrics_%s_%s", svc.Namespace, svc.Name)
if err := addFileToArchive(body, fileName, w); err != nil {
return fmt.Errorf("failed to write metrics to archive from service %s: %w", svc.Name, err)
}
}
Expand Down
13 changes: 12 additions & 1 deletion internal/cmd/cli/dump/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,18 @@ func Test_addMetrics(t *testing.T) {
},
expErrStr: "service cattle-fleet-system/monitoring-prefixed does not have any exposed ports",
},
{
name: "monitoring service in non-default namespace is still discovered",
svcs: []corev1.Service{
{
ObjectMeta: metav1.ObjectMeta{
Name: "monitoring-prefixed",
Namespace: "custom-fleet-system",
},
},
},
expErrStr: "service custom-fleet-system/monitoring-prefixed does not have any exposed ports",
},
{
name: "monitoring service with exposed ports but no labels",
svcs: []corev1.Service{
Expand Down Expand Up @@ -501,7 +513,6 @@ func Test_addMetrics(t *testing.T) {
mockClient.EXPECT().List(
ctx,
gomock.AssignableToTypeOf(&corev1.ServiceList{}),
client.InNamespace("cattle-fleet-system"),
gomock.Any(), // client.Limit(...)
gomock.Any(), // client.Continue(...)
).
Expand Down