Skip to content

Commit 8d2288c

Browse files
committed
feat(api): expose log level controls
Fixes #187 Signed-off-by: Sergei Lukianov <[email protected]>
1 parent b351249 commit 8d2288c

File tree

6 files changed

+145
-1
lines changed

6 files changed

+145
-1
lines changed

api/gateway/v1alpha1/gateway_types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type GatewaySpec struct {
3131
Interfaces map[string]GatewayInterface `json:"interfaces,omitempty"`
3232
// Neighbors is a list of BGP neighbors
3333
Neighbors []GatewayBGPNeighbor `json:"neighbors,omitempty"`
34+
// Logs defines the configuration for logging levels
35+
Logs GatewayLogs `json:"logs,omitempty"`
3436
}
3537

3638
// GatewayInterface defines the configuration for a gateway interface
@@ -51,6 +53,32 @@ type GatewayBGPNeighbor struct {
5153
ASN uint32 `json:"asn,omitempty"`
5254
}
5355

56+
// GatewayLogs defines the configuration for logging levels
57+
type GatewayLogs struct {
58+
Default GatewayLogLevel `json:"default,omitempty"`
59+
Tags map[string]GatewayLogLevel `json:"tags,omitempty"`
60+
}
61+
62+
type GatewayLogLevel string
63+
64+
const (
65+
GatewayLogLevelOff GatewayLogLevel = "off"
66+
GatewayLogLevelError GatewayLogLevel = "error"
67+
GatewayLogLevelWarning GatewayLogLevel = "warning"
68+
GatewayLogLevelInfo GatewayLogLevel = "info"
69+
GatewayLogLevelDebug GatewayLogLevel = "debug"
70+
GatewayLogLevelTrace GatewayLogLevel = "trace"
71+
)
72+
73+
var GatewayLogLevels = []GatewayLogLevel{
74+
GatewayLogLevelOff,
75+
GatewayLogLevelError,
76+
GatewayLogLevelWarning,
77+
GatewayLogLevelInfo,
78+
GatewayLogLevelDebug,
79+
GatewayLogLevelTrace,
80+
}
81+
5482
// GatewayStatus defines the observed state of Gateway.
5583
type GatewayStatus struct{}
5684

@@ -83,6 +111,9 @@ func init() {
83111
}
84112

85113
func (gw *Gateway) Default() {
114+
if gw.Spec.Logs.Default == "" {
115+
gw.Spec.Logs.Default = GatewayLogLevelInfo
116+
}
86117
}
87118

88119
func (gw *Gateway) Validate(_ context.Context, _ kclient.Reader) error {

api/gateway/v1alpha1/zz_generated.deepcopy.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/gateway.githedgehog.com_gateways.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ spec:
7878
type: object
7979
description: Interfaces is a map of interface names to their configurations
8080
type: object
81+
logs:
82+
description: Logs defines the configuration for logging levels
83+
properties:
84+
default:
85+
type: string
86+
tags:
87+
additionalProperties:
88+
type: string
89+
type: object
90+
type: object
8191
neighbors:
8292
description: Neighbors is a list of BGP neighbors
8393
items:

config/crd/bases/gwint.githedgehog.com_gatewayagents.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ spec:
9797
type: object
9898
description: Interfaces is a map of interface names to their configurations
9999
type: object
100+
logs:
101+
description: Logs defines the configuration for logging levels
102+
properties:
103+
default:
104+
type: string
105+
tags:
106+
additionalProperties:
107+
type: string
108+
type: object
109+
type: object
100110
neighbors:
101111
description: Neighbors is a list of BGP neighbors
102112
items:

docs/api.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,44 @@ _Appears in:_
7070
| `mtu` _integer_ | MTU for the interface | | |
7171

7272

73+
#### GatewayLogLevel
74+
75+
_Underlying type:_ _string_
76+
77+
78+
79+
80+
81+
_Appears in:_
82+
- [GatewayLogs](#gatewaylogs)
83+
84+
| Field | Description |
85+
| --- | --- |
86+
| `off` | |
87+
| `error` | |
88+
| `warning` | |
89+
| `info` | |
90+
| `debug` | |
91+
| `trace` | |
92+
93+
94+
#### GatewayLogs
95+
96+
97+
98+
GatewayLogs defines the configuration for logging levels
99+
100+
101+
102+
_Appears in:_
103+
- [GatewaySpec](#gatewayspec)
104+
105+
| Field | Description | Default | Validation |
106+
| --- | --- | --- | --- |
107+
| `default` _[GatewayLogLevel](#gatewayloglevel)_ | | | |
108+
| `tags` _object (keys:string, values:[GatewayLogLevel](#gatewayloglevel))_ | | | |
109+
110+
73111
#### GatewaySpec
74112

75113

@@ -91,6 +129,7 @@ _Appears in:_
91129
| `vtepMTU` _integer_ | VTEPMTU is the MTU for the VTEP interface | | |
92130
| `interfaces` _object (keys:string, values:[GatewayInterface](#gatewayinterface))_ | Interfaces is a map of interface names to their configurations | | |
93131
| `neighbors` _[GatewayBGPNeighbor](#gatewaybgpneighbor) array_ | Neighbors is a list of BGP neighbors | | |
132+
| `logs` _[GatewayLogs](#gatewaylogs)_ | Logs defines the configuration for logging levels | | |
94133

95134

96135
#### GatewayStatus

pkg/agent/dataplane.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/netip"
99

1010
"go.githedgehog.com/gateway-proto/pkg/dataplane"
11+
gwapi "go.githedgehog.com/gateway/api/gateway/v1alpha1"
1112
gwintapi "go.githedgehog.com/gateway/api/gwint/v1alpha1"
1213
)
1314

@@ -153,12 +154,23 @@ func buildDataplaneConfig(ag *gwintapi.GatewayAgent) (*dataplane.GatewayConfig,
153154
peerings = append(peerings, p)
154155
}
155156

157+
if ag.Spec.Gateway.Logs.Default == "" {
158+
ag.Spec.Gateway.Logs.Default = gwapi.GatewayLogLevelInfo
159+
}
160+
tracing := &dataplane.TracingConfig{
161+
Default: pbLevel(ag.Spec.Gateway.Logs.Default),
162+
Taglevel: map[string]dataplane.LogLevel{},
163+
}
164+
for tag, level := range ag.Spec.Gateway.Logs.Tags {
165+
tracing.Taglevel[tag] = pbLevel(level)
166+
}
167+
156168
return &dataplane.GatewayConfig{
157169
Generation: ag.Generation,
158170
Device: &dataplane.Device{
159171
Driver: dataplane.PacketDriver_KERNEL,
160172
Hostname: ag.Name,
161-
Loglevel: dataplane.LogLevel_DEBUG,
173+
Tracing: tracing,
162174
},
163175
Underlay: &dataplane.Underlay{
164176
Vrfs: []*dataplane.VRF{
@@ -187,3 +199,22 @@ func buildDataplaneConfig(ag *gwintapi.GatewayAgent) (*dataplane.GatewayConfig,
187199
},
188200
}, nil
189201
}
202+
203+
func pbLevel(in gwapi.GatewayLogLevel) dataplane.LogLevel {
204+
switch in {
205+
case gwapi.GatewayLogLevelOff:
206+
return dataplane.LogLevel_OFF
207+
case gwapi.GatewayLogLevelError:
208+
return dataplane.LogLevel_ERROR
209+
case gwapi.GatewayLogLevelWarning:
210+
return dataplane.LogLevel_WARNING
211+
case gwapi.GatewayLogLevelInfo:
212+
return dataplane.LogLevel_INFO
213+
case gwapi.GatewayLogLevelDebug:
214+
return dataplane.LogLevel_DEBUG
215+
case gwapi.GatewayLogLevelTrace:
216+
return dataplane.LogLevel_TRACE
217+
}
218+
219+
return dataplane.LogLevel_OFF
220+
}

0 commit comments

Comments
 (0)