Skip to content

Commit

Permalink
feat: add configurable request timeout (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-haley authored Jun 16, 2022
1 parent c9c839a commit 0986010
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ GLOBAL OPTIONS:
--port value Port on which to expose the Prometheus metrics. (default: "9202") [$OMADA_PORT]
--site value Omada site to scrape metrics from. (default: "Default") [$OMADA_SITE]
--interval value Interval between scrapes, in seconds. (default: 5) [$OMADA_SCRAPE_INTERVAL]
--timeout value Timeout when making requests to the Omada Controller. (default: 15) [$OMADA_REQUEST_TIMEOUT]
--insecure Whether to skip verifying the SSL certificate on the controller. (default: false) [$OMADA_INSECURE]
--disable-go-collector Disable Go collector metrics. (default: true) [$OMADA_DISABLE_GO_COLLECTOR]
--disable-process-collector Disable process collector metrics. (default: true) [$OMADA_DISABLE_PROCESS_COLLECTOR]
Expand All @@ -93,6 +94,7 @@ OMADA_SITE | Site you'd like to get metrics from. (default: "Defau
OMADA_PORT | Port on which to expose the Prometheus metrics. (default: 9202)
OMADA_INSECURE | Whether to skip verifying the SSL certificate on the controller. (default: false)
OMADA_SCRAPE_INTERVAL | Interval between scrapes, in seconds. (default: 5)
OMADA_REQUEST_TIMEOUT | Timeout when making requests to the Omada Controller. (default: 15)
OMADA_DISABLE_GO_COLLECTOR | Disable Go collector metrics. (default: true)
OMADA_DISABLE_PROCESS_COLLECTOR | Disable process collector metrics. (default: true)

Expand Down
2 changes: 2 additions & 0 deletions cmd/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
port string
site string
interval int
timeout int
insecure bool
goCollectorDisabled bool
processCollectorDisabled bool
Expand All @@ -44,6 +45,7 @@ func Run() {
&cli.StringFlag{Destination: &port, Name: "port", Value: "9202", Usage: "Port on which to expose the Prometheus metrics.", EnvVars: []string{"OMADA_PORT"}},
&cli.StringFlag{Destination: &site, Name: "site", Value: "Default", Usage: "Omada site to scrape metrics from.", EnvVars: []string{"OMADA_SITE"}},
&cli.IntFlag{Destination: &interval, Name: "interval", Value: 5, Usage: "Interval between scrapes, in seconds.", EnvVars: []string{"OMADA_SCRAPE_INTERVAL"}},
&cli.IntFlag{Destination: &timeout, Name: "timeout", Value: 15, Usage: "Timeout when making requests to the Omada Controller.", EnvVars: []string{"OMADA_REQUEST_TIMEOUT"}},
&cli.BoolFlag{Destination: &insecure, Name: "insecure", Value: false, Usage: "Whether to skip verifying the SSL certificate on the controller.", EnvVars: []string{"OMADA_INSECURE"}},
&cli.BoolFlag{Destination: &goCollectorDisabled, Name: "disable-go-collector", Value: true, Usage: "Disable Go collector metrics.", EnvVars: []string{"OMADA_DISABLE_GO_COLLECTOR"}},
&cli.BoolFlag{Destination: &processCollectorDisabled, Name: "disable-process-collector", Value: true, Usage: "Disable process collector metrics.", EnvVars: []string{"OMADA_DISABLE_PROCESS_COLLECTOR"}},
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Client struct {
SiteId string
}

func setuphttpClient(insecure bool) (*http.Client, error) {
func setuphttpClient(insecure bool, timeout int) (*http.Client, error) {
jar, err := cookiejar.New(nil)
if err != nil {
return nil, fmt.Errorf("failed to init cookiejar")
Expand All @@ -28,7 +28,7 @@ func setuphttpClient(insecure bool) (*http.Client, error) {
t.MaxConnsPerHost = 100
t.MaxIdleConnsPerHost = 100

client := &http.Client{Transport: t, Timeout: time.Duration(10) * time.Second, Jar: jar}
client := &http.Client{Transport: t, Timeout: time.Duration(timeout) * time.Second, Jar: jar}

if insecure {
t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
Expand All @@ -38,7 +38,7 @@ func setuphttpClient(insecure bool) (*http.Client, error) {
}

func Configure(c *cli.Context) (*Client, error) {
httpClient, err := setuphttpClient(c.Bool("insecure"))
httpClient, err := setuphttpClient(c.Bool("insecure"), c.Int("timeout"))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0986010

Please sign in to comment.