scheduler_monitor.go ×13

Frontier kind: Code frontier

unlabeled · c_4fcb8ff71d4c

2 tests · 2701 LOC · 132 files · introduces 0 tests · 88 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges88 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
414 ranges2701 lines · 132 files · Browse complete extent
All tests (intent)
2 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 88 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/history/queues/scheduler_monitor.go 78 introduced LOC · 13 ranges

Open complete file

57 metricsHandler metrics.Handler,
58 options schedulerMonitorOptions,
59 > ) *schedulerMonitor { scheduler_monitor.go
60 > return &schedulerMonitor{
61 > taskChannelKeyFn: taskChannelKeyFn,
62 > namespaceRegistry: namespaceRegistry,
63 > timeSource: timeSource,
64 > metricsHandler: metricsHandler,
65 > options: options,
66 >
67 > status: common.DaemonStatusInitialized,
68 > shutdownCh: make(chan struct{}),
69 >
70 > scheduleStats: make(map[TaskChannelKey]*scheduleStats),
71 > }
72 > }
73
74 > func (m *schedulerMonitor) Start() { scheduler_monitor.go
75 > if !atomic.CompareAndSwapInt32(&m.status, common.DaemonStatusInitialized, common.DaemonStatusStarted) {
76 return
77 }
78
79 > go m.metricEmissionLoop() scheduler_monitor.go
80 }
81
82 > func (m *schedulerMonitor) Stop() { scheduler_monitor.go
83 > if !atomic.CompareAndSwapInt32(&m.status, common.DaemonStatusStarted, common.DaemonStatusStopped) {
84 return
85 }
86
87 > close(m.shutdownCh) scheduler_monitor.go
88 }
89
90 > func (m *schedulerMonitor) RecordStart(executable Executable) { scheduler_monitor.go
91 > startTime := m.timeSource.Now()
92 > taskChanKey := m.taskChannelKeyFn(executable)
93 >
94 > m.Lock()
95 > defer m.Unlock()
96 >
97 > stats := m.getOrCreateScheduleStatsLocked(taskChanKey)
98 >
99 > // The latency we want to measure is the duration between
100 > // two task start time for one task channel.
101 > // However, it's possible that the second task is only queued
102 > // long after the first task is started. In that case, the
103 > // latency becomes the duration between schedule to start time
104 > // for the second task.
105 > latency := min(
106 > startTime.Sub(stats.lastStartTime),
107 > startTime.Sub(executable.GetScheduledTime()),
108 > )
109 > stats.lastStartTime = startTime
110 > stats.numStarted++
111 > stats.totalLatency += latency
112 >
113 > if stats.numStarted >= m.options.aggregationCount {
114 m.emitMetric(taskChanKey, stats)
115 }
116 }
117
118 > func (m *schedulerMonitor) metricEmissionLoop() { scheduler_monitor.go
119 > emissionTicker := time.NewTicker(m.options.aggregationDuration)
120 > defer emissionTicker.Stop()
121 >
122 > for {
123 > select {
124 > case <-m.shutdownCh:
125 > return
126 case <-emissionTicker.C:
127 m.Lock()
141 func (m *schedulerMonitor) getOrCreateScheduleStatsLocked(
142 taskChanKey TaskChannelKey,
143 > ) *scheduleStats { scheduler_monitor.go
144 > if stats, ok := m.scheduleStats[taskChanKey]; ok {
145 > return stats
146 > }
147
148 > namespaceName, _ := m.namespaceRegistry.GetNamespaceName(namespace.ID(taskChanKey.NamespaceID)) scheduler_monitor.go
149 >
150 > stats := &scheduleStats{
151 > taggedMetricsHandler: m.metricsHandler.WithTags(
152 > metrics.NamespaceTag(namespaceName.String()),
153 > metrics.TaskPriorityTag(taskChanKey.Priority.String()),
154 > ),
155 > lastEmissionTime: m.timeSource.Now(),
156 > }
157 > m.scheduleStats[taskChanKey] = stats
158 > return stats
159 }
160
162 taskChanKey TaskChannelKey,
163 stats *scheduleStats,
165 > if stats.numStarted == 0 {
166 return
167 }
168
169 > totalLatency := stats.totalLatency scheduler_monitor.go
170 > if stats.numStarted != m.options.aggregationCount {
171 totalLatency = totalLatency / time.Duration(stats.numStarted) * time.Duration(m.options.aggregationCount)
172 }
173
174 > metrics.QueueScheduleLatency.With(stats.taggedMetricsHandler).Record(totalLatency) scheduler_monitor.go
175 > m.resetStats(stats)
176 }
177
178 func (m *schedulerMonitor) resetStats(
179 stats *scheduleStats,
181 > stats.numStarted = 0
182 > stats.totalLatency = 0
183 > stats.lastEmissionTime = m.timeSource.Now()
184 > }
185
186 func (m *noopSchedulerMonitor) Start() {}
go.temporal.io/server/service/history/queues/executable_mock.go 10 introduced LOC · 2 ranges

Open complete file

181
182 // GetScheduledTime mocks base method.
183 > func (m *MockExecutable) GetScheduledTime() time.Time { executable_mock.go
184 > m.ctrl.T.Helper()
185 > ret := m.ctrl.Call(m, "GetScheduledTime")
186 > ret0, _ := ret[0].(time.Time)
187 > return ret0
188 > }
189
190 // GetScheduledTime indicates an expected call of GetScheduledTime.
191 > func (mr *MockExecutableMockRecorder) GetScheduledTime() *gomock.Call { executable_mock.go
192 > mr.mock.ctrl.T.Helper()
193 > return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetScheduledTime", reflect.TypeOf((*MockExecutable)(nil).GetScheduledTime))
194 > }
195
196 // GetTask mocks base method.