Skip to content

Commit

Permalink
fix/use UNSUPPORTED to represent undefined procotol in labelConvert…
Browse files Browse the repository at this point in the history
…er (#212)

* fix: avoid to use undefined Protocol

Signed-off-by: niejiangang <niejiangang@harmonycloud.cn>

* fix: add return if exporter is not support trace

Signed-off-by: niejiangang <niejiangang@harmonycloud.cn>

* docs(labelConverter): add comments for `withExtraLabels` function

Signed-off-by: niejiangang <niejiangang@harmonycloud.cn>

* refactor: exact a method for finding extraLabels

Signed-off-by: niejiangang <niejiangang@harmonycloud.cn>
  • Loading branch information
NeJan2020 authored May 7, 2022
1 parent 737c811 commit 96f9adf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions collector/consumer/exporter/otelexporter/consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (e *OtelExporter) Export(results []*defaultadapter.AdaptedResult) {
func (e *OtelExporter) exportTrace(result *defaultadapter.AdaptedResult) {
if e.defaultTracer == nil {
e.telemetry.Logger.Error("Send span failed: this exporter doesn't support Span Data", zap.String("exporter", e.cfg.ExportKind))
return
}
_, span := e.defaultTracer.Start(
context.Background(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func newAdapterBuilder(
}
}

// withExtraLabels determine the final output structure according to some fields in the input data adjustment
// params provide a list of extraLabelsParam contain all possible final output structure and a unique key
// update provide a updateKey func to general a extraLabelsKey key from input data
// avoid the situation where the key generated by updateKey is undefined in params
func (m *metricAdapterBuilder) withExtraLabels(params []extraLabelsParam, update updateKey) *metricAdapterBuilder {
if m.extraLabelsKey == nil || len(m.extraLabelsKey) == 0 {
m.extraLabelsKey = make([]extraLabelsKey, len(params))
Expand Down Expand Up @@ -272,11 +276,7 @@ func (m *metricAdapterBuilder) build() (*LabelConverter, error) {
// transform is used to general final labels for Async Metric.It won't modify the origin model.GaugeGroup and should be free by calling the FreeAttrsMap after exported.
func (m *LabelConverter) transform(group *model.GaugeGroup) (*model.AttributeMap, FreeAttrsMap) {
labels := group.Labels
tmpExtraKey := &extraLabelsKey{protocol: empty}
for i := 0; i < len(m.updateKeys); i++ {
tmpExtraKey = m.updateKeys[i](tmpExtraKey, labels)
}
attrs := m.labelsMap[*tmpExtraKey]
attrs := m.searchExtraAttribute(labels)
attrsMap := attrs.attrsMapPool.Get().(*model.AttributeMap)
for i := 0; i < len(attrs.metricsDicList); i++ {
switch attrs.metricsDicList[i].valueType {
Expand Down Expand Up @@ -313,14 +313,25 @@ func (m *LabelConverter) transform(group *model.GaugeGroup) (*model.AttributeMap
return attrsMap, attrs.attrsMapPool.Free
}

// convert is used to general final labels for Sync Metric and Trace. It won't modify the origin model.GaugeGroup and should be free by calling the FreeAttrsList after exported.
func (m *LabelConverter) convert(group *model.GaugeGroup) ([]attribute.KeyValue, FreeAttrsList) {
labels := group.Labels
// searchExtraAttribute determine the final outPut struct for incoming gaugeGroup
// return the default struct of `UNSUPPORTED Protocol` if failed
func (m *LabelConverter) searchExtraAttribute(labels *model.AttributeMap) realAttributes {
tmpExtraKey := &extraLabelsKey{protocol: empty}
for i := 0; i < len(m.updateKeys); i++ {
tmpExtraKey = m.updateKeys[i](tmpExtraKey, labels)
}
attrs := m.labelsMap[*tmpExtraKey]
attrs, ok := m.labelsMap[*tmpExtraKey]
if !ok {
tmpExtraKey.protocol = UNSUPPORTED
attrs = m.labelsMap[*tmpExtraKey]
}
return attrs
}

// convert is used to general final labels for Sync Metric and Trace. It won't modify the origin model.GaugeGroup and should be free by calling the FreeAttrsList after exported.
func (m *LabelConverter) convert(group *model.GaugeGroup) ([]attribute.KeyValue, FreeAttrsList) {
labels := group.Labels
attrs := m.searchExtraAttribute(group.Labels)
attrsList := attrs.attrsListPool.Get().([]attribute.KeyValue)
for i := 0; i < len(attrs.metricsDicList); i++ {
switch attrs.metricsDicList[i].valueType {
Expand Down

0 comments on commit 96f9adf

Please sign in to comment.