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

Method encode

server/controller/prometheus/encoder/label_value.go:103–131  ·  view source on GitHub ↗
(strs []string)

Source from the content-addressed store, hash-verified

101}
102
103func (lv *labelValue) encode(strs []string) ([]*controller.PrometheusLabelValue, error) {
104 lv.lock.Lock()
105 defer lv.lock.Unlock()
106
107 resp := make([]*controller.PrometheusLabelValue, 0)
108 dbToAdd := make([]*metadbmodel.PrometheusLabelValue, 0)
109 for i := range strs {
110 str := strs[i]
111 if id, ok := lv.getID(str); ok {
112 resp = append(resp, &controller.PrometheusLabelValue{Value: &str, Id: proto.Uint32(uint32(id))})
113 continue
114 }
115 dbToAdd = append(dbToAdd, &metadbmodel.PrometheusLabelValue{Value: str})
116 }
117 if len(dbToAdd) == 0 {
118 return resp, nil
119 }
120
121 err := addBatch(lv.org.DB, dbToAdd, lv.resourceType)
122 if err != nil {
123 log.Errorf("add %s error: %s", lv.resourceType, err.Error(), lv.org.LogPrefix)
124 return nil, err
125 }
126 for i := range dbToAdd {
127 lv.store(dbToAdd[i])
128 resp = append(resp, &controller.PrometheusLabelValue{Value: &dbToAdd[i].Value, Id: proto.Uint32(uint32(dbToAdd[i].ID))})
129 }
130 return resp, nil
131}
132
133func (lv *labelValue) getID(str string) (int, bool) {
134 id, ok := lv.strToID[str]

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected