Skip to content

Commit

Permalink
Further review notes
Browse files Browse the repository at this point in the history
Signed-off-by: Owen Williams <[email protected]>
  • Loading branch information
ywwg committed Dec 14, 2023
1 parent 680c492 commit d9a18c0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions expfmt/openmetrics_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ func writeOpenMetricsSample(
return written, nil
}

// writeOpenMetricsNameAndLabelPairs works like writeOpenMetrics but formats the float
// in OpenMetrics style.
// writeOpenMetricsNameAndLabelPairs works like writeOpenMetricsSample but
// formats the float in OpenMetrics style.
func writeOpenMetricsNameAndLabelPairs(
w enhancedWriter,
name string,
Expand Down
22 changes: 11 additions & 11 deletions expfmt/openmetrics_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ name{labelname="val1",basename="basevalue"} 42.0
name{labelname="val2",basename="basevalue"} 0.23 1.23456789e+06
`,
},
// 0.5: Dots in name
// 1: Dots in name
{
in: &dto.MetricFamily{
Name: proto.String("name.with.dots"),
Expand Down Expand Up @@ -128,7 +128,7 @@ name{labelname="val2",basename="basevalue"} 0.23 1.23456789e+06
{"name.with.dots",labelname="val2",basename="basevalue"} 0.23 1.23456789e+06
`,
},
// 1: Dots in name, no labels
// 2: Dots in name, no labels
{
in: &dto.MetricFamily{
Name: proto.String("name.with.dots"),
Expand All @@ -154,7 +154,7 @@ name{labelname="val2",basename="basevalue"} 0.23 1.23456789e+06
{"name.with.dots"} 0.23 1.23456789e+06
`,
},
// 2: Gauge, some escaping required, +Inf as value, multi-byte characters in label values.
// 3: Gauge, some escaping required, +Inf as value, multi-byte characters in label values.
{
in: &dto.MetricFamily{
Name: proto.String("gauge_name"),
Expand Down Expand Up @@ -199,7 +199,7 @@ gauge_name{name_1="val with\nnew line",name_2="val with \\backslash and \"quotes
gauge_name{name_1="Björn",name_2="佖佥"} 3.14e+42
`,
},
// 3: Gauge, utf8, some escaping required, +Inf as value, multi-byte characters in label values.
// 4: Gauge, utf8, some escaping required, +Inf as value, multi-byte characters in label values.
{
in: &dto.MetricFamily{
Name: proto.String("gauge.name\""),
Expand Down Expand Up @@ -244,7 +244,7 @@ gauge_name{name_1="Björn",name_2="佖佥"} 3.14e+42
{"gauge.name\"","name.1"="Björn","name*2"="佖佥"} 3.14e+42
`,
},
// 4: Unknown, no help, one sample with no labels and -Inf as value, another sample with one label.
// 5: Unknown, no help, one sample with no labels and -Inf as value, another sample with one label.
{
in: &dto.MetricFamily{
Name: proto.String("unknown_name"),
Expand Down Expand Up @@ -273,7 +273,7 @@ unknown_name -Inf
unknown_name{name_1="value 1"} -1.23e-45
`,
},
// 5: Summary.
// 6: Summary.
{
in: &dto.MetricFamily{
Name: proto.String("summary_name"),
Expand Down Expand Up @@ -346,7 +346,7 @@ summary_name_sum{name_1="value 1",name_2="value 2"} 2010.1971
summary_name_count{name_1="value 1",name_2="value 2"} 4711
`,
},
// 6: Histogram
// 7: Histogram
{
in: &dto.MetricFamily{
Name: proto.String("request_duration_microseconds"),
Expand Down Expand Up @@ -394,7 +394,7 @@ request_duration_microseconds_sum 1.7560473e+06
request_duration_microseconds_count 2693
`,
},
// 7: Histogram with missing +Inf bucket.
// 8: Histogram with missing +Inf bucket.
{
in: &dto.MetricFamily{
Name: proto.String("request_duration_microseconds"),
Expand Down Expand Up @@ -438,7 +438,7 @@ request_duration_microseconds_sum 1.7560473e+06
request_duration_microseconds_count 2693
`,
},
// 8: Histogram with missing +Inf bucket but with different exemplars.
// 9: Histogram with missing +Inf bucket but with different exemplars.
{
in: &dto.MetricFamily{
Name: proto.String("request_duration_microseconds"),
Expand Down Expand Up @@ -505,7 +505,7 @@ request_duration_microseconds_sum 1.7560473e+06
request_duration_microseconds_count 2693
`,
},
// 9: Simple Counter.
// 10: Simple Counter.
{
in: &dto.MetricFamily{
Name: proto.String("foos_total"),
Expand All @@ -524,7 +524,7 @@ request_duration_microseconds_count 2693
foos_total 42.0
`,
},
// 10: No metric.
// 11: No metric.
{
in: &dto.MetricFamily{
Name: proto.String("name_total"),
Expand Down
8 changes: 4 additions & 4 deletions model/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
// therewith.
type LabelName string

// IsValid returns true iff name matches the pattern of LabelNameRE
// for legacy names, and iff it's valid UTF-8 if isUtf8 is true.
// This function, however, does not use LabelNameRE for the check but a much
// faster hardcoded implementation.
// IsValid returns true iff name matches the pattern of LabelNameRE for legacy
// names, and iff it's valid UTF-8 if NameValidationScheme is set to
// UTF8Validation. For the legacy matching, it does not use LabelNameRE for the
// check but a much faster hardcoded implementation.
func (ln LabelName) IsValid() bool {
if len(ln) == 0 {
return false
Expand Down
4 changes: 2 additions & 2 deletions model/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
type validationSchemeId int

const (
LegacyValidation = validationSchemeId(0)
UTF8Validation = validationSchemeId(1)
LegacyValidation validationSchemeId = iota
UTF8Validation
)

var (
Expand Down

0 comments on commit d9a18c0

Please sign in to comment.