This repository has been archived by the owner on Aug 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
84 lines (69 loc) · 2.14 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"log"
"os"
"time"
"code.cloudfoundry.org/log-cache/internal/blackbox"
"google.golang.org/grpc"
"google.golang.org/grpc/naming"
)
func main() {
infoLogger := log.New(os.Stdout, "", log.LstdFlags|log.Lmicroseconds)
errorLogger := log.New(os.Stderr, "", log.LstdFlags|log.Lmicroseconds)
cfg, err := LoadConfig()
if err != nil {
log.Fatalf("failed to load configuration: %s", err)
}
resolver, _ := naming.NewDNSResolverWithFreq(1 * time.Minute)
ingressClient := blackbox.NewIngressClient(
cfg.DataSourceGrpcAddr,
grpc.WithTransportCredentials(cfg.TLS.Credentials("log-cache")),
grpc.WithBalancer(
grpc.RoundRobin(resolver),
),
)
go blackbox.StartEmittingTestMetrics(cfg.SourceId, cfg.EmissionInterval, ingressClient)
grpcEgressClient := blackbox.NewGrpcEgressClient(
cfg.DataSourceGrpcAddr,
grpc.WithTransportCredentials(cfg.TLS.Credentials("log-cache")),
grpc.WithBalancer(
grpc.RoundRobin(resolver),
),
)
var httpEgressClient blackbox.QueryableClient
if cfg.CfBlackboxEnabled {
httpEgressClient = blackbox.NewHttpEgressClient(
cfg.DataSourceHTTPAddr,
cfg.UaaAddr,
cfg.ClientID,
cfg.ClientSecret,
cfg.SkipTLSVerify,
)
}
t := time.NewTicker(cfg.SampleInterval)
rc := blackbox.ReliabilityCalculator{
SampleInterval: cfg.SampleInterval,
WindowInterval: cfg.WindowInterval,
WindowLag: cfg.WindowLag,
EmissionInterval: cfg.EmissionInterval,
SourceId: cfg.SourceId,
InfoLogger: infoLogger,
ErrorLogger: errorLogger,
}
for range t.C {
reliabilityMetrics := make(map[string]float64)
infoLogger.Println("Querying for gRPC reliability metric...")
grpcReliability, err := rc.Calculate(grpcEgressClient)
if err == nil {
reliabilityMetrics["blackbox.grpc_reliability"] = grpcReliability
}
if cfg.CfBlackboxEnabled {
infoLogger.Println("Querying for HTTP reliability metric...")
httpReliability, err := rc.Calculate(httpEgressClient)
if err == nil {
reliabilityMetrics["blackbox.http_reliability"] = httpReliability
}
}
blackbox.EmitMeasuredMetrics(cfg.SourceId, ingressClient, httpEgressClient, reliabilityMetrics)
}
}