Skip to content

Commit

Permalink
Merge pull request #61 from cgreen12/master
Browse files Browse the repository at this point in the history
Optionally test DNS resolution for each pod
  • Loading branch information
seeker89 authored Sep 6, 2019
2 parents 096b149 + 8a014ad commit 5828594
Show file tree
Hide file tree
Showing 18 changed files with 406 additions and 44 deletions.
6 changes: 4 additions & 2 deletions pkg/client/operations/check_service_pods_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 39 additions & 4 deletions pkg/goldpinger/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package goldpinger

import (
"fmt"
"net"
"sync"
"time"

Expand All @@ -27,7 +28,7 @@ import (

// CheckNeighbours queries the kubernetes API server for all other goldpinger pods
// then calls Ping() on each one
func CheckNeighbours(ps *PodSelecter) models.CheckResults {
func CheckNeighbours(ps *PodSelecter) *models.CheckResults {
return PingAllPods(ps.SelectPods())
}

Expand All @@ -50,7 +51,25 @@ func pickPodHostIP(podIP, hostIP string) string {
return podIP
}

func PingAllPods(pods map[string]string) models.CheckResults {
func checkDNS() *models.DNSResults {
results := models.DNSResults{}
for _, host := range GoldpingerConfig.DnsHosts{

var dnsResult models.DNSResult

start := time.Now()
_, err := net.LookupIP(host)
if err != nil {
dnsResult.Error = err.Error()
CountDnsError(host)
}
dnsResult.ResponseTimeMs = time.Since(start).Nanoseconds() / int64(time.Millisecond)
results[host] = dnsResult
}
return &results
}

func PingAllPods(pods map[string]string) *models.CheckResults {

result := models.CheckResults{}

Expand Down Expand Up @@ -84,11 +103,15 @@ func PingAllPods(pods map[string]string) models.CheckResults {
wg.Done()
}(podIP, hostIP)
}
if len(GoldpingerConfig.DnsHosts) > 0 {
result.DNSResults = *checkDNS()
}
wg.Wait()
close(ch)

counterHealthy, counterUnhealthy := 0.0, 0.0

result.PodResults = make(map[string]models.PodResult)
for response := range ch {
var podIPv4 strfmt.IPv4
podIPv4.UnmarshalText([]byte(response.podIP))
Expand All @@ -97,10 +120,10 @@ func PingAllPods(pods map[string]string) models.CheckResults {
} else {
counterUnhealthy++
}
result[response.podIP] = response.podResult
result.PodResults[response.podIP] = response.podResult
}
CountHealthyUnhealthyNodes(counterHealthy, counterUnhealthy)
return result
return &result
}

type CheckServicePodsResult struct {
Expand Down Expand Up @@ -161,6 +184,18 @@ func CheckAllPods(pods map[string]string) *models.CheckAllResults {
HostIP: response.hostIPv4,
PodIP: podIPv4,
})
if response.checkAllPodResult.Response != nil &&
response.checkAllPodResult.Response.DNSResults != nil {
if result.DNSResults == nil {
result.DNSResults = make(map[string]models.DNSResults)
}
for host := range response.checkAllPodResult.Response.DNSResults {
if result.DNSResults[host] == nil {
result.DNSResults[host] = make(map[string]models.DNSResult)
}
result.DNSResults[host][response.podIP] = response.checkAllPodResult.Response.DNSResults[host]
}
}
}
return &result
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/goldpinger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ var GoldpingerConfig = struct {
LabelSelector string `long:"label-selector" description:"label selector to use to discover goldpinger pods in the cluster" env:"LABEL_SELECTOR" default:"app=goldpinger"`
KubernetesClient *kubernetes.Clientset
*PodSelecter

DnsHosts []string `long:"host-to-resolve" description:"A host to attempt dns resolve on" env:"HOSTS_TO_RESOLVE" env-delim:" "`
}{}
2 changes: 1 addition & 1 deletion pkg/goldpinger/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func HeatmapHandler(w http.ResponseWriter, r *http.Request) {
// draw all the boxes
for sourceIP, results := range checkResults.Responses {
if *results.OK {
for destinationIP, response := range results.Response {
for destinationIP, response := range results.Response.PodResults {
x, y := getPingBoxCoordinates(order[sourceIP], order[destinationIP], boxSize, paddingSize)
color := getPingBoxColor(response.ResponseTimeMs, tresholdLatencies)
drawPingBox(canvas, boxSize+x, boxSize+y, boxSize, color)
Expand Down
19 changes: 19 additions & 0 deletions pkg/goldpinger/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ var (
"type",
},
)
goldpingerDnsErrorsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "goldpinger_dns_errors_total",
Help: "Statistics of DNS errors per instance",
},
[]string{
"goldpinger_instance",
"host",
},
)

bootTime = time.Now()
)
Expand All @@ -92,6 +102,7 @@ func init() {
prometheus.MustRegister(goldpingerResponseTimePeersHistogram)
prometheus.MustRegister(goldpingerResponseTimeKubernetesHistogram)
prometheus.MustRegister(goldpingerErrorsCounter)
prometheus.MustRegister(goldpingerDnsErrorsCounter)
log.Println("Metrics setup - see /metrics")
}

Expand Down Expand Up @@ -131,6 +142,14 @@ func CountError(errorType string) {
).Inc()
}

// counts instances of dns errors
func CountDnsError(host string) {
goldpingerDnsErrorsCounter.WithLabelValues(
GoldpingerConfig.Hostname,
host,
).Inc()
}

// returns a timer for easy observing of the durations of calls to kubernetes API
func GetLabeledKubernetesCallsTimer() *prometheus.Timer {
return prometheus.NewTimer(
Expand Down
2 changes: 1 addition & 1 deletion pkg/goldpinger/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func StartUpdater() {
for {
results := PingAllPods(GoldpingerConfig.PodSelecter.SelectPods())
var troublemakers []string
for podIP, value := range results {
for podIP, value := range results.PodResults {
if *value.OK != true {
troublemakers = append(troublemakers, fmt.Sprintf("%s (%s)", podIP, value.HostIP.String()))
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/models/check_all_pod_result.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions pkg/models/check_all_results.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 66 additions & 7 deletions pkg/models/check_results.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions pkg/models/dns_result.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5828594

Please sign in to comment.