-
Notifications
You must be signed in to change notification settings - Fork 17
/
stats_updater.go
163 lines (139 loc) · 5.59 KB
/
stats_updater.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package consumer
import (
"time"
"github.com/couchbase/eventing/logging"
)
func newVbProcessingStats(appName string, numVbuckets uint16, uuid, workerName string) vbStats {
vbsts := make(vbStats, numVbuckets)
for i := uint16(0); i < numVbuckets; i++ {
vbsts[i] = &vbStat{
stats: make(map[string]interface{}),
}
vbsts[i].stats["assigned_worker"] = ""
vbsts[i].stats["dcp_stream_status"] = dcpStreamStopped
vbsts[i].stats["dcp_stream_requested"] = false
vbsts[i].stats["dcp_stream_requested_worker"] = ""
vbsts[i].stats["dcp_stream_requested_node_uuid"] = ""
vbsts[i].stats["vb_filter_ack_received"] = true
vbsts[i].stats["plasma_last_seq_no_stored"] = uint64(0)
vbsts[i].stats["plasma_last_seq_no_persisted"] = uint64(0)
vbsts[i].stats["last_doc_timer_feedback_seqno"] = uint64(0)
vbsts[i].stats["last_processed_seq_no"] = uint64(0)
vbsts[i].stats["last_sent_seq_no"] = uint64(0)
vbsts[i].stats["manifest_id"] = "0"
vbsts[i].stats["currently_processed_doc_id_timer"] = time.Now().UTC().Format(time.RFC3339)
vbsts[i].stats["last_cleaned_up_doc_id_timer_event"] = time.Now().UTC().Format(time.RFC3339)
vbsts[i].stats["last_doc_id_timer_sent_to_worker"] = time.Now().UTC().Format(time.RFC3339)
vbsts[i].stats["last_processed_doc_id_timer_event"] = time.Now().UTC().Format(time.RFC3339)
vbsts[i].stats["next_doc_id_timer_to_process"] = time.Now().UTC().Add(time.Second).Format(time.RFC3339)
vbsts[i].stats["next_cron_timer_to_process"] = time.Now().UTC().Add(time.Second).Format(time.RFC3339)
vbsts[i].stats["currently_processed_cron_timer"] = time.Now().UTC().Add(time.Second).Format(time.RFC3339)
vbsts[i].stats["last_processed_cron_timer_event"] = time.Now().UTC().Add(time.Second).Format(time.RFC3339)
// Doc timer debug stats
vbsts[i].stats["deleted_during_cleanup_counter"] = uint64(0)
vbsts[i].stats["removed_during_rebalance_counter"] = uint64(0)
vbsts[i].stats["sent_to_worker_counter"] = uint64(0)
vbsts[i].stats["timer_create_counter"] = uint64(0)
vbsts[i].stats["timers_in_past_counter"] = uint64(0)
vbsts[i].stats["timers_in_past_from_backfill_counter"] = uint64(0)
vbsts[i].stats["timers_recreated_from_dcp_backfill"] = uint64(0)
//Cron timer debug stats
vbsts[i].stats["processed_crontimer_counter"] = uint64(0)
// vb seq no stats
vbsts[i].stats["ever_owned_vb"] = false
vbsts[i].stats["host_name"] = ""
vbsts[i].stats["last_checkpointed_seq_no"] = uint64(0)
vbsts[i].stats["last_read_seq_no"] = uint64(0)
vbsts[i].stats["node_uuid"] = uuid
vbsts[i].stats["start_seq_no"] = uint64(0)
vbsts[i].stats["seq_no_at_stream_end"] = uint64(0)
vbsts[i].stats["seq_no_after_close_stream"] = uint64(0)
vbsts[i].stats["timestamp"] = time.Now().UTC().Format(time.RFC3339)
vbsts[i].stats["vb_uuid"] = uint64(0)
vbsts[i].stats["worker_name"] = workerName
}
return vbsts
}
func newVbBackupStats(numVbuckets uint16) vbStats {
vbsts := make(vbStats, numVbuckets)
for i := uint16(0); i < numVbuckets; i++ {
vbsts[i] = &vbStat{
stats: make(map[string]interface{}),
}
vbsts[i].stats["last_doc_timer_feedback_seqno"] = uint64(0)
vbsts[i].stats["last_processed_seq_no"] = uint64(0)
//Doc timer counter
vbsts[i].stats["sent_to_worker_counter"] = uint64(0)
//Cron timer counter
vbsts[i].stats["processed_crontimer_counter"] = uint64(0)
}
return vbsts
}
func (vbs vbStats) getVbStat(vb uint16, statName string) interface{} {
vbstat := vbs[vb]
vbstat.RLock()
defer vbstat.RUnlock()
return vbstat.stats[statName]
}
func (vbs vbStats) updateVbStat(vb uint16, statName string, val interface{}) {
vbstat := vbs[vb]
vbstat.Lock()
defer vbstat.Unlock()
vbstat.stats[statName] = val
}
func (c *Consumer) loadStatsFromConsumer() {
logPrefix := "Consumer::loadStatsFromConsumer"
// initialise workerInitMainLoopTs. This is to ensure we can respawn the consumer in case it never responds after bootstrapping
c.workerInitMainLoopTs.Store(time.Now())
for {
select {
case <-c.loadStatsTicker.C:
val := c.workerRespMainLoopTs.Load()
stopReason := "last response received"
if val == nil {
val = c.workerInitMainLoopTs.Load() // grab initialisation TS if there was no response from worker yet
stopReason = "worker initialised"
}
if lastTs, ok := val.(time.Time); ok {
if int(time.Now().Sub(lastTs).Seconds()) > c.workerRespMainLoopThreshold {
if c.stoppingConsumer {
logging.Errorf("%s [%s:%s:%d] stoppingConsumer: %t %s at %s",
logPrefix, c.workerName, c.tcpPort, c.Pid(), c.stoppingConsumer, stopReason, lastTs.String())
return
}
logging.Infof("%s [%s:%s:%d] stoppingConsumer: %t re-spawning eventing, %s at %s",
logPrefix, c.workerName, c.tcpPort, c.Pid(), c.stoppingConsumer, stopReason, lastTs.String())
c.stoppingConsumer = true
c.killAndRespawn()
}
}
case <-c.stopConsumerCh:
logging.Infof("%s [%s:%s:%d] Exiting cpp worker stats loader routine",
logPrefix, c.workerName, c.tcpPort, c.Pid())
return
}
}
}
func (c *Consumer) updateWorkerStats() {
logPrefix := "Consumer::updateWorkerStats"
for {
select {
case <-c.updateStatsTicker.C:
if c.workerExited {
logging.Debugf("%s [%s:%s:%d] Skipping sending worker stat opcode as worker exited",
logPrefix, c.workerName, c.tcpPort, c.Pid())
continue
}
go c.dcpEventsRemainingToProcess()
c.sendGetExecutionStats(false)
c.sendGetFailureStats(false)
c.sendGetLatencyStats()
c.sendGetLcbExceptionStats(false)
c.refreshCurlLatencyStats()
case <-c.stopConsumerCh:
logging.Infof("%s [%s:%s:%d] Exiting cpp worker stats updater routine",
logPrefix, c.workerName, c.tcpPort, c.Pid())
return
}
}
}