Skip to content

Commit 062e7fa

Browse files
authored
cmd/bosun: don't quit bosun when annotations can't be used
1 parent d3bfdea commit 062e7fa

File tree

8 files changed

+576
-514
lines changed

8 files changed

+576
-514
lines changed

cmd/bosun/web/chart.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,23 @@ func Graph(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interf
182182
return nil, nil
183183
}
184184
var a []annotate.Annotation
185+
warnings := []string{}
185186
if schedule.SystemConf.AnnotateEnabled() {
186187
a, err = annotateBackend.GetAnnotations(&startT, &endT)
187188
if err != nil {
188-
return nil, err
189+
warnings = append(warnings, fmt.Sprintf("unable to get annotations: %v", err))
189190
}
190191
}
191192
return struct {
192193
Queries []string
193194
Series []*chartSeries
194195
Annotations []annotate.Annotation
196+
Warnings []string
195197
}{
196198
queries,
197199
cs,
198200
a,
201+
warnings,
199202
}, nil
200203
}
201204

cmd/bosun/web/static.go

Lines changed: 443 additions & 440 deletions
Large diffs are not rendered by default.

cmd/bosun/web/static/js/annotation.ts

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
interface IAnnotationScope extends ng.IScope {
1+
interface IAnnotationScope extends IBosunScope {
22
id: string;
33
annotation: Annotation;
44
error: string;
@@ -11,7 +11,7 @@ interface IAnnotationScope extends ng.IScope {
1111
deleteSuccess: boolean;
1212
}
1313

14-
bosunControllers.controller('AnnotationCtrl', ['$scope', '$http', '$location', '$route', function($scope: IAnnotationScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) {
14+
bosunControllers.controller('AnnotationCtrl', ['$scope', '$http', '$location', '$route', function ($scope: IAnnotationScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) {
1515
var search = $location.search();
1616
$scope.id = search.id;
1717
if ($scope.id && $scope.id != "") {
@@ -40,28 +40,40 @@ bosunControllers.controller('AnnotationCtrl', ['$scope', '$http', '$location', '
4040
$scope.hosts = data;
4141
});
4242

43-
$scope.submitAnnotation = () => $http.post('/api/annotation', $scope.annotation)
44-
.success((data) => {
45-
$scope.annotation = new Annotation(data, true);
46-
$scope.error = "";
47-
$scope.submitSuccess = true;
48-
$scope.deleteSuccess = false;
49-
})
50-
.error((error) => {
51-
$scope.error = error;
52-
$scope.submitSuccess = false;
53-
});
43+
$scope.submitAnnotation = () => {
44+
$scope.animate();
45+
$http.post('/api/annotation', $scope.annotation)
46+
.success((data) => {
47+
$scope.annotation = new Annotation(data, true);
48+
$scope.error = "";
49+
$scope.submitSuccess = true;
50+
$scope.deleteSuccess = false;
51+
})
52+
.error((error) => {
53+
$scope.error = "failed to create annotation: " + error.error;
54+
$scope.submitSuccess = false;
55+
})
56+
.finally(() => {
57+
$scope.stop();
58+
});
59+
};
5460

55-
$scope.deleteAnnotation = () => $http.delete('/api/annotation/' + $scope.annotation.Id)
56-
.success((data) => {
57-
$scope.error = "";
58-
$scope.deleteSuccess = true;
59-
$scope.submitSuccess = false;
60-
$scope.annotation = new (Annotation);
61-
$scope.annotation.setTimeUTC();
62-
})
63-
.error((error) => {
64-
$scope.error = "failed to delete annotation with id: " + $scope.annotation.Id + ", error: " + error;
65-
$scope.deleteSuccess = false;
66-
});
61+
$scope.deleteAnnotation = () => {
62+
$scope.animate();
63+
$http.delete('/api/annotation/' + $scope.annotation.Id)
64+
.success((data) => {
65+
$scope.error = "";
66+
$scope.deleteSuccess = true;
67+
$scope.submitSuccess = false;
68+
$scope.annotation = new (Annotation);
69+
$scope.annotation.setTimeUTC();
70+
})
71+
.error((error) => {
72+
$scope.error = "failed to delete annotation with id: " + $scope.annotation.Id + ", error: " + error.error;
73+
$scope.deleteSuccess = false;
74+
})
75+
.finally(() => {
76+
$scope.stop();
77+
});
78+
}
6779
}]);

cmd/bosun/web/static/js/bosun.js

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -482,29 +482,41 @@ bosunControllers.controller('AnnotationCtrl', ['$scope', '$http', '$location', '
482482
.success(function (data) {
483483
$scope.hosts = data;
484484
});
485-
$scope.submitAnnotation = function () { return $http.post('/api/annotation', $scope.annotation)
486-
.success(function (data) {
487-
$scope.annotation = new Annotation(data, true);
488-
$scope.error = "";
489-
$scope.submitSuccess = true;
490-
$scope.deleteSuccess = false;
491-
})
492-
.error(function (error) {
493-
$scope.error = error;
494-
$scope.submitSuccess = false;
495-
}); };
496-
$scope.deleteAnnotation = function () { return $http.delete('/api/annotation/' + $scope.annotation.Id)
497-
.success(function (data) {
498-
$scope.error = "";
499-
$scope.deleteSuccess = true;
500-
$scope.submitSuccess = false;
501-
$scope.annotation = new (Annotation);
502-
$scope.annotation.setTimeUTC();
503-
})
504-
.error(function (error) {
505-
$scope.error = "failed to delete annotation with id: " + $scope.annotation.Id + ", error: " + error;
506-
$scope.deleteSuccess = false;
507-
}); };
485+
$scope.submitAnnotation = function () {
486+
$scope.animate();
487+
$http.post('/api/annotation', $scope.annotation)
488+
.success(function (data) {
489+
$scope.annotation = new Annotation(data, true);
490+
$scope.error = "";
491+
$scope.submitSuccess = true;
492+
$scope.deleteSuccess = false;
493+
})
494+
.error(function (error) {
495+
$scope.error = "failed to create annotation: " + error.error;
496+
$scope.submitSuccess = false;
497+
})
498+
.finally(function () {
499+
$scope.stop();
500+
});
501+
};
502+
$scope.deleteAnnotation = function () {
503+
$scope.animate();
504+
$http.delete('/api/annotation/' + $scope.annotation.Id)
505+
.success(function (data) {
506+
$scope.error = "";
507+
$scope.deleteSuccess = true;
508+
$scope.submitSuccess = false;
509+
$scope.annotation = new (Annotation);
510+
$scope.annotation.setTimeUTC();
511+
})
512+
.error(function (error) {
513+
$scope.error = "failed to delete annotation with id: " + $scope.annotation.Id + ", error: " + error.error;
514+
$scope.deleteSuccess = false;
515+
})
516+
.finally(function () {
517+
$scope.stop();
518+
});
519+
};
508520
}]);
509521
bosunControllers.controller('ConfigCtrl', ['$scope', '$http', '$location', '$route', '$timeout', '$sce', function ($scope, $http, $location, $route, $timeout, $sce) {
510522
var search = $location.search();
@@ -2626,11 +2638,12 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
26262638
if ($scope.annotateEnabled) {
26272639
$scope.annotations = _.sortBy(data.Annotations, function (d) { return d.StartDate; });
26282640
}
2641+
$scope.warning = '';
26292642
if (!$scope.result) {
26302643
$scope.warning = 'No Results';
26312644
}
2632-
else {
2633-
$scope.warning = '';
2645+
if (data.Warnings.length > 0) {
2646+
$scope.warning += data.Warnings.join(" ");
26342647
}
26352648
$scope.queries = data.Queries;
26362649
$scope.exprText = "";

cmd/bosun/web/static/js/graph.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,14 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
561561
if ($scope.annotateEnabled) {
562562
$scope.annotations = _.sortBy(data.Annotations, (d: Annotation) => { return d.StartDate; });
563563
}
564+
$scope.warning = '';
564565
if (!$scope.result) {
565566
$scope.warning = 'No Results';
566-
} else {
567-
$scope.warning = '';
568567
}
569-
$scope.queries = data.Queries;
568+
if (data.Warnings.length > 0) {
569+
$scope.warning += data.Warnings.join(" ");
570+
}
571+
$scope.queries = data.Queries;
570572
$scope.exprText = "";
571573
_.each($scope.queries, (q, i) => {
572574
$scope.exprText += "$" + alphabet[i] + " = " + q + "\n";

cmd/bosun/web/web.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,24 @@ func Listen(listenAddr string, devMode bool, tsdbHost string, reloadFunc func()
143143

144144
// Annotations
145145
if schedule.SystemConf.AnnotateEnabled() {
146-
var err error
147146
index := schedule.SystemConf.GetAnnotateIndex()
148147
if index == "" {
149148
index = "annotate"
150149
}
151-
annotateBackend, err = backend.NewElastic(schedule.SystemConf.GetAnnotateElasticHosts(), index)
152-
if err != nil {
153-
return err
154-
}
155-
if err := annotateBackend.InitBackend(); err != nil {
156-
return err
157-
}
150+
annotateBackend = backend.NewElastic(schedule.SystemConf.GetAnnotateElasticHosts(), index)
151+
152+
go func() {
153+
for {
154+
err := annotateBackend.InitBackend()
155+
if err == nil {
156+
return
157+
}
158+
slog.Warningf("could not initalize annotate backend, will try again: %v", err)
159+
time.Sleep(time.Second * 30)
160+
}
161+
}()
158162
web.AddRoutes(router, "/api", []backend.Backend{annotateBackend}, false, false)
163+
159164
}
160165

161166
router.HandleFunc("/api/version", Version)

vendor/github.com/bosun-monitor/annotate/backend/backend.go

Lines changed: 30 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/vendor.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,20 @@
267267
{
268268
"origin": "bosun.org/vendor/github.com/bosun-monitor/annotate",
269269
"path": "github.com/bosun-monitor/annotate",
270-
"revision": "68b0a4165b545e37b87b3b4b8baca55156ac9119",
271-
"revisionTime": "2016-04-29T11:34:44-04:00"
270+
"revision": "fa0f15c651bfe666cd287c2ba760436b41c85cf4",
271+
"revisionTime": "2016-08-04T13:41:31-04:00"
272272
},
273273
{
274274
"origin": "bosun.org/vendor/github.com/bosun-monitor/annotate/backend",
275275
"path": "github.com/bosun-monitor/annotate/backend",
276-
"revision": "68b0a4165b545e37b87b3b4b8baca55156ac9119",
277-
"revisionTime": "2016-04-29T11:34:44-04:00"
276+
"revision": "fa0f15c651bfe666cd287c2ba760436b41c85cf4",
277+
"revisionTime": "2016-08-04T13:41:31-04:00"
278278
},
279279
{
280280
"origin": "bosun.org/vendor/github.com/bosun-monitor/annotate/web",
281281
"path": "github.com/bosun-monitor/annotate/web",
282-
"revision": "68b0a4165b545e37b87b3b4b8baca55156ac9119",
283-
"revisionTime": "2016-04-29T11:34:44-04:00"
282+
"revision": "fa0f15c651bfe666cd287c2ba760436b41c85cf4",
283+
"revisionTime": "2016-08-04T13:41:31-04:00"
284284
},
285285
{
286286
"path": "github.com/bosun-monitor/statusio",

0 commit comments

Comments
 (0)