Skip to content

PO to GMP Migration Tool: Orchestrator & CLI Boilerplate#1961

Merged
karthunni merged 28 commits into
mainfrom
karthunni/podmonitor-migration
Jun 26, 2026
Merged

PO to GMP Migration Tool: Orchestrator & CLI Boilerplate#1961
karthunni merged 28 commits into
mainfrom
karthunni/podmonitor-migration

Conversation

@karthunni

Copy link
Copy Markdown
Collaborator

This PR implements the migration pipeline and CLI carriage boilerplate for the gmp-migrate tool.

  • CLI Carriage: Command-line entrypoint supporting files, directories, and stdin/stdout streams.
  • Parsed-Resource Cache: Stores parsed namespaced resources for cross-reference during migrations.
  • Migration Pipeline: Orchestrator handling YAML parsing and converter execution..
  • Decoupled Logging: Structured logging (LogMessage, MigrationReport) routed to Stderr to keep Stdout clean for Unix piping.
  • Unit Tests: Validates cache isolation, converter registration, and logging.

@karthunni karthunni self-assigned this Jun 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new command-line tool gmp-migrate and a supporting migrate package to facilitate the migration of Prometheus Operator configurations to Google Managed Prometheus (GMP). The core logic parses Kubernetes manifests, caches them for cross-resource resolution, and runs registered converters to output translated manifests. The review feedback focuses on improving the tool's robustness and testability. Key recommendations include: ensuring deterministic resource conversion by sorting map keys, preventing file collisions by incorporating namespaces into output filenames, decoupling standard input (Stdin) for better testability, using filepath.WalkDir for more efficient directory traversal, and adding defensive nil checks within the ResourceCache methods.

Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go
Comment thread pkg/migrate/migrate.go
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/types.go Outdated
Comment thread pkg/migrate/types.go
@karthunni karthunni force-pushed the karthunni/podmonitor-migration branch from 9857444 to 4976085 Compare June 17, 2026 19:22
@karthunni karthunni force-pushed the karthunni/podmonitor-migration branch from 1de300d to 036f215 Compare June 17, 2026 19:30
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@karthunni karthunni requested a review from bernot-dev June 17, 2026 19:39

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new migration tool, gmp-migrate, designed to translate Prometheus Operator configurations to Google Managed Prometheus (GMP). It includes a Dockerfile, a CLI entry point, core migration orchestration logic, and a resource caching mechanism. The review feedback highlights several critical improvements to enhance the tool's robustness and safety: ensuring the CLI exits with a non-zero code when individual resource migrations fail, making file extension checks case-insensitive, skipping nameless resources to avoid cache collisions, deep-copying cached resources before conversion to prevent unintended mutations, and adding nil-safety checks to the resource cache.

Comment thread cmd/gmp-migrate/main.go
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/types.go Outdated
Comment thread cmd/gmp-migrate/main.go Outdated
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate tool and its core migration package, which translates Prometheus Operator configurations to Google Managed Prometheus (GMP). The feedback highlights critical issues regarding thread safety and robustness. Specifically, the custom ConsoleHandler is susceptible to data races when sharing the resourceLevels map across instances, and modifying the global default logger (slog.SetDefault) within a library function is an anti-pattern that should be avoided. Additionally, several improvements are suggested to prevent potential nil-pointer dereferences by defensively handling nil streams, nil output elements, and zero-value initializations of the ResourceCache.

Comment thread pkg/migrate/logger.go
Comment thread pkg/migrate/logger.go
Comment thread pkg/migrate/logger.go Outdated
Comment thread pkg/migrate/logger.go Outdated
Comment thread pkg/migrate/logger.go
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/types.go Outdated
Comment thread pkg/migrate/types.go
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate tool, which migrates Prometheus Operator configurations to Google Managed Prometheus (GMP). It includes a CLI entry point, a core migrator orchestrator, a custom logging handler to track resource-level migration status, and associated unit tests. The review feedback highlights several critical issues: mutating empty namespaces to 'default' can corrupt cluster-scoped resources; debug-level logs are omitted from the final report due to a map lookup bug; additional validation is needed for malformed Kubernetes resources missing kind or apiVersion; and successfully processed resources with zero outputs are incorrectly excluded from the final statistics.

Comment thread pkg/migrate/types.go Outdated
Comment thread pkg/migrate/logger.go
Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go Outdated
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate tool to migrate Prometheus Operator configurations to Google Managed Prometheus (GMP), including a custom console logger, a resource cache, and migration orchestration logic. The reviewer provided several critical recommendations: silently skipping non-Kubernetes YAML files during directory walks to prevent fragile failures, copying attributes in ConsoleHandler.WithAttrs to avoid concurrent slice mutation race conditions, removing redundant filtering code in convertResources, and decoupling migration statistics tracking from logging side-effects to preserve user-configured loggers.

Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/logger.go
Comment thread pkg/migrate/migrate.go
Comment thread pkg/migrate/migrate.go Outdated
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate tool, which automates the migration of Prometheus Operator configurations to Google Managed Prometheus (GMP). It includes a Dockerfile, a CLI entry point, a custom structured logging handler, and the core migration orchestration logic with caching and namespace scoping. The feedback suggests defensively defaulting standard streams in the migrator to prevent nil-pointer dereferences when run programmatically, and properly handling write errors on standard output while avoiding unnecessary string allocations.

Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/migrate.go Outdated
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate tool, which automates the migration of Prometheus Operator configurations to Google Managed Prometheus (GMP). It includes a Dockerfile, a CLI entry point, a custom thread-safe logging handler, and the core migration orchestration logic with accompanying unit tests. The review feedback highlights a critical concurrency issue where a shared map is read without a lock, potentially causing a panic, and suggests adding a thread-safe getter method. Additionally, it recommends using the pflag package to simplify and clean up command-line flag parsing.

Comment thread pkg/migrate/migrate.go Outdated
Comment thread pkg/migrate/logger.go
Comment thread cmd/gmp-migrate/main.go

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new migration tool, gmp-migrate, designed to translate Prometheus Operator configurations to Google Managed Prometheus (GMP). The implementation includes a Dockerfile, a CLI entrypoint, a custom console logger, core migration logic, and corresponding unit tests. The review feedback highlights several improvement opportunities: refactoring the Dockerfile to avoid nested double quotes in -ldflags, validating CLI arguments to prevent unexpected positional arguments from being silently ignored, updating the directory walk to skip hidden files, and logging a warning when a List resource is skipped.

Comment thread cmd/gmp-migrate/Dockerfile
Comment thread cmd/gmp-migrate/main.go Outdated
Comment thread pkg/migrate/migrate.go
Comment thread pkg/migrate/migrate.go Outdated
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate tool, which migrates Prometheus Operator configurations to Google Managed Prometheus (GMP). It includes a CLI entry point, a custom thread-safe ConsoleHandler for logging and tracking migration statuses, a Migrator orchestrator, a ResourceCache for cross-resource resolution, and associated tests. The reviewer feedback highlights three areas for improvement: resolving an inconsistency where parse errors abort execution for direct files/stdin but are skipped during directory walks, refining the directory walk logic to robustly skip all hidden files and directories, and simplifying the slice allocation in WithAttrs using a more idiomatic append pattern.

Comment thread pkg/migrate/migrate.go
Comment thread pkg/migrate/migrate.go
Comment thread pkg/migrate/logger.go
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@karthunni karthunni force-pushed the karthunni/podmonitor-migration branch from 4ca8075 to c5440d0 Compare June 24, 2026 15:47

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate CLI tool and package to facilitate the migration of Prometheus Operator configurations to Google Managed Prometheus (GMP). It includes a core Migrator orchestrator, a custom slog handler for console logging and status tracking, a resource cache, and comprehensive tests. Feedback highlights two key improvements: re-initializing the resource cache on every Run call to prevent state bleeding across multiple executions, and dynamically constructing the suggested command-line flags in the CLI error message to avoid malformed examples when no input files are specified.

Comment thread pkg/migrate/migrate.go Outdated
Comment thread cmd/gmp-migrate/main.go Outdated
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate CLI tool and a supporting migrate package to convert Prometheus Operator configurations to Google Managed Prometheus (GMP). Key additions include a custom console logger, a resource cache, and the core migration runner. The feedback recommends validating the resource's kind and apiVersion before caching to prevent malformed entries, and decoupling the CLI summary printing from the core Run method to improve the package's reusability as a library.

Comment thread pkg/migrate/types.go
Comment thread pkg/migrate/migrate.go Outdated
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate tool, which migrates Prometheus Operator configurations to Google Managed Prometheus (GMP). It includes a Dockerfile, a CLI entry point, a custom console logger, and the core migration logic with unit tests. Key feedback highlights two main issues: first, duplicate resources added to the cache will silently overwrite existing entries, potentially causing silent configuration conflicts; second, writing manifests directly to standard output during processing can result in partial outputs on failure, so buffering the output is recommended.

Comment thread pkg/migrate/types.go
Comment thread pkg/migrate/migrate.go Outdated
@karthunni

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gmp-migrate tool, which migrates Prometheus Operator configurations to Google Managed Prometheus (GMP). It includes a CLI entry point, a custom thread-safe logging handler to track migration statuses, a resource caching mechanism, and comprehensive unit tests. Feedback on the changes suggests optimizing the WriteOutputs function in pkg/migrate/migrate.go by writing directly to the output stream instead of buffering the entire multi-document YAML in a strings.Builder to reduce memory allocations.

Comment thread pkg/migrate/migrate.go
@karthunni karthunni force-pushed the karthunni/podmonitor-migration branch from 3986de9 to 9966902 Compare June 24, 2026 20:27
@karthunni karthunni marked this pull request as ready for review June 24, 2026 22:10
Comment thread pkg/migrate/logger.go Outdated

// Custom slog.Levels for status logging.
const (
LevelSuccess slog.Level = slog.LevelInfo - 1 // Level -1 (Standard Info is 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use LevelDebug for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the LevelSuccess just for the explicit naming to reduce confusion, but for the sake of simplicity we could map it to LevelDebug instead

Comment thread pkg/migrate/logger.go Outdated
// Custom slog.Levels for status logging.
const (
LevelSuccess slog.Level = slog.LevelInfo - 1 // Level -1 (Standard Info is 0)
LevelSkipped slog.Level = slog.LevelInfo + 1 // Level 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The could probably just be LevelInfo/LevelWarn.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to get rid of the custom level, I would need to add an attribute to the log to flag it's a skip, so I can count skips accordingly in the Handler for the final summary.

Also should I continue to log it as [SKIPPED] or just have it default to [INFO] or [WARNING]?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you count skips outside of the log messages?

@bernot-dev bernot-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minus some minor issues. We can continue to iterate, as necessary.

@karthunni karthunni force-pushed the karthunni/podmonitor-migration branch from 773c59b to a3113ee Compare June 26, 2026 17:58
@karthunni karthunni force-pushed the karthunni/podmonitor-migration branch from a3113ee to ad15fd3 Compare June 26, 2026 18:00
@karthunni karthunni merged commit bf51fd4 into main Jun 26, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants