forked from mirrors/statsd_exporter
cleanup
Signed-off-by: Wangchong Zhou <fffonion@gmail.com>
This commit is contained in:
parent
9ebab25dfa
commit
a751c0c091
1 changed files with 9 additions and 16 deletions
|
@ -114,11 +114,11 @@ var defaultQuantiles = []metricObjective{
|
||||||
{Quantile: 0.99, Error: 0.001},
|
{Quantile: 0.99, Error: 0.001},
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateFormatter(valueExpr string, captureCount int) (templateFormatter, error) {
|
func generateFormatter(valueExpr string, captureCount int) templateFormatter {
|
||||||
matches := templateReplaceCaptureRE.FindAllStringSubmatch(valueExpr, -1)
|
matches := templateReplaceCaptureRE.FindAllStringSubmatch(valueExpr, -1)
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
// if no regex reference found, keep it as it is
|
// if no regex reference found, keep it as it is
|
||||||
return templateFormatter{captureCount: 0, fmtString: valueExpr}, nil
|
return templateFormatter{captureCount: 0, fmtString: valueExpr}
|
||||||
}
|
}
|
||||||
|
|
||||||
var indexes []int
|
var indexes []int
|
||||||
|
@ -139,7 +139,7 @@ func generateFormatter(valueExpr string, captureCount int) (templateFormatter, e
|
||||||
captureIndexes: indexes,
|
captureIndexes: indexes,
|
||||||
captureCount: len(indexes),
|
captureCount: len(indexes),
|
||||||
fmtString: valueFormatter,
|
fmtString: valueFormatter,
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatTemplate(formatter templateFormatter, captures map[int]string) string {
|
func formatTemplate(formatter templateFormatter, captures map[int]string) string {
|
||||||
|
@ -274,18 +274,13 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
|
||||||
root = state
|
root = state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nameFmt, err := generateFormatter(currentMapping.Name, captureCount)
|
nameFmt := generateFormatter(currentMapping.Name, captureCount)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
currentMapping.NameFormatter = nameFmt
|
currentMapping.NameFormatter = nameFmt
|
||||||
|
|
||||||
currentLabelFormatter := make(map[string]templateFormatter, captureCount)
|
currentLabelFormatter := make(map[string]templateFormatter, captureCount)
|
||||||
for label, valueExpr := range currentMapping.Labels {
|
for label, valueExpr := range currentMapping.Labels {
|
||||||
lblFmt, err := generateFormatter(valueExpr, captureCount)
|
lblFmt := generateFormatter(valueExpr, captureCount)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
currentLabelFormatter[label] = lblFmt
|
currentLabelFormatter[label] = lblFmt
|
||||||
}
|
}
|
||||||
currentMapping.LabelsFormatter = currentLabelFormatter
|
currentMapping.LabelsFormatter = currentLabelFormatter
|
||||||
|
@ -317,8 +312,8 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
|
||||||
|
|
||||||
m.Defaults = n.Defaults
|
m.Defaults = n.Defaults
|
||||||
m.Mappings = n.Mappings
|
m.Mappings = n.Mappings
|
||||||
|
m.hasFSM = n.hasFSM
|
||||||
if n.hasFSM {
|
if n.hasFSM {
|
||||||
m.hasFSM = n.hasFSM
|
|
||||||
m.FSM = n.FSM
|
m.FSM = n.FSM
|
||||||
m.doRegex = n.doRegex
|
m.doRegex = n.doRegex
|
||||||
if m.dumpFSMPath != "" {
|
if m.dumpFSMPath != "" {
|
||||||
|
@ -394,7 +389,7 @@ func needBacktracking(n *MetricMapper) bool {
|
||||||
for i2, re2 := range rulesRE {
|
for i2, re2 := range rulesRE {
|
||||||
// especially, if r1 is a subset of other rule, we don't need backtrack
|
// especially, if r1 is a subset of other rule, we don't need backtrack
|
||||||
// because either we turned on ordering
|
// because either we turned on ordering
|
||||||
// or we disabled ordering and can't match it with backtrack
|
// or we disabled ordering and can't match it even with backtrack
|
||||||
if i2 != i1 && re2 != nil && len(re2.FindStringSubmatchIndex(r1)) > 0 {
|
if i2 != i1 && re2 != nil && len(re2.FindStringSubmatchIndex(r1)) > 0 {
|
||||||
currentRuleNeedBacktrack = false
|
currentRuleNeedBacktrack = false
|
||||||
}
|
}
|
||||||
|
@ -462,12 +457,10 @@ func (m *MetricMapper) GetMapping(statsdMetric string, statsdMetricType MetricTy
|
||||||
// glob matching
|
// glob matching
|
||||||
if m.hasFSM {
|
if m.hasFSM {
|
||||||
matchFields := strings.Split(statsdMetric, ".")
|
matchFields := strings.Split(statsdMetric, ".")
|
||||||
|
|
||||||
root := m.FSM.transitions[string(statsdMetricType)]
|
root := m.FSM.transitions[string(statsdMetricType)]
|
||||||
captures := make(map[int]string, len(matchFields))
|
captures := make(map[int]string, len(matchFields))
|
||||||
captureIdx := 0
|
captureIdx := 0
|
||||||
var backtrackCursor *fsmBacktrackStackCursor
|
var backtrackCursor *fsmBacktrackStackCursor
|
||||||
backtrackCursor = nil
|
|
||||||
resumeFromBacktrack := false
|
resumeFromBacktrack := false
|
||||||
var result *MetricMapping
|
var result *MetricMapping
|
||||||
filedsCount := len(matchFields)
|
filedsCount := len(matchFields)
|
||||||
|
@ -505,7 +498,7 @@ func (m *MetricMapper) GetMapping(statsdMetric string, statsdMetricType MetricTy
|
||||||
backtrackCursor = &newCursor
|
backtrackCursor = &newCursor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // root.transitions == nil
|
} else { // no more transitions for this state
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} // backtrack will resume from here
|
} // backtrack will resume from here
|
||||||
|
|
Loading…
Reference in a new issue