MCPcopy Create free account
hub / github.com/deepflowio/deepflow / refresh

Method refresh

server/controller/prometheus/cache/label.go:157–198  ·  view source on GitHub ↗
(args ...interface{})

Source from the content-addressed store, hash-verified

155}
156
157func (l *label) refresh(args ...interface{}) error {
158 var count int64
159 if err := l.org.DB.Model(&metadbmodel.PrometheusLabel{}).Count(&count).Error; err != nil {
160 return err
161 }
162
163 rows, err := l.org.DB.Model(&metadbmodel.PrometheusLabel{}).Select("id", "name", "value").Rows()
164 if err != nil {
165 return err
166 }
167 defer rows.Close()
168
169 newActive := make(map[IDLabelKey]int, count)
170 for rows.Next() {
171 var id int
172 var name, value string
173 if scanErr := rows.Scan(&id, &name, &value); scanErr != nil {
174 log.Errorf("stream scan prometheus_label interrupted: %v", scanErr, l.org.LogPrefix)
175 return scanErr
176 }
177 nameID, ok1 := l.labelName.GetIDByName(name)
178 valueID, ok2 := l.labelValue.GetIDByValue(value)
179 if ok1 && ok2 {
180 newActive[IDLabelKey{NameID: nameID, ValueID: valueID}] = id
181 }
182 }
183 if err := rows.Err(); err != nil {
184 log.Errorf("stream read prometheus_label error: %v", err, l.org.LogPrefix)
185 return err
186 }
187
188 l.mu.Lock()
189 pending := l.pending
190 l.pending = make(map[IDLabelKey]int)
191 for key, value := range pending {
192 newActive[key] = value
193 }
194 l.mu.Unlock()
195
196 l.replaceActive(newActive)
197 return nil
198}

Callers

nothing calls this directly

Calls 10

replaceActiveMethod · 0.95
NextMethod · 0.80
GetIDByValueMethod · 0.80
CloseMethod · 0.65
SelectMethod · 0.45
ScanMethod · 0.45
ErrorfMethod · 0.45
GetIDByNameMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected