Skip to content

Commit

Permalink
Merge pull request #1665 from jkroepke/BuildFQName
Browse files Browse the repository at this point in the history
Optimize BuildFQName function
  • Loading branch information
bwplotka authored Nov 1, 2024
2 parents 769f6f6 + ece74f8 commit d3f2840
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions prometheus/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,23 @@ func BuildFQName(namespace, subsystem, name string) string {
if name == "" {
return ""
}
switch {
case namespace != "" && subsystem != "":
return strings.Join([]string{namespace, subsystem, name}, "_")
case namespace != "":
return strings.Join([]string{namespace, name}, "_")
case subsystem != "":
return strings.Join([]string{subsystem, name}, "_")

sb := strings.Builder{}
sb.Grow(len(namespace) + len(subsystem) + len(name) + 2)

if namespace != "" {
sb.WriteString(namespace)
sb.WriteString("_")
}
return name

if subsystem != "" {
sb.WriteString(subsystem)
sb.WriteString("_")
}

sb.WriteString(name)

return sb.String()
}

type invalidMetric struct {
Expand Down

0 comments on commit d3f2840

Please sign in to comment.