Skip to content

Commit 50bf1fe

Browse files
improvements
1 parent 53fc1fe commit 50bf1fe

File tree

8 files changed

+60
-168
lines changed

8 files changed

+60
-168
lines changed

docs/api.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,8 @@ Following is the supported API format for writing to loki:
323323
timestampScale: timestamp units scale (e.g. for UNIX = 1s)
324324
format: the format of each line: printf (writes using golang's default map printing), fields (writes one key and value field per line) or json (default)
325325
reorder: reorder json map keys
326-
clientType: type of client to use: 'http' or 'grpc' (default: 'http')
327-
grpcConfig: gRPC client configuration (used only for gRPC client type)
328-
serverAddress: gRPC server address (host:port)
329-
maxRecvMsgSize: maximum message size the client can receive
330-
maxSendMsgSize: maximum message size the client can send
326+
clientProtocol: type of client protocol to use: 'http' or 'grpc' (default: 'http')
327+
grpcConfig: gRPC client configuration (used only for gRPC client protocol)
331328
keepAlive: keep alive interval
332329
keepAliveTimeout: keep alive timeout
333330
tls: TLS configuration

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,4 @@ require (
176176

177177
replace github.com/vmware/go-ipfix => github.com/jotak/go-ipfix v0.0.0-20250708115123-407c539ea101
178178

179-
replace github.com/netobserv/loki-client-go => github.com/leandroberetta/loki-client-go v0.0.0-20250923004934-a3e68fd6a596
179+
replace github.com/netobserv/loki-client-go => github.com/leandroberetta/loki-client-go v0.0.0-20250924145641-591b5499691d

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
206206
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
207207
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
208208
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
209-
github.com/leandroberetta/loki-client-go v0.0.0-20250923004934-a3e68fd6a596 h1:FhZHtZsaCa4LMhgTrU+eM1iTnl2X1L1yrSRQjGHiJOo=
210-
github.com/leandroberetta/loki-client-go v0.0.0-20250923004934-a3e68fd6a596/go.mod h1:Zb/jtD3Lnu88Poo+jnhTASzxYnvncmHOoZaT93xQjJ8=
209+
github.com/leandroberetta/loki-client-go v0.0.0-20250924145641-591b5499691d h1:qXM2SFkp1qzHcvrfPMleIkmEF2lVyKr1PQcpyCMbDWE=
210+
github.com/leandroberetta/loki-client-go v0.0.0-20250924145641-591b5499691d/go.mod h1:Zb/jtD3Lnu88Poo+jnhTASzxYnvncmHOoZaT93xQjJ8=
211211
github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s=
212212
github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU=
213213
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=

pkg/api/write_loki.go

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,12 @@ type WriteLoki struct {
4848
Format string `yaml:"format,omitempty" json:"format,omitempty" doc:"the format of each line: printf (writes using golang's default map printing), fields (writes one key and value field per line) or json (default)"`
4949
Reorder bool `yaml:"reorder,omitempty" json:"reorder,omitempty" doc:"reorder json map keys"`
5050

51-
// Client type selection
52-
ClientType string `yaml:"clientType,omitempty" json:"clientType,omitempty" doc:"type of client to use: 'http' or 'grpc' (default: 'http')"`
51+
// Client protocol selection
52+
ClientProtocol string `yaml:"clientProtocol,omitempty" json:"clientProtocol,omitempty" doc:"type of client protocol to use: 'http' or 'grpc' (default: 'http')"`
5353
GRPCConfig *GRPCLokiConfig `yaml:"grpcConfig,omitempty" json:"grpcConfig,omitempty" doc:"gRPC client configuration (used only for gRPC client type)"`
5454
}
5555

5656
type GRPCLokiConfig struct {
57-
ServerAddress string `yaml:"serverAddress,omitempty" json:"serverAddress,omitempty" doc:"gRPC server address (host:port)"`
58-
MaxRecvMsgSize int `yaml:"maxRecvMsgSize,omitempty" json:"maxRecvMsgSize,omitempty" doc:"maximum message size the client can receive"`
59-
MaxSendMsgSize int `yaml:"maxSendMsgSize,omitempty" json:"maxSendMsgSize,omitempty" doc:"maximum message size the client can send"`
6057
KeepAlive string `yaml:"keepAlive,omitempty" json:"keepAlive,omitempty" doc:"keep alive interval"`
6158
KeepAliveTimeout string `yaml:"keepAliveTimeout,omitempty" json:"keepAliveTimeout,omitempty" doc:"keep alive timeout"`
6259
TLS *GRPCTLSConfig `yaml:"tls,omitempty" json:"tls,omitempty" doc:"TLS configuration"`
@@ -99,23 +96,17 @@ func (w *WriteLoki) SetDefaults() {
9996
if w.Format == "" {
10097
w.Format = "json"
10198
}
102-
if w.ClientType == "" {
103-
w.ClientType = "http"
99+
if w.ClientProtocol == "" {
100+
w.ClientProtocol = "http"
104101
}
105102

106-
// Set defaults for gRPC config if gRPC client type is selected
107-
if w.ClientType == "grpc" && w.GRPCConfig != nil {
103+
// Set defaults for gRPC config if gRPC client protocol is selected
104+
if w.ClientProtocol == "grpc" && w.GRPCConfig != nil {
108105
w.GRPCConfig.SetDefaults()
109106
}
110107
}
111108

112109
func (g *GRPCLokiConfig) SetDefaults() {
113-
if g.MaxRecvMsgSize == 0 {
114-
g.MaxRecvMsgSize = 1024 * 1024 * 64 // 64MB
115-
}
116-
if g.MaxSendMsgSize == 0 {
117-
g.MaxSendMsgSize = 1024 * 1024 * 16 // 16MB
118-
}
119110
if g.KeepAlive == "" {
120111
g.KeepAlive = "30s"
121112
}
@@ -135,20 +126,23 @@ func (w *WriteLoki) Validate() error {
135126
return fmt.Errorf("invalid batchSize: %v. Required > 0", w.BatchSize)
136127
}
137128

138-
// Validate client type
139-
if w.ClientType != "" && w.ClientType != "http" && w.ClientType != "grpc" {
140-
return fmt.Errorf("invalid clientType: %s. Must be 'http' or 'grpc'", w.ClientType)
129+
// Validate client protocol
130+
if w.ClientProtocol != "" && w.ClientProtocol != "http" && w.ClientProtocol != "grpc" {
131+
return fmt.Errorf("invalid clientProtocol: %s. Must be 'http' or 'grpc'", w.ClientProtocol)
141132
}
142133

143-
// Validate based on client type
144-
switch w.ClientType {
134+
// Validate based on client protocol
135+
switch w.ClientProtocol {
145136
case "http", "":
146137
if w.URL == "" {
147138
return errors.New("url can't be empty for HTTP client")
148139
}
149140
case "grpc":
141+
if w.URL == "" {
142+
return errors.New("url can't be empty for gRPC client")
143+
}
150144
if w.GRPCConfig == nil {
151-
return errors.New("grpcConfig is required when using gRPC client type")
145+
return errors.New("grpcConfig is required when using gRPC client protocol")
152146
}
153147
if err := w.GRPCConfig.Validate(); err != nil {
154148
return fmt.Errorf("gRPC config validation failed: %w", err)
@@ -162,10 +156,6 @@ func (g *GRPCLokiConfig) Validate() error {
162156
if g == nil {
163157
return errors.New("gRPC config cannot be nil")
164158
}
165-
if g.ServerAddress == "" {
166-
return errors.New("gRPC serverAddress cannot be empty")
167-
}
168-
169159
// Validate duration fields
170160
if g.KeepAlive != "" {
171161
if _, err := time.ParseDuration(g.KeepAlive); err != nil {

pkg/pipeline/write/write_loki.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ type Loki struct {
6262
}
6363

6464
func createLokiClient(c *api.WriteLoki) (emitter, error) {
65-
switch c.ClientType {
65+
switch c.ClientProtocol {
6666
case "grpc":
6767
return createGRPCClient(c)
6868
case "http", "":
6969
return createHTTPClient(c)
7070
default:
71-
return nil, fmt.Errorf("unsupported client type: %s", c.ClientType)
71+
return nil, fmt.Errorf("unsupported client protocol: %s", c.ClientProtocol)
7272
}
7373
}
7474

@@ -146,7 +146,7 @@ func buildHTTPLokiConfig(c *api.WriteLoki) (loki.Config, error) {
146146

147147
func buildGRPCLokiConfig(c *api.WriteLoki) (grpc.Config, error) {
148148
if c.GRPCConfig == nil {
149-
return grpc.Config{}, fmt.Errorf("gRPC config is required for gRPC client type")
149+
return grpc.Config{}, fmt.Errorf("gRPC config is required for gRPC client protocol")
150150
}
151151

152152
batchWait, err := time.ParseDuration(c.BatchWait)
@@ -180,13 +180,11 @@ func buildGRPCLokiConfig(c *api.WriteLoki) (grpc.Config, error) {
180180
}
181181

182182
cfg := grpc.Config{
183-
ServerAddress: c.GRPCConfig.ServerAddress,
183+
ServerAddress: c.URL,
184184
TenantID: c.TenantID,
185185
BatchWait: batchWait,
186186
BatchSize: c.BatchSize,
187187
Timeout: timeout,
188-
MaxRecvMsgSize: c.GRPCConfig.MaxRecvMsgSize,
189-
MaxSendMsgSize: c.GRPCConfig.MaxSendMsgSize,
190188
KeepAlive: keepAlive,
191189
KeepAliveTimeout: keepAliveTimeout,
192190
BackoffConfig: backoff.BackoffConfig{
@@ -330,7 +328,7 @@ func NewWriteLoki(opMetrics *operational.Metrics, params config.StageParam) (*Lo
330328
return nil, fmt.Errorf("the provided config is not valid: %w", err)
331329
}
332330

333-
// Create the appropriate client based on clientType
331+
// Create the appropriate client based on clientProtocol
334332
client, err := createLokiClient(&lokiConfigIn)
335333
if err != nil {
336334
return nil, fmt.Errorf("failed to create Loki client: %w", err)

0 commit comments

Comments
 (0)