Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stability lvl to config blocks #2441

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/runtime/foreach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/runtime"
alloy_runtime "github.com/grafana/alloy/internal/runtime"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -103,7 +104,7 @@ func buildTestForEach(t *testing.T, filename string) testForEachFile {
func testConfigForEach(t *testing.T, config string, reloadConfig string, update func(), expectedMetrics *string, expectedDurationMetrics *int) {
defer verifyNoGoroutineLeaks(t)
reg := prometheus.NewRegistry()
ctrl, f := setup(t, config, reg)
ctrl, f := setup(t, config, reg, featuregate.StabilityExperimental)

err := ctrl.LoadSource(f, nil, "")
require.NoError(t, err)
Expand Down
11 changes: 6 additions & 5 deletions internal/runtime/import_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"testing"
"time"

"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/vcs"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -55,7 +56,7 @@ testImport.add "cc" {
runGit(t, testRepo, "commit", "-m \"test\"")

defer verifyNoGoroutineLeaks(t)
ctrl, f := setup(t, main, nil)
ctrl, f := setup(t, main, nil, featuregate.StabilityPublicPreview)
err = ctrl.LoadSource(f, nil, "")
require.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -122,7 +123,7 @@ testImport.add "cc" {
runGit(t, testRepo, "commit", "-m \"test\"")

defer verifyNoGoroutineLeaks(t)
ctrl, f := setup(t, main, nil)
ctrl, f := setup(t, main, nil, featuregate.StabilityPublicPreview)
err = ctrl.LoadSource(f, nil, "")
require.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -205,7 +206,7 @@ testImport.add "cc" {
runGit(t, testRepo, "commit", "-m \"test2\"")

defer verifyNoGoroutineLeaks(t)
ctrl, f := setup(t, main, nil)
ctrl, f := setup(t, main, nil, featuregate.StabilityPublicPreview)
err = ctrl.LoadSource(f, nil, "")
require.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -269,7 +270,7 @@ testImport.add "cc" {

defer verifyNoGoroutineLeaks(t)

ctrl, f := setup(t, main, nil)
ctrl, f := setup(t, main, nil, featuregate.StabilityPublicPreview)
err = ctrl.LoadSource(f, nil, "")
require.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -354,7 +355,7 @@ testImport.add "cc" {
runGit(t, testRepo, "commit", "-m \"test\"")

defer verifyNoGoroutineLeaks(t)
ctrl, f := setup(t, main, nil)
ctrl, f := setup(t, main, nil, featuregate.StabilityPublicPreview)
err = ctrl.LoadSource(f, nil, "")
expectedErr := vcs.InvalidRevisionError{
Revision: "nonexistent",
Expand Down
8 changes: 4 additions & 4 deletions internal/runtime/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestImportError(t *testing.T) {

func testConfig(t *testing.T, config string, reloadConfig string, update func()) {
defer verifyNoGoroutineLeaks(t)
ctrl, f := setup(t, config, nil)
ctrl, f := setup(t, config, nil, featuregate.StabilityPublicPreview)

err := ctrl.LoadSource(f, nil, "")
require.NoError(t, err)
Expand Down Expand Up @@ -352,7 +352,7 @@ func testConfig(t *testing.T, config string, reloadConfig string, update func())

func testConfigError(t *testing.T, config string, expectedError string) {
defer verifyNoGoroutineLeaks(t)
ctrl, f := setup(t, config, nil)
ctrl, f := setup(t, config, nil, featuregate.StabilityPublicPreview)
err := ctrl.LoadSource(f, nil, "")
require.ErrorContains(t, err, expectedError)
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -369,13 +369,13 @@ func testConfigError(t *testing.T, config string, expectedError string) {
}()
}

func setup(t *testing.T, config string, reg prometheus.Registerer) (*alloy_runtime.Runtime, *alloy_runtime.Source) {
func setup(t *testing.T, config string, reg prometheus.Registerer, stability featuregate.Stability) (*alloy_runtime.Runtime, *alloy_runtime.Source) {
s, err := logging.New(os.Stderr, logging.DefaultOptions)
require.NoError(t, err)
ctrl := alloy_runtime.New(alloy_runtime.Options{
Logger: s,
DataPath: t.TempDir(),
MinStability: featuregate.StabilityPublicPreview,
MinStability: stability,
Reg: reg,
Services: []service.Service{},
})
Expand Down
13 changes: 13 additions & 0 deletions internal/runtime/internal/controller/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ func TestLoader(t *testing.T) {
diags = applyFromContent(t, l, nil, nil, []byte(invalidFile))
require.ErrorContains(t, diags.ErrorOrNil(), `block declare.a already declared at TestLoader/Declare_block_redefined_after_reload:2:4`)
})

t.Run("Foreach incorrect feature stability", func(t *testing.T) {
invalidFile := `
foreach "a" {
collection = [5]
var = "item"
template {}
}
`
l := controller.NewLoader(newLoaderOptions())
diags := applyFromContent(t, l, nil, []byte(invalidFile), nil)
require.ErrorContains(t, diags.ErrorOrNil(), `config block "foreach" is at stability level "experimental", which is below the minimum allowed stability level "public-preview". Use --stability.level command-line flag to enable "experimental"`)
})
}

func TestLoader_Services(t *testing.T) {
Expand Down
27 changes: 26 additions & 1 deletion internal/runtime/internal/controller/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"fmt"

"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/runtime/internal/importsource"
"github.com/grafana/alloy/syntax/ast"
"github.com/grafana/alloy/syntax/diag"
Expand All @@ -16,9 +17,26 @@ const (
foreachID = "foreach"
)

// Add config blocks that are not GA. Config blocks that are not specified here are considered GA.
var configBlocksUnstable = map[string]featuregate.Stability{
foreachID: featuregate.StabilityExperimental,
}

// NewConfigNode creates a new ConfigNode from an initial ast.BlockStmt.
// The underlying config isn't applied until Evaluate is called.
func NewConfigNode(block *ast.BlockStmt, globals ComponentGlobals, customReg *CustomComponentRegistry) (BlockNode, diag.Diagnostics) {
var diags diag.Diagnostics

if err := checkFeatureStability(block.GetBlockName(), globals.MinStability); err != nil {
diags.Add(diag.Diagnostic{
Severity: diag.SeverityLevelError,
Message: err.Error(),
StartPos: ast.StartPos(block).Position(),
EndPos: ast.EndPos(block).Position(),
})
return nil, diags
}

switch block.GetBlockName() {
case argumentBlockID:
return NewArgumentConfigNode(block, globals), nil
Expand All @@ -33,7 +51,6 @@ func NewConfigNode(block *ast.BlockStmt, globals ComponentGlobals, customReg *Cu
case foreachID:
return NewForeachConfigNode(block, globals, customReg), nil
default:
var diags diag.Diagnostics
diags.Add(diag.Diagnostic{
Severity: diag.SeverityLevelError,
Message: fmt.Sprintf("invalid config block type %s while creating new config node", block.GetBlockName()),
Expand All @@ -44,6 +61,14 @@ func NewConfigNode(block *ast.BlockStmt, globals ComponentGlobals, customReg *Cu
}
}

func checkFeatureStability(blockName string, minStability featuregate.Stability) error {
blockStability, exist := configBlocksUnstable[blockName]
if exist {
return featuregate.CheckAllowed(blockStability, minStability, fmt.Sprintf("config block %q", blockName))
}
return nil
}

// ConfigNodeMap represents the config BlockNodes in their explicit types.
// This is helpful when validating node conditions specific to config node
// types.
Expand Down
Loading