Skip to content

Commit 68fc844

Browse files
authored
enable RE2 support by default on linux (#4386)
1 parent ac5e6f9 commit 68fc844

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

pkg/fflag/crowdsec.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
11
package fflag
22

3+
import "runtime"
4+
35
var Crowdsec = FeatureRegister{EnvPrefix: "CROWDSEC_FEATURE_"}
46

57
var (
68
DisableHttpRetryBackoff = &Feature{Name: "disable_http_retry_backoff", Description: "Disable http retry backoff"}
79
ChunkedDecisionsStream = &Feature{Name: "chunked_decisions_stream", Description: "Enable chunked decisions stream"}
810
PapiClient = &Feature{Name: "papi_client", Description: "Enable Polling API client", State: DeprecatedState}
9-
Re2GrokSupport = &Feature{Name: "re2_grok_support", Description: "Enable RE2 support for GROK patterns"}
10-
Re2RegexpInfileSupport = &Feature{Name: "re2_regexp_in_file_support", Description: "Enable RE2 support for RegexpInFile expr helper"}
11-
PProfBlockProfile = &Feature{Name: "pprof_block_profile", Description: "Enable pprof block/mutex profiling. Do not use unless instructed by CrowdSec support"}
11+
// The state will be set to deprecated for linux only.
12+
Re2GrokSupport = &Feature{Name: "re2_grok_support", Description: "Enable RE2 support for GROK patterns"}
13+
// This one is only available on OS where RE2 support is enabled by default (linux only at the moment)
14+
Re2DisableGrokSupport = &Feature{Name: "re2_disable_grok_support", Description: "Disable RE2 support for GROK patterns (linux only)"}
15+
Re2RegexpInfileSupport = &Feature{Name: "re2_regexp_in_file_support", Description: "Enable RE2 support for RegexpInFile expr helper"}
16+
PProfBlockProfile = &Feature{Name: "pprof_block_profile", Description: "Enable pprof block/mutex profiling. Do not use unless instructed by CrowdSec support"}
1217
)
1318

19+
//revive:disable:if-return
1420
func RegisterAllFeatures() error {
15-
err := Crowdsec.RegisterFeature(DisableHttpRetryBackoff)
16-
if err != nil {
21+
if err := Crowdsec.RegisterFeature(DisableHttpRetryBackoff); err != nil {
1722
return err
1823
}
1924

20-
err = Crowdsec.RegisterFeature(ChunkedDecisionsStream)
21-
if err != nil {
25+
if err := Crowdsec.RegisterFeature(ChunkedDecisionsStream); err != nil {
2226
return err
2327
}
2428

25-
err = Crowdsec.RegisterFeature(PapiClient)
26-
if err != nil {
29+
if err := Crowdsec.RegisterFeature(PapiClient); err != nil {
2730
return err
2831
}
2932

30-
err = Crowdsec.RegisterFeature(Re2GrokSupport)
31-
if err != nil {
33+
if err := Crowdsec.RegisterFeature(Re2RegexpInfileSupport); err != nil {
3234
return err
3335
}
3436

35-
err = Crowdsec.RegisterFeature(Re2RegexpInfileSupport)
36-
if err != nil {
37+
if err := Crowdsec.RegisterFeature(PProfBlockProfile); err != nil {
3738
return err
3839
}
3940

40-
err = Crowdsec.RegisterFeature(PProfBlockProfile)
41-
if err != nil {
41+
if runtime.GOOS == "linux" {
42+
// This cannot actually fail in a release, so the state will always be set
43+
if err := Crowdsec.RegisterFeature(Re2DisableGrokSupport); err != nil {
44+
return err
45+
}
46+
Re2GrokSupport.State = DeprecatedState
47+
}
48+
49+
if err := Crowdsec.RegisterFeature(Re2GrokSupport); err != nil {
4250
return err
4351
}
4452

4553
return nil
4654
}
55+
56+
//revice:enable:if-return

pkg/parser/unix_parser.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"runtime"
78
"sort"
89
"strings"
910

@@ -36,7 +37,12 @@ type Parsers struct {
3637
func NewUnixParserCtx(patternDir string, dataDir string) (*UnixParserCtx, error) {
3738
r := UnixParserCtx{}
3839
r.Grok = grokky.NewBase()
39-
r.Grok.UseRe2 = fflag.Re2GrokSupport.IsEnabled()
40+
// RE2 is enabled by default on linux, but can be disabled with re2_disable_grok_support
41+
if runtime.GOOS == "linux" {
42+
r.Grok.UseRe2 = !fflag.Re2DisableGrokSupport.IsEnabled()
43+
} else {
44+
r.Grok.UseRe2 = fflag.Re2GrokSupport.IsEnabled()
45+
}
4046

4147
files, err := os.ReadDir(patternDir)
4248
if err != nil {

0 commit comments

Comments
 (0)