MCPcopy Create free account
hub / github.com/couchbase/cbft / gatherIndexStats

Function gatherIndexStats

ns_server.go:208–432  ·  view source on GitHub ↗
(mgr *cbgt.Manager, rd *recentInfo,
	collAware bool)

Source from the content-addressed store, hash-verified

206}
207
208func gatherIndexStats(mgr *cbgt.Manager, rd *recentInfo,
209 collAware bool) (NSIndexStats, error) {
210 if rd == nil || mgr == nil {
211 return nil, nil
212 }
213
214 indexDefsMap := rd.indexDefsMap
215 planPIndexes := rd.planPIndexes
216 nodeUUID := mgr.UUID()
217
218 nsIndexStats := make(NSIndexStats, len(indexDefsMap))
219
220 indexNameToSourceName := map[string]string{}
221
222 indexNameToPlanPIndexes := map[string][]*cbgt.PlanPIndex{}
223 if planPIndexes != nil {
224 for _, planPIndex := range planPIndexes.PlanPIndexes {
225 // Only focus on the planPIndex entries for this node.
226 if planPIndex.Nodes[nodeUUID] != nil {
227 indexNameToPlanPIndexes[planPIndex.IndexName] =
228 append(indexNameToPlanPIndexes[planPIndex.IndexName], planPIndex)
229 }
230 }
231 }
232
233 indexQueryPathStats := MapRESTPathStats[RESTIndexQueryPath]
234
235 // Keyed by sourceName, sub-key is source partition id.
236 sourceNameToSourcePartitionSeqs := map[string]map[string]cbgt.UUIDSeq{}
237
238 // Keyed by indexName, sub-key is source partition id.
239 indexNameToDestPartitionSeqs := map[string]map[string]cbgt.UUIDSeq{}
240
241 for indexName, indexDef := range indexDefsMap {
242 nsIndexStat := NewIndexStat()
243 if collAware {
244 key := getNsIndexStatsKey(indexName, indexDef.SourceName, indexDef.Params)
245 nsIndexStats[key] = nsIndexStat
246 indexNameToSourceName[indexName] = key
247 } else {
248 nsIndexStats[indexDef.SourceName+":"+indexName] = nsIndexStat
249 indexNameToSourceName[indexName] = indexDef.SourceName + ":" + indexName
250 }
251
252 focusStats := indexQueryPathStats.FocusStats(indexName)
253 if focusStats != nil {
254 totalQueries := atomic.LoadUint64(&focusStats.TotClientRequest)
255 nsIndexStat["total_queries"] = totalQueries
256 if totalQueries > 0 {
257 nsIndexStat["avg_queries_latency"] =
258 float64(atomic.LoadUint64(&focusStats.TotClientRequestTimeNS)/
259 totalQueries) / 1000000.0 // Convert from nanosecs to millisecs.
260 }
261 totalInternalQueries := atomic.LoadUint64(&focusStats.TotInternalRequest)
262 nsIndexStat["total_internal_queries"] = totalInternalQueries
263 if totalInternalQueries > 0 {
264 nsIndexStat["avg_internal_queries_latency"] =
265 float64(atomic.LoadUint64(&focusStats.TotInternalRequestTimeNS)/

Callers 2

ServeHTTPMethod · 0.85
ServeHTTPMethod · 0.85

Calls 10

NewIndexStatFunction · 0.85
getNsIndexStatsKeyFunction · 0.85
GetSourcePartitionSeqsFunction · 0.85
addPIndexStatsFunction · 0.85
addFeedStatsFunction · 0.85
obtainDestSeqsForIndexFunction · 0.85
gatherTopLevelStatsFunction · 0.85
FocusStatsMethod · 0.80
PartitionSeqsMethod · 0.65

Tested by

no test coverage detected