Skip to content

[-] fix sources handling in config upgrade#1274

Closed
0xgouda wants to merge 6 commits intomasterfrom
fix-sources-migration
Closed

[-] fix sources handling in config upgrade#1274
0xgouda wants to merge 6 commits intomasterfrom
fix-sources-migration

Conversation

@0xgouda
Copy link
Copy Markdown
Collaborator

@0xgouda 0xgouda commented Mar 4, 2026

  • don't run migrations for sources on config upgrade

    • There aren't any migrations for sources and the pg sources reader/writer
      doesn't even implement a Migrate() method, so it's not necessary, and calling Migrate() on it will trigger a crash.
  • Update config upgrade help messages

    • They are now more clear and state which flag the user needs to specify
      for this migration to happen correctly.

    • This is especially useful for users who specify --sources without --metrics,
      then it will get used as the metrics database and on migration users will have a clue that
      they have to explicitly specify --metrics for the upgrade to happen.

Closes: #1273

@0xgouda 0xgouda requested a review from pashagolub March 4, 2026 09:55
@0xgouda 0xgouda self-assigned this Mar 4, 2026
@0xgouda 0xgouda added bug Something isn't working sources What sources and in what way to monitor labels Mar 4, 2026
@0xgouda 0xgouda force-pushed the fix-sources-migration branch from c7b3e1e to 26c8932 Compare March 4, 2026 09:56
@0xgouda 0xgouda changed the title [*] fix sources migration [-] fix sources handling in config upgrade Mar 4, 2026
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 22666439513

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • 8 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 82.056%

Files with Coverage Reduction New Missed Lines %
internal/sinks/prometheus.go 8 71.98%
Totals Coverage Status
Change from base Build 22626483866: -0.2%
Covered Lines: 4477
Relevant Lines: 5456

💛 - Coveralls

var output bytes.Buffer
opts := &Options{
Sources: sources.CmdOpts{Sources: "/tmp/sources.yaml"},
Metrics: metrics.CmdOpts{Metrics: "/tmp/sources.yaml"},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey just a heads up. After the change this test becomes a duplicate of the previous test (only metrics specified as yaml - unsupported error)

Comment thread internal/cmdopts/cmdconfig.go
Comment thread docs/reference/cli_env.md
- `upgrade`

Upgrade the configuration and/or sink database to the latest version by applying all pending migrations.
Upgrades the metrics configuration and/or sink database to the latest version by applying all pending migrations.
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.

It also update sources configuration on Postgres. Because they are stored together

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.

What if a user (for some weird reason) uses to separate dbs for sources and metrics?

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.

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.

that's a good question. never tested in real life. I assume pgwatch will take --metrics and use it as a default database while ignoring the --sources silently

Copy link
Copy Markdown
Collaborator Author

@0xgouda 0xgouda Mar 10, 2026

Choose a reason for hiding this comment

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

That's why I removed source-related docs and code.

There haven't been any migrations for sources yet, so we can only ask for --metrics and --sink, and we don't care about sources for now.

And in the future, when we wish to add source migrations (if ever), we can start thinking about how we will solve this problem.

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.

I see your point. but sources schema can be migrated. and user must know it. the fact we do storage in the same database is our problem. if you remove source upgrade mentions, user will stuck.

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 clear way may be to make sure source writer is responsible for creating it's own tables and functions.

Copy link
Copy Markdown
Collaborator Author

@0xgouda 0xgouda Mar 10, 2026

Choose a reason for hiding this comment

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

Yeah, but I mean for now they are not upgradable. Once they become so in future releases, we can update docs/code and see how to handle this problem, its not urgent/necessary now.

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.

no. docs must tell that sources schema is upgradable. it's not important that upgrade is done with metric writer. user must know that all main database schemas are upgradable: sources, metrics, sinks.

Comment thread docs/reference/cli_env.md
Upgrades the metrics configuration and/or sink database to the latest version by applying all pending migrations.
File or folder based configurations are not supported. The command will automatically detect which
databases (sources, metrics, sinks) require migrations and apply them.
databases (metrics, sinks) require migrations and apply them.
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.

It will update sources stored in Postgres.

@pashagolub
Copy link
Copy Markdown
Collaborator

  • There aren't any migrations for sources and the pg sources reader/writer
    doesn't even implement a Migrate() method

because metrics reader takes care of it because sources and metrics are stored in the same schema of the same database

0xgouda added 6 commits March 9, 2026 17:12
There isn't any migrations for sources and the pg sources reader/writer
doesn't even implement a `Migrate()` method, so its not necessary
They are now more clear and state which flag the user needs to specify
for this migration to happen correctly.

This is especially useful for users who specify `--sources` without `--metrics`,
then it will get used as the metrics database and on migration users will have a clue that
they have to explicitly specify `--metrics` for the upgrade to happen.
@0xgouda 0xgouda force-pushed the fix-sources-migration branch from 779fff1 to a35f271 Compare March 9, 2026 15:12
@0xgouda 0xgouda requested a review from pashagolub March 9, 2026 15:29
@0xgouda
Copy link
Copy Markdown
Collaborator Author

0xgouda commented Mar 10, 2026

Overtaken by: #1287

@0xgouda 0xgouda closed this Mar 10, 2026
@0xgouda 0xgouda deleted the fix-sources-migration branch March 10, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working sources What sources and in what way to monitor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem on migrating from 4.1.0 to 5.0.0

4 participants