Skip to content
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

Prometheus config fallbacks #115

Merged
merged 13 commits into from
Jan 20, 2025
Merged

Prometheus config fallbacks #115

merged 13 commits into from
Jan 20, 2025

Conversation

jrauh01
Copy link
Collaborator

@jrauh01 jrauh01 commented Aug 21, 2024

Add more options to set Prometheus config:

  1. Read from config table in the database
  2. Auto detect Prometheus server service

@jrauh01 jrauh01 requested a review from lippserd August 21, 2024 09:01
@jrauh01 jrauh01 self-assigned this Aug 21, 2024
@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Aug 21, 2024
@jrauh01 jrauh01 force-pushed the prometheus-config branch from a2ae88f to 768e5c9 Compare August 21, 2024 13:08
pkg/metrics/config.go Show resolved Hide resolved
internal/basic_auth.go Outdated Show resolved Hide resolved
schema/mysql/schema.sql Outdated Show resolved Hide resolved
pkg/metrics/config.go Outdated Show resolved Hide resolved
pkg/metrics/config.go Outdated Show resolved Hide resolved
}

stmt, _ := db.BuildUpsertStmt(&schemav1.Config{})
if _, err := db.NamedExecContext(ctx, stmt, configPairs); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Do the INSERTs/UPDATEs in a serializable transaction. Think about why this is a good idea and whether the other side should do that too. See here for how we do it in Icinga DB: https://github.com/Icinga/icingadb/blob/main/pkg/icingadb/ha.go#L289.

As this is a pattern that we are now using a second time, you should consider how this could be done using a function.

@lippserd lippserd added this to the 0.3.0 milestone Aug 25, 2024
@lippserd lippserd force-pushed the notifications-integration branch 2 times, most recently from e4223a9 to e9917b7 Compare November 19, 2024 08:14
@jrauh01 jrauh01 requested a review from lippserd November 19, 2024 12:20
Base automatically changed from notifications-integration to main November 19, 2024 12:26
Copy link
Member

@lippserd lippserd left a comment

Choose a reason for hiding this comment

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

Please resolve conflicts 😆

@jrauh01 jrauh01 requested a review from lippserd November 19, 2024 13:12
@jrauh01 jrauh01 force-pushed the prometheus-config branch 3 times, most recently from 5310012 to 308520c Compare December 18, 2024 14:19
}

if ip == "" {

Copy link
Member

Choose a reason for hiding this comment

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

I think you forgot something here.

schema/mysql/schema.sql Show resolved Hide resolved
}

// Validate checks constraints in the supplied Prometheus configuration and returns an error if they are violated.
func (c *PrometheusConfig) Validate() error {
if c.Url == "" && (c.Username != "" || c.Password != "") {
return errors.New("credentials cannot be provided without a URL")
Copy link
Member

Choose a reason for hiding this comment

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

I would relax this. If no URL is specified, the feature is disabled. I don't think we should require all other configurations to be removed as well.

@jrauh01 jrauh01 requested a review from lippserd January 14, 2025 09:27
}

// Validate checks constraints in the supplied Prometheus configuration and returns an error if they are violated.
func (c *PrometheusConfig) Validate() error {
if (c.Username == "") != (c.Password == "") {
return errors.New("both username and password must be provided")
}
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Please add a newline before return.

}

// Validate checks constraints in the supplied Prometheus configuration and returns an error if they are violated.
func (c *PrometheusConfig) Validate() error {
if (c.Username == "") != (c.Password == "") {
Copy link
Member

Choose a reason for hiding this comment

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

notifications.Config only validates configuration if url is set, i,e. if c.Url != "" .... We could do the same here so that validation works the same for both.

@jrauh01 jrauh01 requested a review from lippserd January 15, 2025 09:45
Copy link
Member

@lippserd lippserd left a comment

Choose a reason for hiding this comment

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

Please rebase.

@jrauh01 jrauh01 requested a review from lippserd January 17, 2025 06:39
@lippserd lippserd merged commit c4cd6d4 into main Jan 20, 2025
7 checks passed
@lippserd lippserd deleted the prometheus-config branch January 20, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants