github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/segment/structs/searchmetrics.go (about) 1 /* 2 Copyright 2023. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package structs 18 19 import ( 20 "sync" 21 "sync/atomic" 22 "time" 23 ) 24 25 type QueryProcessingMetrics struct { 26 NumRecordsMatched uint64 27 NumBlocksWithMatch uint64 28 NumBlocksToRawSearch uint64 29 NumBlocksInSegment uint64 30 NumRecordsToRawSearch uint64 31 NumRecordsUnmatched uint64 32 } 33 34 type MetricsQueryProcessingMetrics struct { 35 UpdateLock *sync.Mutex 36 NumMetricsSegmentsSearched uint64 37 NumTSOFilesLoaded uint64 38 NumTSGFilesLoaded uint64 39 NumSeriesSearched uint64 40 TimeLoadingTSOFiles time.Duration 41 TimeLoadingTSGFiles time.Duration 42 } 43 44 func (qm *QueryProcessingMetrics) SetNumRecordsMatched(records uint64) { 45 atomic.AddUint64(&qm.NumRecordsMatched, records) 46 } 47 48 func (qm *QueryProcessingMetrics) SetNumRecordsUnmatched(records uint64) { 49 atomic.AddUint64(&qm.NumRecordsUnmatched, records) 50 } 51 52 func (qm *QueryProcessingMetrics) IncrementNumBlocksWithMatch(nBlocks uint64) { 53 atomic.AddUint64(&qm.NumBlocksWithMatch, nBlocks) 54 } 55 56 func (qm *QueryProcessingMetrics) IncrementNumRecordsWithMatch(nBlocks uint64) { 57 atomic.AddUint64(&qm.NumRecordsMatched, nBlocks) 58 } 59 60 func (qm *QueryProcessingMetrics) IncrementNumRecordsNoMatch(nBlocks uint64) { 61 atomic.AddUint64(&qm.NumRecordsUnmatched, nBlocks) 62 } 63 64 func (qm *QueryProcessingMetrics) IncrementNumBlocksToRawSearch(records uint64) { 65 atomic.AddUint64(&qm.NumBlocksToRawSearch, records) 66 } 67 68 func (qm *QueryProcessingMetrics) SetNumBlocksToRawSearch(records uint64) { 69 atomic.StoreUint64(&qm.NumBlocksToRawSearch, records) 70 } 71 72 func (qm *QueryProcessingMetrics) SetNumBlocksInSegFile(records uint64) { 73 atomic.StoreUint64(&qm.NumBlocksInSegment, records) 74 } 75 76 func (qm *QueryProcessingMetrics) SetNumRecordsToRawSearch(records uint64) { 77 atomic.StoreUint64(&qm.NumRecordsToRawSearch, records) 78 } 79 80 func (qm *MetricsQueryProcessingMetrics) IncrementNumMetricsSegmentsSearched(records uint64) { 81 atomic.StoreUint64(&qm.NumMetricsSegmentsSearched, records) 82 } 83 84 func (qm *MetricsQueryProcessingMetrics) IncrementNumTSOFilesLoaded(records uint64) { 85 atomic.AddUint64(&qm.NumTSOFilesLoaded, records) 86 } 87 88 func (qm *MetricsQueryProcessingMetrics) IncrementNumTSGFilesLoaded(records uint64) { 89 atomic.AddUint64(&qm.NumTSGFilesLoaded, records) 90 } 91 92 func (qm *MetricsQueryProcessingMetrics) IncrementNumSeriesSearched(records uint64) { 93 atomic.AddUint64(&qm.NumSeriesSearched, records) 94 } 95 96 func (qm *MetricsQueryProcessingMetrics) SetTimeLoadingTSOFiles(ttime time.Duration) { 97 qm.UpdateLock.Lock() 98 defer qm.UpdateLock.Unlock() 99 qm.TimeLoadingTSOFiles = ttime 100 } 101 102 func (qm *MetricsQueryProcessingMetrics) SetTimeLoadingTSGFiles(ttime time.Duration) { 103 qm.UpdateLock.Lock() 104 defer qm.UpdateLock.Unlock() 105 qm.TimeLoadingTSGFiles = ttime 106 }