Skip to content

Commit

Permalink
Merge pull request #30 from dreamblack86/master
Browse files Browse the repository at this point in the history
Offers the possibility to use an internal proxy.
  • Loading branch information
mr-karan authored Jul 8, 2021
2 parents 45ea348 + eb3a2fb commit 10c0996
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions config.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ max_size = 4000
[app.http_client]
max_idle_conns = 100
request_timeout = 8000
proxy_url = "http://internal-squid-proxy.com:3128"

[app.chat.alertManagerTestRoom]
notification_url = "https://chat.googleapis.com/v1/spaces/xxx/messages?key=abc-xyz&token=token-unique-key%3D"
Expand Down
1 change: 1 addition & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data:
[app.http_client]
max_idle_conns = {{ .Values.configmap.app.http_client.max_idle_conns }}
request_timeout = {{ .Values.configmap.app.http_client.request_timeout }}
proxy_url = {{ .Values.configmap.app.http_client.proxy_url | quote }}
{{- with .Values.configmap.rooms }}
{{ tpl . $ | indent 4 }}
Expand Down
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ configmap:
http_client:
max_idle_conns: "100"
request_timeout: "8000"
proxy_url: "http://internal-squid-proxy.com:3128"
rooms: |
[app.chat.alertManagerTestRoom]
Expand Down
1 change: 1 addition & 0 deletions kustomize/overlays/prod/raw/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ template_file = "message.tmpl"
[app.http_client]
max_idle_conns = 100
request_timeout = 8000
proxy_url = "http://internal-squid-proxy.com:3128"

[app.chat.alertManagerTestRoom]
notification_url = "https://chat.googleapis.com/v1/spaces/xxx/messages?key=abc-xyz&token=token-unique-key%3D"
Expand Down
28 changes: 23 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"time"

Expand Down Expand Up @@ -72,6 +73,7 @@ func initConfig() {
viper.SetDefault("server.read_timeout", 1000)
viper.SetDefault("server.write_timeout", 5000)
viper.SetDefault("server.keepalive_timeout", 30000)
viper.SetDefault("app.http_client.proxy_url", "")
viper.SetDefault("app.max_size", 4000)
// Process flags.
flagSet.Parse(os.Args[1:])
Expand All @@ -94,13 +96,29 @@ func initConfig() {
}

func initClient() *http.Client {

transport := &http.Transport{
MaxIdleConnsPerHost: viper.GetInt("app.http_client.max_idle_conns"),
ResponseHeaderTimeout: time.Duration(viper.GetDuration("app.http_client.request_timeout") * time.Millisecond),
}

proxyURLString := viper.GetString("app.http_client.proxy_url")

if proxyURLString != "" {

proxyURL, err := url.Parse(proxyURLString)
if err != nil {
errLog.Fatalf("Unable to parse `proxy_url`: %s", err)
}

transport.Proxy = http.ProxyURL(proxyURL)
}

// Generic HTTP handler for communicating with the Chat webhook endpoint.
return &http.Client{
Timeout: time.Duration(viper.GetDuration("app.http_client.request_timeout") * time.Millisecond),
Transport: &http.Transport{
MaxIdleConnsPerHost: viper.GetInt("app.http_client.max_idle_conns"),
ResponseHeaderTimeout: time.Duration(viper.GetDuration("app.http_client.request_timeout") * time.Millisecond),
}}
Timeout: time.Duration(viper.GetDuration("app.http_client.request_timeout") * time.Millisecond),
Transport: transport}

}

// prog initialisation.
Expand Down

0 comments on commit 10c0996

Please sign in to comment.