Skip to content

Commit

Permalink
misc: switch to new units package
Browse files Browse the repository at this point in the history
This switches everything over to the new units package.
  • Loading branch information
rfratto committed Apr 29, 2024
1 parent e7bc2fb commit 4b1177e
Show file tree
Hide file tree
Showing 29 changed files with 101 additions and 98 deletions.
10 changes: 5 additions & 5 deletions internal/component/common/loki/client/queue_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
},
Expand Down
6 changes: 3 additions & 3 deletions internal/component/faro/receiver/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"`
Expand All @@ -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()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/component/faro/receiver/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
18 changes: 9 additions & 9 deletions internal/component/loki/process/stages/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions internal/component/loki/process/stages/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions internal/component/loki/write/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
}
}
Expand Down
14 changes: 7 additions & 7 deletions internal/component/otelcol/config_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`

Expand Down Expand Up @@ -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"`
Expand Down
10 changes: 5 additions & 5 deletions internal/component/otelcol/config_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
Expand Down
16 changes: 8 additions & 8 deletions internal/component/otelcol/receiver/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
},
}
Expand All @@ -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,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/component/otelcol/receiver/otlp/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 4b1177e

Please sign in to comment.