Skip to content

fix: dont panic when schema_config does not exist in the config file #16702

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

abacef
Copy link

@abacef abacef commented Mar 12, 2025

What this PR does / why we need it:
initial startup should not panic

Which issue(s) this PR fixes:
Fixes #16698

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR
@abacef abacef requested a review from a team as a code owner March 12, 2025 01:07
@CLAassistant
Copy link

CLAassistant commented Mar 12, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

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

I'm confused how is Loki going to work without a schema config? Would you mind sharing the config you're running and how you are storing the data?

@abacef
Copy link
Author

abacef commented Mar 12, 2025

The thing I wanted to change it to know why the config is wrong. With this change, the binary outputs this, which helps me debut faster

level=error ts=2025-03-12T18:54:23.284905392Z caller=main.go:70 msg="validating config" err="CONFIG ERROR: invalid schema config: must specify at least one schema configuration"
@chaudum
Copy link
Contributor

chaudum commented Mar 13, 2025

I see what the problem is: There's is a panic in the config validation, because it accesses properties of the schema_config even if it is not present. This is definitely a bug and not expected behaviour.

@trevorwhitney Loki still will not start up without a schema_config, because the validation would fail. However it would terminate gracefully.

Comment on lines +26 to +28
if len(c.SchemaConfig.Configs) == 0 {
return []error{}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a comment mentioning that the length of c.SchemaConfig.Configs is already validated in the Validate() function of the SchemaConfig itself.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I added the comment

Copy link
Collaborator

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

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

I understand now, lgtm

@abacef
Copy link
Author

abacef commented Apr 8, 2025

Apparently I need to lint this code before the lint check can pass. I tried running make format with a new clone of this branch but it does not seem to change any files. Do I have to do any setup to run the linter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 participants