Fix: Change TTFB metric type to histogram (#20999)

This commit is contained in:
iamsagar99 2025-04-02 11:33:58 +05:45 committed by GitHub
parent 4041a8727c
commit 8d223e07fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 5 deletions

View File

@ -319,6 +319,7 @@ type MetricDescription struct {
Name MetricName `json:"MetricName"` Name MetricName `json:"MetricName"`
Help string `json:"Help"` Help string `json:"Help"`
Type MetricTypeV2 `json:"Type"` Type MetricTypeV2 `json:"Type"`
Buckets []float64 `json:"Buckets,omitempty"`
} }
// MetricV2 captures the details for a metric // MetricV2 captures the details for a metric
@ -1543,7 +1544,8 @@ func getS3TTFBDistributionMD() MetricDescription {
Subsystem: ttfbSubsystem, Subsystem: ttfbSubsystem,
Name: ttfbDistribution, Name: ttfbDistribution,
Help: "Distribution of time to first byte across API calls", Help: "Distribution of time to first byte across API calls",
Type: gaugeMetric, Type: histogramMetric,
Buckets: []float64{0.01, 0.05, 0.1, 0.5, 1.0, 2.0, 5.0},
} }
} }
@ -1553,7 +1555,8 @@ func getBucketTTFBDistributionMD() MetricDescription {
Subsystem: ttfbSubsystem, Subsystem: ttfbSubsystem,
Name: ttfbDistribution, Name: ttfbDistribution,
Help: "Distribution of time to first byte across API calls per bucket", Help: "Distribution of time to first byte across API calls per bucket",
Type: gaugeMetric, Type: histogramMetric,
Buckets: []float64{0.01, 0.05, 0.1, 0.5, 1.0, 2.0, 5.0},
} }
} }

View File

@ -9,9 +9,9 @@ import (
// MarshalMsg implements msgp.Marshaler // MarshalMsg implements msgp.Marshaler
func (z *MetricDescription) MarshalMsg(b []byte) (o []byte, err error) { func (z *MetricDescription) MarshalMsg(b []byte) (o []byte, err error) {
o = msgp.Require(b, z.Msgsize()) o = msgp.Require(b, z.Msgsize())
// map header, size 5 // map header, size 6
// string "Namespace" // string "Namespace"
o = append(o, 0x85, 0xa9, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65) o = append(o, 0x86, 0xa9, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65)
o = msgp.AppendString(o, string(z.Namespace)) o = msgp.AppendString(o, string(z.Namespace))
// string "Subsystem" // string "Subsystem"
o = append(o, 0xa9, 0x53, 0x75, 0x62, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d) o = append(o, 0xa9, 0x53, 0x75, 0x62, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d)
@ -25,6 +25,12 @@ func (z *MetricDescription) MarshalMsg(b []byte) (o []byte, err error) {
// string "Type" // string "Type"
o = append(o, 0xa4, 0x54, 0x79, 0x70, 0x65) o = append(o, 0xa4, 0x54, 0x79, 0x70, 0x65)
o = msgp.AppendString(o, string(z.Type)) o = msgp.AppendString(o, string(z.Type))
// string "Buckets"
o = append(o, 0xa7, 0x42, 0x75, 0x63, 0x6b, 0x65, 0x74, 0x73)
o = msgp.AppendArrayHeader(o, uint32(len(z.Buckets)))
for za0001 := range z.Buckets {
o = msgp.AppendFloat64(o, z.Buckets[za0001])
}
return return
} }
@ -92,6 +98,25 @@ func (z *MetricDescription) UnmarshalMsg(bts []byte) (o []byte, err error) {
} }
z.Type = MetricTypeV2(zb0005) z.Type = MetricTypeV2(zb0005)
} }
case "Buckets":
var zb0006 uint32
zb0006, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Buckets")
return
}
if cap(z.Buckets) >= int(zb0006) {
z.Buckets = (z.Buckets)[:zb0006]
} else {
z.Buckets = make([]float64, zb0006)
}
for za0001 := range z.Buckets {
z.Buckets[za0001], bts, err = msgp.ReadFloat64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Buckets", za0001)
return
}
}
default: default:
bts, err = msgp.Skip(bts) bts, err = msgp.Skip(bts)
if err != nil { if err != nil {
@ -106,7 +131,7 @@ func (z *MetricDescription) UnmarshalMsg(bts []byte) (o []byte, err error) {
// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (z *MetricDescription) Msgsize() (s int) { func (z *MetricDescription) Msgsize() (s int) {
s = 1 + 10 + msgp.StringPrefixSize + len(string(z.Namespace)) + 10 + msgp.StringPrefixSize + len(string(z.Subsystem)) + 5 + msgp.StringPrefixSize + len(string(z.Name)) + 5 + msgp.StringPrefixSize + len(z.Help) + 5 + msgp.StringPrefixSize + len(string(z.Type)) s = 1 + 10 + msgp.StringPrefixSize + len(string(z.Namespace)) + 10 + msgp.StringPrefixSize + len(string(z.Subsystem)) + 5 + msgp.StringPrefixSize + len(string(z.Name)) + 5 + msgp.StringPrefixSize + len(z.Help) + 5 + msgp.StringPrefixSize + len(string(z.Type)) + 8 + msgp.ArrayHeaderSize + (len(z.Buckets) * (msgp.Float64Size))
return return
} }