-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dca29a
commit 70bd82e
Showing
14 changed files
with
234 additions
and
30 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
vendor | ||
vendor | ||
bin |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
sfTraefikWatchdog | ||
traefik-appinsights-watchdog | ||
debug | ||
bin | ||
**/debug.test |
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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
#/bin/sh | ||
docker build . -t traefik-appinsights-watchdog | ||
#/bin/bash | ||
set -e | ||
set -o pipefail | ||
|
||
./codechecks.sh | ||
|
||
echo "Building...." | ||
GOOS=windows go build -o traefik-appinsights-watchdog -o ./bin/traefik-appinsgihts-watchdog.exe | ||
GOOS=windows go build -o traefik-appinsights-watchdog -o ./bin/traefik-appinsgihts-watchdog |
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,2 @@ | ||
docker build . -t traefik-appinsights-watchdog | ||
docker run -it traefik-appinsights-watchdog |
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,3 @@ | ||
#/bin/sh | ||
docker build . -t traefik-appinsights-watchdog | ||
docker run -it -v $PWD/bin:/go/src/github.com/lawrencegripper/traefik-appinsights-watchdog/bin traefik-appinsights-watchdog bash -f build.sh |
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,150 @@ | ||
package health | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/lawrencegripper/traefik-appinsights-watchdog/types" | ||
) | ||
|
||
func TestHealthRetreiveMetrics(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(handleHealthSuceed)) | ||
defer server.Close() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
config := types.Configuration{TraefikHealthEndpoint: server.URL + "/health"} | ||
channel := make(chan types.StatsEvent) | ||
|
||
go StartCheck(ctx, config, channel) | ||
|
||
timeout := time.After(time.Second * 3) | ||
|
||
select { | ||
case statEvent := <-channel: | ||
if !statEvent.IsSuccess { | ||
t.Error("Stats event was a failure") | ||
} | ||
t.Log(statEvent) | ||
return | ||
case <-timeout: | ||
t.Error("Timeout occurred") | ||
return | ||
} | ||
} | ||
|
||
func TestHealthRetreiveMetrics_Invalid(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(handleHealthInvalid)) | ||
defer server.Close() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
config := types.Configuration{TraefikHealthEndpoint: server.URL + "/health"} | ||
channel := make(chan types.StatsEvent) | ||
|
||
go StartCheck(ctx, config, channel) | ||
|
||
timeout := time.After(time.Second * 3) | ||
|
||
select { | ||
case statEvent := <-channel: | ||
if statEvent.IsSuccess { | ||
t.Error("Stats expected to fail but suceeded") | ||
} | ||
t.Log(statEvent) | ||
return | ||
case <-timeout: | ||
t.Error("Timeout occurred") | ||
return | ||
} | ||
} | ||
|
||
func TestHealthRetreiveMetrics_Timeout(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(handleHealthTimeout)) | ||
defer server.Close() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
config := types.Configuration{TraefikHealthEndpoint: server.URL + "/health"} | ||
channel := make(chan types.StatsEvent) | ||
|
||
go StartCheck(ctx, config, channel) | ||
|
||
timeout := time.After(time.Second * 5) | ||
|
||
select { | ||
case statEvent := <-channel: | ||
if statEvent.IsSuccess { | ||
t.Error("Stats expected to fail but suceeded") | ||
} | ||
if !strings.Contains(statEvent.ErrorDetails, "net/http: request canceled (Client.Timeout exceeded while awaiting headers)") { | ||
t.Error("Expected timout error") | ||
} | ||
t.Log(statEvent) | ||
return | ||
case <-timeout: | ||
t.Error("Test timeout occurred") | ||
return | ||
} | ||
} | ||
|
||
func handleHealthSuceed(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path != "/health" { | ||
http.NotFound(w, r) | ||
return | ||
} | ||
|
||
body, err := ioutil.ReadFile("testdata/healthresponse_normal.json") | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
_, err = w.Write([]byte(err.Error())) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
_, err = w.Write(body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func handleHealthInvalid(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path != "/health" { | ||
http.NotFound(w, r) | ||
return | ||
} | ||
|
||
body, err := ioutil.ReadFile("testdata/healthresponse_invalid.json") | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
_, err = w.Write([]byte(err.Error())) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
_, err = w.Write(body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func handleHealthTimeout(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path != "/health" { | ||
http.NotFound(w, r) | ||
return | ||
} | ||
|
||
time.Sleep(time.Second * 5) | ||
} |
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 @@ | ||
jammydodgers |
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,31 @@ | ||
{ | ||
"pid": 2458, | ||
"uptime": "39m6.885931127s", | ||
"uptime_sec": 2346.885931127, | ||
"time": "2015-10-07 18:32:24.362238909 +0200 CEST", | ||
"unixtime": 1444235544, | ||
"status_code_count": { | ||
"502": 1 | ||
}, | ||
"total_status_code_count": { | ||
"200": 7, | ||
"404": 21, | ||
"502": 13 | ||
}, | ||
"count": 1, | ||
"total_count": 41, | ||
"total_response_time": "35.456865605s", | ||
"total_response_time_sec": 35.456865605, | ||
"average_response_time": "864.8016ms", | ||
"average_response_time_sec": 0.8648016000000001, | ||
"recent_errors": [ | ||
{ | ||
"status_code": 500, | ||
"status": "Internal Server Error", | ||
"method": "GET", | ||
"host": "localhost", | ||
"path": "/path", | ||
"time": "2016-10-21T16:59:15.418495872-07:00" | ||
} | ||
] | ||
} |
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