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

Method encode

server/controller/prometheus/encoder/label.go:130–172  ·  view source on GitHub ↗
(toAdd []*controller.PrometheusLabelRequest)

Source from the content-addressed store, hash-verified

128}
129
130func (l *label) encode(toAdd []*controller.PrometheusLabelRequest) ([]*controller.PrometheusLabel, error) {
131 l.lock.Lock()
132 defer l.lock.Unlock()
133
134 resp := make([]*controller.PrometheusLabel, 0)
135 var dbToAdd []*metadbmodel.PrometheusLabel
136 for _, item := range toAdd {
137 n := item.GetName()
138 v := item.GetValue()
139 nameID, ok1 := l.labelName.getID(n)
140 valueID, ok2 := l.labelValue.getID(v)
141 if ok1 && ok2 {
142 if id, ok := l.getID(cache.IDLabelKey{NameID: nameID, ValueID: valueID}); ok {
143 resp = append(resp, &controller.PrometheusLabel{
144 Name: &n,
145 Value: &v,
146 Id: proto.Uint32(uint32(id)),
147 })
148 continue
149 }
150 }
151 dbToAdd = append(dbToAdd, &metadbmodel.PrometheusLabel{
152 Name: n,
153 Value: v,
154 })
155 }
156
157 err := addBatch(l.org.DB, dbToAdd, l.resourceType)
158 if err != nil {
159 log.Errorf("add %s error: %s", l.resourceType, err.Error(), l.org.LogPrefix)
160 return nil, err
161 }
162 for _, item := range dbToAdd {
163 l.store(item)
164 resp = append(resp, &controller.PrometheusLabel{
165 Name: &item.Name,
166 Value: &item.Value,
167 Id: proto.Uint32(uint32(item.ID)),
168 })
169
170 }
171 return resp, nil
172}

Callers 5

encodeMetricNameMethod · 0.45
encodeLabelNameMethod · 0.45
encodeLabelValueMethod · 0.45
encodeLabelIndexMethod · 0.45
encodeLabelMethod · 0.45

Calls 9

getIDMethod · 0.95
storeMethod · 0.95
addBatchFunction · 0.85
GetNameMethod · 0.65
ErrorMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
GetValueMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected