Sort scrapers by name (#3691)

This commit is contained in:
Flashy78 2023-05-02 20:34:57 -07:00 committed by GitHub
parent d6b4d16ff4
commit 1606f1b17e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 4 deletions

View File

@ -150,7 +150,6 @@ func (c *Cache) loadScrapers() (map[string]scraper, error) {
logger.Debugf("Reading scraper configs from %s", path) logger.Debugf("Reading scraper configs from %s", path)
scraperFiles := []string{}
err := fsutil.SymWalk(path, func(fp string, f os.FileInfo, err error) error { err := fsutil.SymWalk(path, func(fp string, f os.FileInfo, err error) error {
if filepath.Ext(fp) == ".yml" { if filepath.Ext(fp) == ".yml" {
conf, err := loadConfigFromYAMLFile(fp) conf, err := loadConfigFromYAMLFile(fp)
@ -160,7 +159,6 @@ func (c *Cache) loadScrapers() (map[string]scraper, error) {
scraper := newGroupScraper(*conf, c.globalConfig) scraper := newGroupScraper(*conf, c.globalConfig)
scrapers[scraper.spec().ID] = scraper scrapers[scraper.spec().ID] = scraper
} }
scraperFiles = append(scraperFiles, fp)
} }
return nil return nil
}) })
@ -187,7 +185,7 @@ func (c *Cache) ReloadScrapers() error {
} }
// ListScrapers lists scrapers matching one of the given types. // ListScrapers lists scrapers matching one of the given types.
// Returns a list of scrapers, sorted by their ID. // Returns a list of scrapers, sorted by their name.
func (c Cache) ListScrapers(tys []ScrapeContentType) []*Scraper { func (c Cache) ListScrapers(tys []ScrapeContentType) []*Scraper {
var ret []*Scraper var ret []*Scraper
for _, s := range c.scrapers { for _, s := range c.scrapers {
@ -201,7 +199,7 @@ func (c Cache) ListScrapers(tys []ScrapeContentType) []*Scraper {
} }
sort.Slice(ret, func(i, j int) bool { sort.Slice(ret, func(i, j int) bool {
return ret[i].ID < ret[j].ID return strings.ToLower(ret[i].Name) < strings.ToLower(ret[j].Name)
}) })
return ret return ret