Skip to content

Commit 786d411

Browse files
committed
feat: make raw format experimental
1 parent 2ba0e7e commit 786d411

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

docs/sources/reference/components/loki/loki.source.syslog.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ For a detailed example, refer to the [Monitor RFC5424-compliant syslog messages
1818

1919
{{< admonition type="note" >}}
2020
If your messages aren't RFC5424 compliant, you can use `raw` syslog format in combination with the [`loki.process`](./loki.process.md) component.
21+
22+
Please note, that the `raw` syslog format is an [experimental][] feature.
2123
{{< /admonition >}}
2224

25+
[experimental]: https://grafana.com/docs/release-life-cycle/
26+
2327
The component starts a new syslog listener for each of the given `config` blocks and fans out incoming entries to the list of receivers in `forward_to`.
2428

2529
You can specify multiple `loki.source.syslog` components by giving them different labels.
@@ -146,10 +150,21 @@ The `rfc3164_default_to_current_year`, `use_incoming_timestamp` and `use_rfc5424
146150
Disables log line parsing. This format allows receiving non-RFC5424 compliant logs, such as [CEF][cef].
147151
Raw logs can be forwarded to [`loki.process`](./loki.process.md) component for parsing.
148152

153+
{{< admonition type="note" >}}
154+
The `raw` format is an [experimental][] feature.
155+
Experimental features are subject to frequent breaking changes, and may be removed with no equivalent replacement.
156+
To enable and use an experimental feature, you must set the `stability.level` [flag][] to `experimental`.
157+
{{< /admonition >}}
158+
159+
[flag]: https://grafana.com/docs/alloy/<ALLOY_VERSION>/reference/cli/run/
160+
[experimental]: https://grafana.com/docs/release-life-cycle/
161+
149162
[cef]: https://www.splunk.com/en_us/blog/learn/common-event-format-cef.html
150163

151164
### `raw_format_options`
152165

166+
{{< docs/shared lookup="stability/experimental_feature.md" source="alloy" version="<ALLOY_VERSION>" >}}
167+
153168
The `raw_format_options` block configures the `raw` syslog format behavior.
154169

155170
{{< admonition type="note" >}}

internal/component/loki/source/syslog/syslog.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package syslog
22

33
import (
44
"context"
5+
"fmt"
56
"reflect"
67
"sync"
78

@@ -10,6 +11,7 @@ import (
1011
"github.com/grafana/alloy/internal/component"
1112
"github.com/grafana/alloy/internal/component/common/loki"
1213
alloy_relabel "github.com/grafana/alloy/internal/component/common/relabel"
14+
scrapeconfig "github.com/grafana/alloy/internal/component/loki/source/syslog/config"
1315
st "github.com/grafana/alloy/internal/component/loki/source/syslog/internal/syslogtarget"
1416
"github.com/grafana/alloy/internal/featuregate"
1517
"github.com/grafana/alloy/internal/runtime/logging/level"
@@ -109,6 +111,10 @@ func (c *Component) Update(args component.Arguments) error {
109111
defer c.mut.Unlock()
110112

111113
newArgs := args.(Arguments)
114+
if err := c.checkExperimentalFeatures(newArgs); err != nil {
115+
return err
116+
}
117+
112118
prevArgs := c.args
113119
c.fanout = newArgs.ForwardTo
114120

@@ -125,6 +131,21 @@ func (c *Component) Update(args component.Arguments) error {
125131
return nil
126132
}
127133

134+
func (c *Component) checkExperimentalFeatures(args Arguments) error {
135+
isExperimental := c.opts.MinStability.Permits(featuregate.StabilityExperimental)
136+
if isExperimental {
137+
return nil
138+
}
139+
140+
for _, listener := range args.SyslogListeners {
141+
if listener.SyslogFormat == scrapeconfig.SyslogFormatRaw {
142+
return fmt.Errorf("%q syslog format is available only at experimental stability level", scrapeconfig.SyslogFormatRaw)
143+
}
144+
}
145+
146+
return nil
147+
}
148+
128149
func (c *Component) startDrainingRoutine() func() {
129150
readCtx, cancel := context.WithCancel(context.Background())
130151
c.mut.RLock()

internal/component/loki/source/syslog/syslog_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
1616

17+
scrapeconfig "github.com/grafana/alloy/internal/component/loki/source/syslog/config"
18+
"github.com/grafana/alloy/internal/featuregate"
19+
1720
"github.com/grafana/alloy/internal/component"
1821
"github.com/grafana/alloy/internal/component/common/loki"
1922
alloy_relabel "github.com/grafana/alloy/internal/component/common/relabel"
@@ -278,3 +281,25 @@ func TestShutdownAndRebindOnSamePort(t *testing.T) {
278281
require.NoError(t, err)
279282
}
280283
}
284+
285+
func TestRawFormatRequiresExperimentalStabilityLevel(t *testing.T) {
286+
opts := component.Options{
287+
Logger: util.TestAlloyLogger(t),
288+
Registerer: prometheus.NewRegistry(),
289+
OnStateChange: func(e component.Exports) {},
290+
MinStability: featuregate.StabilityGenerallyAvailable,
291+
}
292+
293+
ch1 := loki.NewLogsReceiver()
294+
args1 := Arguments{}
295+
l1 := DefaultListenerConfig
296+
l1.ListenAddress = "127.0.0.1:1234"
297+
l1.ListenProtocol = syslogtarget.ProtocolTCP
298+
l1.SyslogFormat = scrapeconfig.SyslogFormatRaw
299+
args1.SyslogListeners = []ListenerConfig{l1}
300+
args1.ForwardTo = []loki.LogsReceiver{ch1}
301+
302+
_, err := New(opts, args1)
303+
require.Error(t, err)
304+
require.Error(t, err, "syslog format requires experimental stability level")
305+
}

0 commit comments

Comments
 (0)