-
Notifications
You must be signed in to change notification settings - Fork 6
/
stopper.go
69 lines (60 loc) · 1.61 KB
/
stopper.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
// Copyright 2022 The incite Authors. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package incite
import (
"context"
"time"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
)
type stopper struct {
worker
}
func newStopper(m *mgr) *stopper {
s := &stopper{
worker: worker{
m: m,
regulator: makeRegulator(m.close, m.RPS[StopQuery], RPSDefaults[StopQuery], !m.DisableAdaptation),
in: m.stop,
out: m.update,
name: "stopper",
maxTemporaryError: 3,
},
}
s.manipulator = s
return s
}
func (s *stopper) context(_ *chunk) context.Context {
return context.Background()
}
func (s *stopper) manipulate(c *chunk) outcome {
output, err := s.m.Actions.StopQueryWithContext(context.Background(), &cloudwatchlogs.StopQueryInput{
QueryId: &c.queryID,
}, request.WithAppendUserAgent(version()))
s.lastReq = time.Now()
if err != nil {
switch classifyError(err) {
case throttlingClass:
return throttlingError
case temporaryClass, limitExceededClass:
return temporaryError
default:
s.m.logChunk(c, "failed to stop", "error from CloudWatch Logs: "+err.Error())
return finished
}
} else if output.Success == nil || !*output.Success {
s.m.logChunk(c, "failed to stop", "CloudWatch Logs did not indicate success")
return finished
} else {
s.m.logChunk(c, "stopped", "")
return finished
}
}
func (s *stopper) release(c *chunk) {
if s.setTimerRPS() {
<-s.timer.C
s.ding = true
}
_ = s.manipulate(c)
}