From 4b1177e49d7c8accc4453d4ebf2c53cb3015010f Mon Sep 17 00:00:00 2001 From: Robert Fratto Date: Mon, 29 Apr 2024 12:16:03 -0400 Subject: [PATCH] misc: switch to new units package This switches everything over to the new units package. --- .../common/loki/client/queue_client_test.go | 10 +++++----- internal/component/faro/receiver/arguments.go | 6 +++--- .../component/faro/receiver/handler_test.go | 6 +++--- internal/component/loki/process/stages/drop.go | 18 +++++++++--------- .../component/loki/process/stages/drop_test.go | 4 ++-- internal/component/loki/write/types.go | 12 ++++++------ internal/component/otelcol/config_grpc.go | 14 +++++++------- internal/component/otelcol/config_http.go | 10 +++++----- .../exporter/loadbalancing/loadbalancing.go | 6 +++--- .../processor/memorylimiter/memorylimiter.go | 12 ++++++------ .../otelcol/receiver/jaeger/jaeger.go | 16 ++++++++-------- .../otelcol/receiver/opencensus/opencensus.go | 2 +- .../component/otelcol/receiver/otlp/otlp.go | 2 +- internal/component/prometheus/scrape/scrape.go | 7 ++++--- .../otelcolconvert/converter_jaegerreceiver.go | 6 +++--- .../converter_loadbalancingexporter.go | 6 +++--- .../converter_memorylimiterprocessor.go | 6 +++--- .../otelcolconvert/converter_otlpexporter.go | 6 +++--- .../converter_otlphttpexporter.go | 6 +++--- .../otelcolconvert/converter_otlpreceiver.go | 10 +++++----- .../otelcolconvert/testdata/jaeger.alloy | 4 ++-- .../testdata/jaegerremotesampling.alloy | 4 ++-- .../prometheusconvert/component/scrape.go | 3 ++- .../internal/build/loki_write.go | 6 +++--- .../promtailconvert/internal/build/stages.go | 7 ++++--- .../internal/build/app_agent_receiver.go | 4 ++-- .../testdata-v2/integrations_v2.alloy | 2 +- .../testdata-v2/unsupported.alloy | 2 +- .../staticconvert/testdata/traces.alloy | 2 +- 29 files changed, 101 insertions(+), 98 deletions(-) diff --git a/internal/component/common/loki/client/queue_client_test.go b/internal/component/common/loki/client/queue_client_test.go index 57228150e9..19b110bef9 100644 --- a/internal/component/common/loki/client/queue_client_test.go +++ b/internal/component/common/loki/client/queue_client_test.go @@ -6,11 +6,11 @@ import ( "testing" "time" - "github.com/alecthomas/units" "github.com/go-kit/log" "github.com/grafana/alloy/internal/component/common/loki" "github.com/grafana/alloy/internal/component/common/loki/client/internal" "github.com/grafana/alloy/internal/component/common/loki/utils" + "github.com/grafana/alloy/internal/units" "github.com/grafana/dskit/backoff" "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" @@ -80,10 +80,10 @@ func TestQueueClient(t *testing.T) { "many lines and series, delivery because of batch age": { numLines: 100, numSeries: 10, - batchSize: int(1 * units.MiB), // make batch size big enough so that all batches should be delivered because of batch age + batchSize: int(1 * units.Mebibyte), // make batch size big enough so that all batches should be delivered because of batch age batchWait: time.Millisecond * 50, queueConfig: QueueConfig{ - Capacity: int(100 * units.MiB), // keep buffered channel size on 100 + Capacity: int(100 * units.Mebibyte), // keep buffered channel size on 100 DrainTimeout: 10 * time.Second, }, expectedRWReqsCount: 1, // expect all entries to be sent in a single batch (100 * < 10B per line) < 1MiB @@ -196,10 +196,10 @@ func BenchmarkClientImplementations(b *testing.B) { "100k entries, 100 series, default batching": { numLines: 100_000, numSeries: 100, - batchSize: int(1 * units.MiB), + batchSize: int(1 * units.Mebibyte), batchWait: time.Second, queueConfig: QueueConfig{ - Capacity: int(10 * units.MiB), // buffer size 100 + Capacity: int(10 * units.Mebibyte), // buffer size 100 DrainTimeout: 5 * time.Second, }, }, diff --git a/internal/component/faro/receiver/arguments.go b/internal/component/faro/receiver/arguments.go index 915f472574..0cf85149cc 100644 --- a/internal/component/faro/receiver/arguments.go +++ b/internal/component/faro/receiver/arguments.go @@ -3,9 +3,9 @@ package receiver import ( "time" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/common/loki" "github.com/grafana/alloy/internal/component/otelcol" + "github.com/grafana/alloy/internal/units" "github.com/grafana/alloy/syntax" "github.com/grafana/alloy/syntax/alloytypes" ) @@ -34,7 +34,7 @@ type ServerArguments struct { Port int `alloy:"listen_port,attr,optional"` CORSAllowedOrigins []string `alloy:"cors_allowed_origins,attr,optional"` APIKey alloytypes.Secret `alloy:"api_key,attr,optional"` - MaxAllowedPayloadSize units.Base2Bytes `alloy:"max_allowed_payload_size,attr,optional"` + MaxAllowedPayloadSize units.Bytes `alloy:"max_allowed_payload_size,attr,optional"` RateLimiting RateLimitingArguments `alloy:"rate_limiting,block,optional"` IncludeMetadata bool `alloy:"include_metadata,attr,optional"` @@ -44,7 +44,7 @@ func (s *ServerArguments) SetToDefault() { *s = ServerArguments{ Host: "127.0.0.1", Port: 12347, - MaxAllowedPayloadSize: 5 * units.MiB, + MaxAllowedPayloadSize: 5 * units.Mebibyte, } s.RateLimiting.SetToDefault() } diff --git a/internal/component/faro/receiver/handler_test.go b/internal/component/faro/receiver/handler_test.go index 228b8c87cd..f03f8ff45f 100644 --- a/internal/component/faro/receiver/handler_test.go +++ b/internal/component/faro/receiver/handler_test.go @@ -8,8 +8,8 @@ import ( "strings" "testing" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/faro/receiver/internal/payload" + "github.com/grafana/alloy/internal/units" "github.com/grafana/alloy/internal/util" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" @@ -108,7 +108,7 @@ func TestPayloadWithinLimit(t *testing.T) { ) h.Update(ServerArguments{ - MaxAllowedPayloadSize: units.Base2Bytes(len(emptyPayload)), + MaxAllowedPayloadSize: units.Bytes(len(emptyPayload)), }) req, err := http.NewRequest(http.MethodPost, "/collect", strings.NewReader(emptyPayload)) @@ -134,7 +134,7 @@ func TestPayloadTooLarge(t *testing.T) { ) h.Update(ServerArguments{ - MaxAllowedPayloadSize: units.Base2Bytes(len(emptyPayload) - 1), + MaxAllowedPayloadSize: units.Bytes(len(emptyPayload) - 1), }) req, err := http.NewRequest(http.MethodPost, "/collect", strings.NewReader(emptyPayload)) diff --git a/internal/component/loki/process/stages/drop.go b/internal/component/loki/process/stages/drop.go index fae4c4559e..f44fea7975 100644 --- a/internal/component/loki/process/stages/drop.go +++ b/internal/component/loki/process/stages/drop.go @@ -8,9 +8,9 @@ import ( "strings" "time" - "github.com/alecthomas/units" "github.com/go-kit/log" "github.com/grafana/alloy/internal/alloy/logging/level" + "github.com/grafana/alloy/internal/units" "github.com/prometheus/client_golang/prometheus" ) @@ -25,18 +25,18 @@ var ( defaultDropReason = "drop_stage" defaultSeparator = ";" emptyDuration time.Duration - emptySize units.Base2Bytes + emptySize units.Bytes ) // DropConfig contains the configuration for a dropStage type DropConfig struct { - DropReason string `alloy:"drop_counter_reason,attr,optional"` - Source string `alloy:"source,attr,optional"` - Value string `alloy:"value,attr,optional"` - Separator string `alloy:"separator,attr,optional"` - Expression string `alloy:"expression,attr,optional"` - OlderThan time.Duration `alloy:"older_than,attr,optional"` - LongerThan units.Base2Bytes `alloy:"longer_than,attr,optional"` + DropReason string `alloy:"drop_counter_reason,attr,optional"` + Source string `alloy:"source,attr,optional"` + Value string `alloy:"value,attr,optional"` + Separator string `alloy:"separator,attr,optional"` + Expression string `alloy:"expression,attr,optional"` + OlderThan time.Duration `alloy:"older_than,attr,optional"` + LongerThan units.Bytes `alloy:"longer_than,attr,optional"` regex *regexp.Regexp } diff --git a/internal/component/loki/process/stages/drop_test.go b/internal/component/loki/process/stages/drop_test.go index 736ddfe5d1..38f61a4b4f 100644 --- a/internal/component/loki/process/stages/drop_test.go +++ b/internal/component/loki/process/stages/drop_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/alecthomas/units" + "github.com/grafana/alloy/internal/units" "github.com/grafana/alloy/internal/util" dskit "github.com/grafana/dskit/server" "github.com/prometheus/client_golang/prometheus" @@ -48,7 +48,7 @@ func Test_dropStage_Process(t *testing.T) { require.Nil(t, cfg.LogLevel.Set("debug")) Debug = true - tenBytes, _ := units.ParseBase2Bytes("10B") + tenBytes := 10 * units.Byte oneHour := 1 * time.Hour tests := []struct { diff --git a/internal/component/loki/write/types.go b/internal/component/loki/write/types.go index 9bfb9880be..ae6263ee56 100644 --- a/internal/component/loki/write/types.go +++ b/internal/component/loki/write/types.go @@ -7,8 +7,8 @@ import ( "github.com/grafana/alloy/internal/component/common/loki/client" "github.com/grafana/alloy/internal/component/common/loki/utils" + "github.com/grafana/alloy/internal/units" - "github.com/alecthomas/units" types "github.com/grafana/alloy/internal/component/common/config" "github.com/grafana/dskit/backoff" "github.com/grafana/dskit/flagext" @@ -20,7 +20,7 @@ type EndpointOptions struct { Name string `alloy:"name,attr,optional"` URL string `alloy:"url,attr"` BatchWait time.Duration `alloy:"batch_wait,attr,optional"` - BatchSize units.Base2Bytes `alloy:"batch_size,attr,optional"` + BatchSize units.Bytes `alloy:"batch_size,attr,optional"` RemoteTimeout time.Duration `alloy:"remote_timeout,attr,optional"` Headers map[string]string `alloy:"headers,attr,optional"` MinBackoff time.Duration `alloy:"min_backoff_period,attr,optional"` // start backoff at this level @@ -40,7 +40,7 @@ type EndpointOptions struct { func GetDefaultEndpointOptions() EndpointOptions { var defaultEndpointOptions = EndpointOptions{ BatchWait: 1 * time.Second, - BatchSize: 1 * units.MiB, + BatchSize: 1 * units.Mebibyte, RemoteTimeout: 10 * time.Second, MinBackoff: 500 * time.Millisecond, MaxBackoff: 5 * time.Minute, @@ -74,14 +74,14 @@ func (r *EndpointOptions) Validate() error { // QueueConfig controls how the queue logs remote write client is configured. Note that this client is only used when the // loki.write component has WAL support enabled. type QueueConfig struct { - Capacity units.Base2Bytes `alloy:"capacity,attr,optional"` - DrainTimeout time.Duration `alloy:"drain_timeout,attr,optional"` + Capacity units.Bytes `alloy:"capacity,attr,optional"` + DrainTimeout time.Duration `alloy:"drain_timeout,attr,optional"` } // SetToDefault implements syntax.Defaulter. func (q *QueueConfig) SetToDefault() { *q = QueueConfig{ - Capacity: 10 * units.MiB, // considering the default BatchSize of 1MiB, this gives us a default buffered channel of size 10 + Capacity: 10 * units.Mebibyte, // considering the default BatchSize of 1MiB, this gives us a default buffered channel of size 10 DrainTimeout: 15 * time.Second, } } diff --git a/internal/component/otelcol/config_grpc.go b/internal/component/otelcol/config_grpc.go index 44d263f512..903841f0f4 100644 --- a/internal/component/otelcol/config_grpc.go +++ b/internal/component/otelcol/config_grpc.go @@ -3,8 +3,8 @@ package otelcol import ( "time" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/otelcol/auth" + "github.com/grafana/alloy/internal/units" otelcomponent "go.opentelemetry.io/collector/component" otelconfigauth "go.opentelemetry.io/collector/config/configauth" otelconfiggrpc "go.opentelemetry.io/collector/config/configgrpc" @@ -23,10 +23,10 @@ type GRPCServerArguments struct { TLS *TLSServerArguments `alloy:"tls,block,optional"` - MaxRecvMsgSize units.Base2Bytes `alloy:"max_recv_msg_size,attr,optional"` - MaxConcurrentStreams uint32 `alloy:"max_concurrent_streams,attr,optional"` - ReadBufferSize units.Base2Bytes `alloy:"read_buffer_size,attr,optional"` - WriteBufferSize units.Base2Bytes `alloy:"write_buffer_size,attr,optional"` + MaxRecvMsgSize units.Bytes `alloy:"max_recv_msg_size,attr,optional"` + MaxConcurrentStreams uint32 `alloy:"max_concurrent_streams,attr,optional"` + ReadBufferSize units.Bytes `alloy:"read_buffer_size,attr,optional"` + WriteBufferSize units.Bytes `alloy:"write_buffer_size,attr,optional"` Keepalive *KeepaliveServerArguments `alloy:"keepalive,block,optional"` @@ -141,8 +141,8 @@ type GRPCClientArguments struct { TLS TLSClientArguments `alloy:"tls,block,optional"` Keepalive *KeepaliveClientArguments `alloy:"keepalive,block,optional"` - ReadBufferSize units.Base2Bytes `alloy:"read_buffer_size,attr,optional"` - WriteBufferSize units.Base2Bytes `alloy:"write_buffer_size,attr,optional"` + ReadBufferSize units.Bytes `alloy:"read_buffer_size,attr,optional"` + WriteBufferSize units.Bytes `alloy:"write_buffer_size,attr,optional"` WaitForReady bool `alloy:"wait_for_ready,attr,optional"` Headers map[string]string `alloy:"headers,attr,optional"` BalancerName string `alloy:"balancer_name,attr,optional"` diff --git a/internal/component/otelcol/config_http.go b/internal/component/otelcol/config_http.go index b6185c8861..0cfd291d6d 100644 --- a/internal/component/otelcol/config_http.go +++ b/internal/component/otelcol/config_http.go @@ -3,8 +3,8 @@ package otelcol import ( "time" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/otelcol/auth" + "github.com/grafana/alloy/internal/units" otelcomponent "go.opentelemetry.io/collector/component" otelconfigauth "go.opentelemetry.io/collector/config/configauth" otelconfighttp "go.opentelemetry.io/collector/config/confighttp" @@ -29,8 +29,8 @@ type HTTPServerArguments struct { // We will need to generally figure out how we want to provide common // authentication extensions to all of our components. - MaxRequestBodySize units.Base2Bytes `alloy:"max_request_body_size,attr,optional"` - IncludeMetadata bool `alloy:"include_metadata,attr,optional"` + MaxRequestBodySize units.Bytes `alloy:"max_request_body_size,attr,optional"` + IncludeMetadata bool `alloy:"include_metadata,attr,optional"` } // Convert converts args into the upstream type. @@ -80,8 +80,8 @@ type HTTPClientArguments struct { TLS TLSClientArguments `alloy:"tls,block,optional"` - ReadBufferSize units.Base2Bytes `alloy:"read_buffer_size,attr,optional"` - WriteBufferSize units.Base2Bytes `alloy:"write_buffer_size,attr,optional"` + ReadBufferSize units.Bytes `alloy:"read_buffer_size,attr,optional"` + WriteBufferSize units.Bytes `alloy:"write_buffer_size,attr,optional"` Timeout time.Duration `alloy:"timeout,attr,optional"` Headers map[string]string `alloy:"headers,attr,optional"` // CustomRoundTripper func(next http.RoundTripper) (http.RoundTripper, error) TODO (@tpaschalis) diff --git a/internal/component/otelcol/exporter/loadbalancing/loadbalancing.go b/internal/component/otelcol/exporter/loadbalancing/loadbalancing.go index 6cfe6837b7..36e1f07c1b 100644 --- a/internal/component/otelcol/exporter/loadbalancing/loadbalancing.go +++ b/internal/component/otelcol/exporter/loadbalancing/loadbalancing.go @@ -5,12 +5,12 @@ import ( "fmt" "time" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/auth" "github.com/grafana/alloy/internal/component/otelcol/exporter" "github.com/grafana/alloy/internal/featuregate" + "github.com/grafana/alloy/internal/units" "github.com/grafana/alloy/syntax" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter" otelcomponent "go.opentelemetry.io/collector/component" @@ -245,8 +245,8 @@ type GRPCClientArguments struct { TLS otelcol.TLSClientArguments `alloy:"tls,block,optional"` Keepalive *otelcol.KeepaliveClientArguments `alloy:"keepalive,block,optional"` - ReadBufferSize units.Base2Bytes `alloy:"read_buffer_size,attr,optional"` - WriteBufferSize units.Base2Bytes `alloy:"write_buffer_size,attr,optional"` + ReadBufferSize units.Bytes `alloy:"read_buffer_size,attr,optional"` + WriteBufferSize units.Bytes `alloy:"write_buffer_size,attr,optional"` WaitForReady bool `alloy:"wait_for_ready,attr,optional"` Headers map[string]string `alloy:"headers,attr,optional"` BalancerName string `alloy:"balancer_name,attr,optional"` diff --git a/internal/component/otelcol/processor/memorylimiter/memorylimiter.go b/internal/component/otelcol/processor/memorylimiter/memorylimiter.go index ab4bf79166..4d6d57c471 100644 --- a/internal/component/otelcol/processor/memorylimiter/memorylimiter.go +++ b/internal/component/otelcol/processor/memorylimiter/memorylimiter.go @@ -5,11 +5,11 @@ import ( "fmt" "time" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/processor" "github.com/grafana/alloy/internal/featuregate" + "github.com/grafana/alloy/internal/units" otelcomponent "go.opentelemetry.io/collector/component" otelextension "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/processor/memorylimiterprocessor" @@ -31,11 +31,11 @@ func init() { // Arguments configures the otelcol.processor.memory_limiter component. type Arguments struct { - CheckInterval time.Duration `alloy:"check_interval,attr"` - MemoryLimit units.Base2Bytes `alloy:"limit,attr,optional"` - MemorySpikeLimit units.Base2Bytes `alloy:"spike_limit,attr,optional"` - MemoryLimitPercentage uint32 `alloy:"limit_percentage,attr,optional"` - MemorySpikePercentage uint32 `alloy:"spike_limit_percentage,attr,optional"` + CheckInterval time.Duration `alloy:"check_interval,attr"` + MemoryLimit units.Bytes `alloy:"limit,attr,optional"` + MemorySpikeLimit units.Bytes `alloy:"spike_limit,attr,optional"` + MemoryLimitPercentage uint32 `alloy:"limit_percentage,attr,optional"` + MemorySpikePercentage uint32 `alloy:"spike_limit_percentage,attr,optional"` // Output configures where to send processed data. Required. Output *otelcol.ConsumerArguments `alloy:"output,block"` diff --git a/internal/component/otelcol/receiver/jaeger/jaeger.go b/internal/component/otelcol/receiver/jaeger/jaeger.go index 47f9f01906..7137a8f9db 100644 --- a/internal/component/otelcol/receiver/jaeger/jaeger.go +++ b/internal/component/otelcol/receiver/jaeger/jaeger.go @@ -4,11 +4,11 @@ package jaeger import ( "fmt" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/receiver" "github.com/grafana/alloy/internal/featuregate" + "github.com/grafana/alloy/internal/units" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver" otelcomponent "go.opentelemetry.io/collector/component" otelconfiggrpc "go.opentelemetry.io/collector/config/configgrpc" @@ -144,11 +144,11 @@ func (args *ThriftHTTP) Convert() *otelconfighttp.ServerConfig { // ProtocolUDP configures a UDP server. type ProtocolUDP struct { - Endpoint string `alloy:"endpoint,attr,optional"` - QueueSize int `alloy:"queue_size,attr,optional"` - MaxPacketSize units.Base2Bytes `alloy:"max_packet_size,attr,optional"` - Workers int `alloy:"workers,attr,optional"` - SocketBufferSize units.Base2Bytes `alloy:"socket_buffer_size,attr,optional"` + Endpoint string `alloy:"endpoint,attr,optional"` + QueueSize int `alloy:"queue_size,attr,optional"` + MaxPacketSize units.Bytes `alloy:"max_packet_size,attr,optional"` + Workers int `alloy:"workers,attr,optional"` + SocketBufferSize units.Bytes `alloy:"socket_buffer_size,attr,optional"` } // Convert converts proto into the upstream type. @@ -179,7 +179,7 @@ func (args *ThriftCompact) SetToDefault() { ProtocolUDP: &ProtocolUDP{ Endpoint: "0.0.0.0:6831", QueueSize: 1_000, - MaxPacketSize: 65 * units.KiB, + MaxPacketSize: 65 * units.Kibibyte, Workers: 10, }, } @@ -205,7 +205,7 @@ func (args *ThriftBinary) SetToDefault() { ProtocolUDP: &ProtocolUDP{ Endpoint: "0.0.0.0:6832", QueueSize: 1_000, - MaxPacketSize: 65 * units.KiB, + MaxPacketSize: 65 * units.Kibibyte, Workers: 10, }, } diff --git a/internal/component/otelcol/receiver/opencensus/opencensus.go b/internal/component/otelcol/receiver/opencensus/opencensus.go index 06e1b199d4..f8c527f926 100644 --- a/internal/component/otelcol/receiver/opencensus/opencensus.go +++ b/internal/component/otelcol/receiver/opencensus/opencensus.go @@ -2,11 +2,11 @@ package opencensus import ( - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/receiver" "github.com/grafana/alloy/internal/featuregate" + "github.com/grafana/alloy/internal/units" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/opencensusreceiver" otelcomponent "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/extension" diff --git a/internal/component/otelcol/receiver/otlp/otlp.go b/internal/component/otelcol/receiver/otlp/otlp.go index 9278cf1c78..daa570d9c4 100644 --- a/internal/component/otelcol/receiver/otlp/otlp.go +++ b/internal/component/otelcol/receiver/otlp/otlp.go @@ -5,11 +5,11 @@ import ( "fmt" net_url "net/url" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/receiver" "github.com/grafana/alloy/internal/featuregate" + "github.com/grafana/alloy/internal/units" otelcomponent "go.opentelemetry.io/collector/component" otelextension "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/receiver/otlpreceiver" diff --git a/internal/component/prometheus/scrape/scrape.go b/internal/component/prometheus/scrape/scrape.go index 75f1933240..f8e9f110da 100644 --- a/internal/component/prometheus/scrape/scrape.go +++ b/internal/component/prometheus/scrape/scrape.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/alecthomas/units" + alecthomas_units "github.com/alecthomas/units" "github.com/grafana/alloy/internal/alloy/logging/level" "github.com/grafana/alloy/internal/component" component_config "github.com/grafana/alloy/internal/component/common/config" @@ -17,6 +17,7 @@ import ( "github.com/grafana/alloy/internal/service/cluster" "github.com/grafana/alloy/internal/service/http" "github.com/grafana/alloy/internal/service/labelstore" + "github.com/grafana/alloy/internal/units" "github.com/grafana/alloy/internal/useragent" client_prometheus "github.com/prometheus/client_golang/prometheus" config_util "github.com/prometheus/common/config" @@ -69,7 +70,7 @@ type Arguments struct { Scheme string `alloy:"scheme,attr,optional"` // An uncompressed response body larger than this many bytes will cause the // scrape to fail. 0 means no limit. - BodySizeLimit units.Base2Bytes `alloy:"body_size_limit,attr,optional"` + BodySizeLimit units.Bytes `alloy:"body_size_limit,attr,optional"` // More than this many samples post metric-relabeling will cause the scrape // to fail. SampleLimit uint `alloy:"sample_limit,attr,optional"` @@ -299,7 +300,7 @@ func getPromScrapeConfigs(jobName string, c Arguments) *config.ScrapeConfig { dec.ScrapeTimeout = model.Duration(c.ScrapeTimeout) dec.MetricsPath = c.MetricsPath dec.Scheme = c.Scheme - dec.BodySizeLimit = c.BodySizeLimit + dec.BodySizeLimit = alecthomas_units.Base2Bytes(c.BodySizeLimit) dec.SampleLimit = c.SampleLimit dec.TargetLimit = c.TargetLimit dec.LabelLimit = c.LabelLimit diff --git a/internal/converter/internal/otelcolconvert/converter_jaegerreceiver.go b/internal/converter/internal/otelcolconvert/converter_jaegerreceiver.go index fc3a85d43d..aa8ef2622d 100644 --- a/internal/converter/internal/otelcolconvert/converter_jaegerreceiver.go +++ b/internal/converter/internal/otelcolconvert/converter_jaegerreceiver.go @@ -3,11 +3,11 @@ package otelcolconvert import ( "fmt" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/receiver/jaeger" "github.com/grafana/alloy/internal/converter/diag" "github.com/grafana/alloy/internal/converter/internal/common" + "github.com/grafana/alloy/internal/units" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configgrpc" @@ -91,9 +91,9 @@ func toJaegerProtocolUDPArguments(cfg *jaegerreceiver.ProtocolUDP) *jaeger.Proto return &jaeger.ProtocolUDP{ Endpoint: cfg.Endpoint, QueueSize: cfg.QueueSize, - MaxPacketSize: units.Base2Bytes(cfg.MaxPacketSize), + MaxPacketSize: units.Bytes(cfg.MaxPacketSize), Workers: cfg.Workers, - SocketBufferSize: units.Base2Bytes(cfg.SocketBufferSize), + SocketBufferSize: units.Bytes(cfg.SocketBufferSize), } } diff --git a/internal/converter/internal/otelcolconvert/converter_loadbalancingexporter.go b/internal/converter/internal/otelcolconvert/converter_loadbalancingexporter.go index 870daed953..f81b88b23e 100644 --- a/internal/converter/internal/otelcolconvert/converter_loadbalancingexporter.go +++ b/internal/converter/internal/otelcolconvert/converter_loadbalancingexporter.go @@ -4,12 +4,12 @@ import ( "fmt" "strings" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/auth" "github.com/grafana/alloy/internal/component/otelcol/exporter/loadbalancing" "github.com/grafana/alloy/internal/converter/diag" "github.com/grafana/alloy/internal/converter/internal/common" + "github.com/grafana/alloy/internal/units" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter" "go.opentelemetry.io/collector/component" ) @@ -93,8 +93,8 @@ func toProtocol(cfg loadbalancingexporter.Protocol) loadbalancing.Protocol { TLS: toTLSClientArguments(cfg.OTLP.TLSSetting), Keepalive: toKeepaliveClientArguments(cfg.OTLP.Keepalive), - ReadBufferSize: units.Base2Bytes(cfg.OTLP.ReadBufferSize), - WriteBufferSize: units.Base2Bytes(cfg.OTLP.WriteBufferSize), + ReadBufferSize: units.Bytes(cfg.OTLP.ReadBufferSize), + WriteBufferSize: units.Bytes(cfg.OTLP.WriteBufferSize), WaitForReady: cfg.OTLP.WaitForReady, Headers: toHeadersMap(cfg.OTLP.Headers), BalancerName: balancerName, diff --git a/internal/converter/internal/otelcolconvert/converter_memorylimiterprocessor.go b/internal/converter/internal/otelcolconvert/converter_memorylimiterprocessor.go index 36293f99cb..9572d868f6 100644 --- a/internal/converter/internal/otelcolconvert/converter_memorylimiterprocessor.go +++ b/internal/converter/internal/otelcolconvert/converter_memorylimiterprocessor.go @@ -3,11 +3,11 @@ package otelcolconvert import ( "fmt" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/processor/memorylimiter" "github.com/grafana/alloy/internal/converter/diag" "github.com/grafana/alloy/internal/converter/internal/common" + "github.com/grafana/alloy/internal/units" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/processor/memorylimiterprocessor" ) @@ -52,8 +52,8 @@ func toMemoryLimiterProcessor(state *State, id component.InstanceID, cfg *memory return &memorylimiter.Arguments{ CheckInterval: cfg.CheckInterval, - MemoryLimit: units.Base2Bytes(cfg.MemoryLimitMiB) * units.MiB, - MemorySpikeLimit: units.Base2Bytes(cfg.MemorySpikeLimitMiB) * units.MiB, + MemoryLimit: units.Bytes(cfg.MemoryLimitMiB) * units.Mebibyte, + MemorySpikeLimit: units.Bytes(cfg.MemorySpikeLimitMiB) * units.Mebibyte, MemoryLimitPercentage: cfg.MemoryLimitPercentage, MemorySpikePercentage: cfg.MemorySpikePercentage, Output: &otelcol.ConsumerArguments{ diff --git a/internal/converter/internal/otelcolconvert/converter_otlpexporter.go b/internal/converter/internal/otelcolconvert/converter_otlpexporter.go index 26a41167a8..406eb838bb 100644 --- a/internal/converter/internal/otelcolconvert/converter_otlpexporter.go +++ b/internal/converter/internal/otelcolconvert/converter_otlpexporter.go @@ -4,12 +4,12 @@ import ( "fmt" "strings" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/auth" "github.com/grafana/alloy/internal/component/otelcol/exporter/otlp" "github.com/grafana/alloy/internal/converter/diag" "github.com/grafana/alloy/internal/converter/internal/common" + "github.com/grafana/alloy/internal/units" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configopaque" @@ -108,8 +108,8 @@ func toGRPCClientArguments(cfg configgrpc.ClientConfig) otelcol.GRPCClientArgume TLS: toTLSClientArguments(cfg.TLSSetting), Keepalive: toKeepaliveClientArguments(cfg.Keepalive), - ReadBufferSize: units.Base2Bytes(cfg.ReadBufferSize), - WriteBufferSize: units.Base2Bytes(cfg.WriteBufferSize), + ReadBufferSize: units.Bytes(cfg.ReadBufferSize), + WriteBufferSize: units.Bytes(cfg.WriteBufferSize), WaitForReady: cfg.WaitForReady, Headers: toHeadersMap(cfg.Headers), BalancerName: balancerName, diff --git a/internal/converter/internal/otelcolconvert/converter_otlphttpexporter.go b/internal/converter/internal/otelcolconvert/converter_otlphttpexporter.go index a4f88d259e..4c49da7e1e 100644 --- a/internal/converter/internal/otelcolconvert/converter_otlphttpexporter.go +++ b/internal/converter/internal/otelcolconvert/converter_otlphttpexporter.go @@ -5,12 +5,12 @@ import ( "strings" "time" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/auth" "github.com/grafana/alloy/internal/component/otelcol/exporter/otlphttp" "github.com/grafana/alloy/internal/converter/diag" "github.com/grafana/alloy/internal/converter/internal/common" + "github.com/grafana/alloy/internal/units" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/exporter/otlphttpexporter" @@ -84,8 +84,8 @@ func toHTTPClientArguments(cfg confighttp.ClientConfig) otelcol.HTTPClientArgume Endpoint: cfg.Endpoint, Compression: otelcol.CompressionType(cfg.Compression), TLS: toTLSClientArguments(cfg.TLSSetting), - ReadBufferSize: units.Base2Bytes(cfg.ReadBufferSize), - WriteBufferSize: units.Base2Bytes(cfg.WriteBufferSize), + ReadBufferSize: units.Bytes(cfg.ReadBufferSize), + WriteBufferSize: units.Bytes(cfg.WriteBufferSize), Timeout: cfg.Timeout, Headers: toHeadersMap(cfg.Headers), diff --git a/internal/converter/internal/otelcolconvert/converter_otlpreceiver.go b/internal/converter/internal/otelcolconvert/converter_otlpreceiver.go index d32769f1b1..0c82a66c2b 100644 --- a/internal/converter/internal/otelcolconvert/converter_otlpreceiver.go +++ b/internal/converter/internal/otelcolconvert/converter_otlpreceiver.go @@ -3,11 +3,11 @@ package otelcolconvert import ( "fmt" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/component/otelcol/receiver/otlp" "github.com/grafana/alloy/internal/converter/diag" "github.com/grafana/alloy/internal/converter/internal/common" + "github.com/grafana/alloy/internal/units" "github.com/grafana/alloy/syntax/alloytypes" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configgrpc" @@ -75,10 +75,10 @@ func toGRPCServerArguments(cfg *configgrpc.ServerConfig) *otelcol.GRPCServerArgu TLS: toTLSServerArguments(cfg.TLSSetting), - MaxRecvMsgSize: units.Base2Bytes(cfg.MaxRecvMsgSizeMiB) * units.MiB, + MaxRecvMsgSize: units.Bytes(cfg.MaxRecvMsgSizeMiB) * units.Mebibyte, MaxConcurrentStreams: cfg.MaxConcurrentStreams, - ReadBufferSize: units.Base2Bytes(cfg.ReadBufferSize), - WriteBufferSize: units.Base2Bytes(cfg.WriteBufferSize), + ReadBufferSize: units.Bytes(cfg.ReadBufferSize), + WriteBufferSize: units.Bytes(cfg.WriteBufferSize), Keepalive: toKeepaliveServerArguments(cfg.Keepalive), @@ -177,7 +177,7 @@ func toHTTPServerArguments(cfg *confighttp.ServerConfig) *otelcol.HTTPServerArgu CORS: toCORSArguments(cfg.CORS), - MaxRequestBodySize: units.Base2Bytes(cfg.MaxRequestBodySize), + MaxRequestBodySize: units.Bytes(cfg.MaxRequestBodySize), IncludeMetadata: cfg.IncludeMetadata, } } diff --git a/internal/converter/internal/otelcolconvert/testdata/jaeger.alloy b/internal/converter/internal/otelcolconvert/testdata/jaeger.alloy index a503778318..9bc4a7ae0d 100644 --- a/internal/converter/internal/otelcolconvert/testdata/jaeger.alloy +++ b/internal/converter/internal/otelcolconvert/testdata/jaeger.alloy @@ -5,11 +5,11 @@ otelcol.receiver.jaeger "default" { thrift_http { } thrift_binary { - max_packet_size = "63KiB488B" + max_packet_size = "65kB" } thrift_compact { - max_packet_size = "63KiB488B" + max_packet_size = "65kB" } } diff --git a/internal/converter/internal/otelcolconvert/testdata/jaegerremotesampling.alloy b/internal/converter/internal/otelcolconvert/testdata/jaegerremotesampling.alloy index 5d1efebc69..6bf8cd4825 100644 --- a/internal/converter/internal/otelcolconvert/testdata/jaegerremotesampling.alloy +++ b/internal/converter/internal/otelcolconvert/testdata/jaegerremotesampling.alloy @@ -18,11 +18,11 @@ otelcol.receiver.jaeger "default" { thrift_http { } thrift_binary { - max_packet_size = "63KiB488B" + max_packet_size = "65kB" } thrift_compact { - max_packet_size = "63KiB488B" + max_packet_size = "65kB" } } diff --git a/internal/converter/internal/prometheusconvert/component/scrape.go b/internal/converter/internal/prometheusconvert/component/scrape.go index a5f6da29ad..bce1f327b1 100644 --- a/internal/converter/internal/prometheusconvert/component/scrape.go +++ b/internal/converter/internal/prometheusconvert/component/scrape.go @@ -13,6 +13,7 @@ import ( "github.com/grafana/alloy/internal/converter/internal/common" "github.com/grafana/alloy/internal/converter/internal/prometheusconvert/build" "github.com/grafana/alloy/internal/service/cluster" + "github.com/grafana/alloy/internal/units" prom_config "github.com/prometheus/prometheus/config" prom_discovery "github.com/prometheus/prometheus/discovery" "github.com/prometheus/prometheus/storage" @@ -59,7 +60,7 @@ func toScrapeArguments(scrapeConfig *prom_config.ScrapeConfig, forwardTo []stora ScrapeTimeout: time.Duration(scrapeConfig.ScrapeTimeout), MetricsPath: scrapeConfig.MetricsPath, Scheme: scrapeConfig.Scheme, - BodySizeLimit: scrapeConfig.BodySizeLimit, + BodySizeLimit: units.Bytes(scrapeConfig.BodySizeLimit), SampleLimit: scrapeConfig.SampleLimit, TargetLimit: scrapeConfig.TargetLimit, LabelLimit: scrapeConfig.LabelLimit, diff --git a/internal/converter/internal/promtailconvert/internal/build/loki_write.go b/internal/converter/internal/promtailconvert/internal/build/loki_write.go index 208249f843..23f08b9e76 100644 --- a/internal/converter/internal/promtailconvert/internal/build/loki_write.go +++ b/internal/converter/internal/promtailconvert/internal/build/loki_write.go @@ -3,11 +3,11 @@ package build import ( "fmt" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/common/loki" lokiwrite "github.com/grafana/alloy/internal/component/loki/write" "github.com/grafana/alloy/internal/converter/diag" "github.com/grafana/alloy/internal/converter/internal/common" + "github.com/grafana/alloy/internal/units" "github.com/grafana/alloy/syntax/token/builder" "github.com/grafana/loki/clients/pkg/promtail/client" lokiflag "github.com/grafana/loki/pkg/util/flagext" @@ -29,8 +29,8 @@ func NewLokiWrite(client *client.Config, diags *diag.Diagnostics, index int, lab } func toLokiWriteArguments(config *client.Config, diags *diag.Diagnostics) *lokiwrite.Arguments { - batchSize, err := units.ParseBase2Bytes(fmt.Sprintf("%dB", config.BatchSize)) - if err != nil { + var batchSize units.Bytes + if err := batchSize.UnmarshalText([]byte(fmt.Sprintf("%dB", config.BatchSize))); err != nil { diags.Add( diag.SeverityLevelError, fmt.Sprintf("failed to parse BatchSize for client config %s: %s", config.Name, err.Error()), diff --git a/internal/converter/internal/promtailconvert/internal/build/stages.go b/internal/converter/internal/promtailconvert/internal/build/stages.go index 6b615c5769..1c6255bd3e 100644 --- a/internal/converter/internal/promtailconvert/internal/build/stages.go +++ b/internal/converter/internal/promtailconvert/internal/build/stages.go @@ -6,7 +6,6 @@ import ( "strings" "time" - "github.com/alecthomas/units" promtailmetric "github.com/grafana/loki/clients/pkg/logentry/metric" promtailstages "github.com/grafana/loki/clients/pkg/logentry/stages" "github.com/grafana/loki/pkg/util/flagext" @@ -15,6 +14,7 @@ import ( "github.com/grafana/alloy/internal/component/loki/process/metric" "github.com/grafana/alloy/internal/component/loki/process/stages" "github.com/grafana/alloy/internal/converter/diag" + "github.com/grafana/alloy/internal/units" ) func convertStage(st interface{}, diags *diag.Diagnostics) (stages.StageConfig, bool) { @@ -293,7 +293,7 @@ func convertDrop(cfg interface{}, diags *diag.Diagnostics) (stages.StageConfig, olderThan = d } - var longerThan units.Base2Bytes + var longerThan units.Bytes if pDrop.LongerThan != nil { var pLongerThan flagext.ByteSize err := pLongerThan.Set(*pDrop.LongerThan) @@ -301,7 +301,8 @@ func convertDrop(cfg interface{}, diags *diag.Diagnostics) (stages.StageConfig, diags.Add(diag.SeverityLevelError, fmt.Sprintf("invalid pipeline_stages.drop.longer_than field: %v", err)) return stages.StageConfig{}, false } - longerThan, err = units.ParseBase2Bytes(fmt.Sprintf("%dB", pLongerThan.Val())) + + err = longerThan.UnmarshalText([]byte(fmt.Sprintf("%dB", pLongerThan.Val()))) if err != nil { diags.Add(diag.SeverityLevelError, fmt.Sprintf("invalid pipeline_stages.drop.longer_than field: failed Alloy type conversion: %v", err)) return stages.StageConfig{}, false diff --git a/internal/converter/internal/staticconvert/internal/build/app_agent_receiver.go b/internal/converter/internal/staticconvert/internal/build/app_agent_receiver.go index a3e2b1c9bb..648973d030 100644 --- a/internal/converter/internal/staticconvert/internal/build/app_agent_receiver.go +++ b/internal/converter/internal/staticconvert/internal/build/app_agent_receiver.go @@ -3,13 +3,13 @@ package build import ( "fmt" - "github.com/alecthomas/units" "github.com/grafana/alloy/internal/component/common/loki" "github.com/grafana/alloy/internal/component/faro/receiver" "github.com/grafana/alloy/internal/component/otelcol" "github.com/grafana/alloy/internal/converter/diag" "github.com/grafana/alloy/internal/converter/internal/common" app_agent_receiver_v2 "github.com/grafana/alloy/internal/static/integrations/v2/app_agent_receiver" + "github.com/grafana/alloy/internal/units" "github.com/grafana/alloy/syntax/alloytypes" "github.com/grafana/alloy/syntax/scanner" ) @@ -52,7 +52,7 @@ func toAppAgentReceiverV2(config *app_agent_receiver_v2.Config) *receiver.Argume Port: config.Server.Port, CORSAllowedOrigins: config.Server.CORSAllowedOrigins, APIKey: alloytypes.Secret(config.Server.APIKey), - MaxAllowedPayloadSize: units.Base2Bytes(config.Server.MaxAllowedPayloadSize), + MaxAllowedPayloadSize: units.Bytes(config.Server.MaxAllowedPayloadSize), RateLimiting: receiver.RateLimitingArguments{ Enabled: config.Server.RateLimiting.Enabled, Rate: config.Server.RateLimiting.RPS, diff --git a/internal/converter/internal/staticconvert/testdata-v2/integrations_v2.alloy b/internal/converter/internal/staticconvert/testdata-v2/integrations_v2.alloy index 38f656b4ee..2bee5b8601 100644 --- a/internal/converter/internal/staticconvert/testdata-v2/integrations_v2.alloy +++ b/internal/converter/internal/staticconvert/testdata-v2/integrations_v2.alloy @@ -27,7 +27,7 @@ faro.receiver "integrations_app_agent_receiver" { server { listen_address = "localhost" listen_port = 55678 - max_allowed_payload_size = "4MiB786KiB832B" + max_allowed_payload_size = "5MB" rate_limiting { rate = 100 diff --git a/internal/converter/internal/staticconvert/testdata-v2/unsupported.alloy b/internal/converter/internal/staticconvert/testdata-v2/unsupported.alloy index 9f06a3cdc5..d2134ca217 100644 --- a/internal/converter/internal/staticconvert/testdata-v2/unsupported.alloy +++ b/internal/converter/internal/staticconvert/testdata-v2/unsupported.alloy @@ -22,7 +22,7 @@ faro.receiver "integrations_app_agent_receiver" { server { listen_address = "localhost" listen_port = 55678 - max_allowed_payload_size = "4MiB786KiB832B" + max_allowed_payload_size = "5MB" rate_limiting { rate = 100 diff --git a/internal/converter/internal/staticconvert/testdata/traces.alloy b/internal/converter/internal/staticconvert/testdata/traces.alloy index 0e1684d924..ab6fb5cb34 100644 --- a/internal/converter/internal/staticconvert/testdata/traces.alloy +++ b/internal/converter/internal/staticconvert/testdata/traces.alloy @@ -18,7 +18,7 @@ otelcol.extension.jaeger_remote_sampling "default_0" { remote { endpoint = "jaeger-collector:14250" compression = "" - write_buffer_size = "0B" + write_buffer_size = "0" } reload_interval = "30s" }