-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(zfs): Allow testing collector output
TODO: Test caching
- Loading branch information
Showing
16 changed files
with
1,102 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ jobs: | |
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- name: Go Report Card | ||
uses: creekorful/[email protected] | ||
|
||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- name: Checkout | ||
id: checkout | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package collector | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"time" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/pdf/zfs_exporter/zfs" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
) | ||
|
||
var ( | ||
logger = log.NewNopLogger() | ||
//logger = log.NewLogfmtLogger(os.Stderr) | ||
) | ||
|
||
func callCollector(ctx context.Context, collector prometheus.Collector, metricResults []byte, metricNames []string) error { | ||
result := make(chan error) | ||
go func() { | ||
result <- testutil.CollectAndCompare(collector, bytes.NewBuffer(metricResults), metricNames...) | ||
}() | ||
|
||
select { | ||
case err := <-result: | ||
return err | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
} | ||
} | ||
|
||
func defaultConfig(z zfs.Client) (ZFSConfig, error) { | ||
duration, err := time.ParseDuration(`5m`) | ||
if err != nil { | ||
return ZFSConfig{}, err | ||
} | ||
return ZFSConfig{ | ||
DisableMetrics: true, | ||
Deadline: duration, | ||
Logger: logger, | ||
ZFSClient: z, | ||
}, nil | ||
} | ||
|
||
func stringPointer(s string) *string { | ||
return &s | ||
} | ||
|
||
func boolPointer(b bool) *bool { | ||
return &b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.