Skip to content

Commit

Permalink
Merge branch 'main' into repo_sync
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperQ committed Mar 21, 2024
2 parents b850d7b + 057bec8 commit cc797da
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
6 changes: 3 additions & 3 deletions expfmt/openmetrics_create.go
Expand Up @@ -248,12 +248,12 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
var createdTsBytesWritten int

// Finally the samples, one line for each.
if metricType == dto.MetricType_COUNTER && strings.HasSuffix(name, "_total") {
compliantName = compliantName + "_total"
}
for _, metric := range in.Metric {
switch metricType {
case dto.MetricType_COUNTER:
if strings.HasSuffix(name, "_total") {
compliantName = compliantName + "_total"
}
if metric.Counter == nil {
return written, fmt.Errorf(
"expected counter in metric %s %s", compliantName, metric,
Expand Down
49 changes: 49 additions & 0 deletions expfmt/openmetrics_create_test.go
Expand Up @@ -694,6 +694,55 @@ request_duration_microseconds_count 2693
options: []EncoderOption{WithUnit()},
out: `# HELP name doc string
# TYPE name counter
`,
},
// 18: Counter, timestamp given, unit opted in, _total suffix.
{
in: &dto.MetricFamily{
Name: proto.String("some_measure_total"),
Help: proto.String("some testing measurement"),
Type: dto.MetricType_COUNTER.Enum(),
Unit: proto.String("seconds"),
Metric: []*dto.Metric{
{
Label: []*dto.LabelPair{
{
Name: proto.String("labelname"),
Value: proto.String("val1"),
},
{
Name: proto.String("basename"),
Value: proto.String("basevalue"),
},
},
Counter: &dto.Counter{
Value: proto.Float64(42),
},
},
{
Label: []*dto.LabelPair{
{
Name: proto.String("labelname"),
Value: proto.String("val2"),
},
{
Name: proto.String("basename"),
Value: proto.String("basevalue"),
},
},
Counter: &dto.Counter{
Value: proto.Float64(.23),
},
TimestampMs: proto.Int64(1234567890),
},
},
},
options: []EncoderOption{WithUnit()},
out: `# HELP some_measure_seconds some testing measurement
# TYPE some_measure_seconds counter
# UNIT some_measure_seconds seconds
some_measure_seconds_total{labelname="val1",basename="basevalue"} 42.0
some_measure_seconds_total{labelname="val2",basename="basevalue"} 0.23 1.23456789e+06
`,
},
}
Expand Down
2 changes: 1 addition & 1 deletion promlog/log.go
Expand Up @@ -36,7 +36,7 @@ var (
)

LevelFlagOptions = []string{"debug", "info", "warn", "error"}
FormatFlagOptions = []string{"logfmt, json"}
FormatFlagOptions = []string{"logfmt", "json"}
)

// AllowedLevel is a settable identifier for the minimum level a log entry
Expand Down

0 comments on commit cc797da

Please sign in to comment.