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

Add options for History and Wanted/Missing queries skip, remove sort on Wanted/Missing #299

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

Conversation

codefaux
Copy link

@codefaux codefaux commented May 9, 2024

Description of the change

  • Add options for History and Wanted/Missing queries skip, remove sort on Wanted/Missing

Benefits

  • Faster metrics collection for users not desiring History/Wanted/Missing
  • Stall mitigation re: users with large collections or long-lived instances

Possible drawbacks

  • I don't know Golang or koanf and did not look up reference for either, but I believe I have treated both appropriately.

Applicable issues

Additional information

  • Thanks for your work.

@codefaux codefaux requested a review from onedr0p as a code owner May 9, 2024 00:52
Comment on lines 26 to 27
flags.Bool("skip-history", false, "Skip History metrics query")
flags.Bool("skip-missing", false, "Skip Wanted/Missing metrics query")
Copy link
Owner

Choose a reason for hiding this comment

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

Tabs

Copy link
Author

Choose a reason for hiding this comment

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

I've never used go and I'm a "spaces not tabs" person so I was unaware of the standard or that I had done it differently than yours. I ran it through gofmt, given that's the official tool I'd imagine that's your expectation. Let me know if it needs anything else.

Copy link
Owner

Choose a reason for hiding this comment

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

I am also a spaces person as well, but Go has some opinions on formatting that I like to follow.

Copy link
Author

Choose a reason for hiding this comment

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

Wholeheartedly agree -- if the language has a suggested standard, use it.

@onedr0p
Copy link
Owner

onedr0p commented May 9, 2024

Changes appear good here, but I wonder if it could be added to the logic --enable-additional-metrics flag instead of creating separate config flags / env options? I am not sure if there is a use-case for why you would want --enable-additional-metrics on but turn off the history & wanted/missing flags? The --enable-additional-metrics flag was mainly created for those with large libraries that need to turn off the slower API calls.

Also @rtrox would be great if/when you are free to review to get a pair of second eyes on this.

@rtrox
Copy link
Collaborator

rtrox commented Aug 9, 2024

Thanks for the PR @codefaux! Sorry about the delayed review here, been dealing with some issues in RL. A few comments, but overall looks good!

"error", err)
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
return
if collector.config.EnableAdditionalMetrics {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given we're blocking the whole collector, can we instead put this in the Commands file, and just not register the collector?

var radarrCmd = &cobra.Command{
Use: "radarr",
Aliases: []string{"r"},
Short: "Prometheus Exporter for Radarr",
Long: "Prometheus Exporter for Radarr.",
RunE: func(cmd *cobra.Command, args []string) error {
c, err := config.LoadArrConfig(*conf, cmd.PersistentFlags())
if err != nil {
return err
}
c.ApiVersion = "v3"
UsageOnError(cmd, c.Validate())
serveHttp(func(r prometheus.Registerer) {
r.MustRegister(
collector.NewRadarrCollector(c),
collector.NewQueueCollector(c),
collector.NewHistoryCollector(c),
collector.NewRootFolderCollector(c),
collector.NewSystemStatusCollector(c),
collector.NewSystemHealthCollector(c),
)
})
return nil

The same config is available there as c, so you can just check c.EnableAdditionalMetrics.

@@ -197,21 +197,21 @@ func (collector *lidarrCollector) Collect(ch chan<- prometheus.Metric) {
albumGenres[genre]++
}
}
albumsMissing := model.Missing{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

For Radarr & Readarr, we divine this metric instead of sending a separate call for it:

var radarrCmd = &cobra.Command{
Use: "radarr",
Aliases: []string{"r"},
Short: "Prometheus Exporter for Radarr",
Long: "Prometheus Exporter for Radarr.",
RunE: func(cmd *cobra.Command, args []string) error {
c, err := config.LoadArrConfig(*conf, cmd.PersistentFlags())
if err != nil {
return err
}
c.ApiVersion = "v3"
UsageOnError(cmd, c.Validate())
serveHttp(func(r prometheus.Registerer) {
r.MustRegister(
collector.NewRadarrCollector(c),
collector.NewQueueCollector(c),
collector.NewHistoryCollector(c),
collector.NewRootFolderCollector(c),
collector.NewSystemStatusCollector(c),
collector.NewSystemHealthCollector(c),
)
})
return nil

I wonder if we should do something similar for Lidarr & Sonarr, instead of just turning it off. @codefaux - if you're up for taking a stab that, that would be great. Otherwise, I'm happy with us putting this behind a flag for now, and I can create a ticket to add it back by mathing it.

"error", err)
ch <- prometheus.NewInvalidMetric(collector.errorMetric, err)
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor nit: can we leave the metric emission immediately below where it's collected, like we did before? So move line 285 here.

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.

3 participants