amimof / node-cert-exporter

An SSL certificate Prometheus exporter
Apache License 2.0
173 stars 36 forks source link

Do not search in --exclude-path #52

Closed r2ronoha closed 3 years ago

r2ronoha commented 4 years ago

Description Currently the exporter walks through all the contents of the path(s) provided, and then skips all paths under the --exclude-path.

func (e *Exporter) Scrape(ch chan<- prometheus.Metric) {
    for _, root := range e.roots {
        exPaths := e.exRoots
        paths := []string{}
        err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
            for _, exPath := range exPaths {
                if strings.Contains(filepath.Dir(path), exPath) || path == exPath {
                    return nil
                }
            }

This causes an issue in cases where the number of subfolders/files under the path is very high (i.e. k3s clusters under/var/lib/rancher/k3s/agent, which contains containerd folder). In that case the exporter just hangs, without any error, and the metrics are not reported.

It would be great if it skipped them from the search in the first place.

amimof commented 4 years ago

That’s a good point. Thanks for reporting. Have a look at #51. It changes how certs are read a bit. Can you perhaps test that branch in your environment? That would be awesome. Let me know if you need help building the binary or container image.

amimof commented 3 years ago

51 is merged and you can now use --exclude-glob and --include-glob cmd arguments instead of --path