change set md

This commit is contained in:
Gorbunov Kirill Andreevich 2024-03-18 16:59:17 +03:00
parent 364077e72d
commit 4ec60dbb5b

View File

@ -44,6 +44,7 @@ type Options struct {
Meter meter.Meter Meter meter.Meter
Name string Name string
MeterOptions []meter.Option MeterOptions []meter.Option
DisableCompress bool
} }
func Meter(m meter.Meter) Option { func Meter(m meter.Meter) Option {
@ -58,6 +59,12 @@ func Name(name string) Option {
} }
} }
func DisableCompress(g bool) Option {
return func(o *Options) {
o.DisableCompress = g
}
}
func MeterOptions(opts ...meter.Option) Option { func MeterOptions(opts ...meter.Option) Option {
return func(o *Options) { return func(o *Options) {
o.MeterOptions = append(o.MeterOptions, opts...) o.MeterOptions = append(o.MeterOptions, opts...)
@ -65,7 +72,7 @@ func MeterOptions(opts ...meter.Option) Option {
} }
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{Meter: meter.DefaultMeter} options := Options{Meter: meter.DefaultMeter, DisableCompress: false}
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
@ -89,8 +96,9 @@ func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb.
w := io.Writer(buf) w := io.Writer(buf)
if md, ok := metadata.FromOutgoingContext(ctx); gzipAccepted(md) && ok { if md, ok := metadata.FromOutgoingContext(ctx); gzipAccepted(md) && ok && !h.opts.DisableCompress {
md.Set(contentEncodingHeader, "gzip")) omd, _ := metadata.FromOutgoingContext(ctx)
omd.Set(contentEncodingHeader, "gzip")
gz := gzipPool.Get().(*gzip.Writer) gz := gzipPool.Get().(*gzip.Writer)
defer gzipPool.Put(gz) defer gzipPool.Put(gz)