-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprobe.go
68 lines (55 loc) · 1.72 KB
/
probe.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
package main
import (
"fmt"
"net/http"
"go.uber.org/zap"
"github.com/webdevops/azure-loganalytics-exporter/loganalytics"
)
func handleProbePanic(w http.ResponseWriter, r *http.Request) {
if err := recover(); err != nil {
switch v := err.(type) {
case loganalytics.LogAnalyticsPanicStop:
// log entry already sent
msg := fmt.Sprintf("ERROR: %v", v.Message)
http.Error(w, msg, http.StatusBadRequest)
case error:
logger.Error(err)
http.Error(w, v.Error(), http.StatusBadRequest)
default:
msg := fmt.Sprintf("%v", err)
logger.With(zap.String("request", r.RequestURI)).Errorf(msg)
http.Error(w, msg, http.StatusBadRequest)
}
}
}
func handleProbeRequest(w http.ResponseWriter, r *http.Request) {
defer handleProbePanic(w, r)
prober := NewLogAnalyticsProber(w, r)
prober.AddWorkspaces(Opts.Loganalytics.Workspace...)
prober.Run()
}
func handleProbeWorkspace(w http.ResponseWriter, r *http.Request) {
defer handleProbePanic(w, r)
workspaceList, err := loganalytics.ParamsGetListRequired(r.URL.Query(), "workspace")
if err != nil {
panic("no workspaces defined")
}
prober := NewLogAnalyticsProber(w, r)
prober.AddWorkspaces(workspaceList...)
prober.Run()
}
func handleProbeSubscriptionRequest(w http.ResponseWriter, r *http.Request) {
defer handleProbePanic(w, r)
prober := NewLogAnalyticsProber(w, r)
prober.ServiceDiscovery.Use()
prober.Run()
}
func NewLogAnalyticsProber(w http.ResponseWriter, r *http.Request) *loganalytics.LogAnalyticsProber {
prober := loganalytics.NewLogAnalyticsProber(logger, w, r, &concurrentWaitGroup)
prober.QueryConfig = Config
prober.Conf = Opts
prober.UserAgent = UserAgent + gitTag
prober.SetAzureClient(AzureClient)
prober.EnableCache(metricCache)
return prober
}