Skip to content

Commit

Permalink
internal: rename all River references to Alloy
Browse files Browse the repository at this point in the history
This also includes renaming file extensions from `.river` to `.alloy`.
  • Loading branch information
rfratto committed Mar 27, 2024
1 parent a303bce commit 357ae19
Show file tree
Hide file tree
Showing 509 changed files with 1,877 additions and 1,811 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN <<EOF
EOF

COPY --from=build /src/alloy/build/alloy /bin/alloy
COPY example-config.river /etc/alloy/config.river
COPY example-config.alloy /etc/alloy/config.alloy

# Create alloy user in container, but do not set it as default
RUN groupadd --gid $UID $USERNAME
Expand All @@ -56,4 +56,4 @@ RUN chown -R $USERNAME:$USERNAME /bin/alloy

ENTRYPOINT ["/bin/alloy"]
ENV ALLOY_DEPLOY_MODE=docker
CMD ["run", "/etc/alloy/config.river", "--storage.path=/etc/alloy/data"]
CMD ["run", "/etc/alloy/config.alloy", "--storage.path=/etc/alloy/data"]
4 changes: 2 additions & 2 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ RUN ""C:\Program Files\git\bin\bash.exe" -c "go clean -cache -modcache""
FROM mcr.microsoft.com/windows/nanoserver:1809

COPY --from=builder /src/alloy/build/alloy /bin/alloy
COPY --from=builder /src/alloy/example-config.river /etc/alloy/config.river
COPY --from=builder /src/alloy/example-config.alloy /etc/alloy/config.alloy

ENTRYPOINT ["/bin/alloy"]
ENV ALLOY_DEPLOY_MODE=docker
CMD ["run", "/etc/alloy/config.river", "--storage.path=/etc/alloy/data"]
CMD ["run", "/etc/alloy/config.alloy", "--storage.path=/etc/alloy/data"]
File renamed without changes.
6 changes: 3 additions & 3 deletions internal/alloy/alloy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//
// # Components
//
// Each component has a set of arguments (River attributes and blocks) and
// Each component has a set of arguments (Alloy attributes and blocks) and
// optionally a set of exported fields. Components can reference the exports of
// other components using River expressions.
// other components using Alloy expressions.
//
// See the top-level component package for more information on components, and
// subpackages for defined components.
Expand All @@ -29,7 +29,7 @@
//
// # Node Evaluation
//
// The process of converting the River block associated with a node into
// The process of converting the Alloy block associated with a node into
// the appropriate Go struct is called "node evaluation."
//
// Nodes are only evaluated after all nodes they reference have been
Expand Down
4 changes: 2 additions & 2 deletions internal/alloy/import_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestPullUpdating(t *testing.T) {
main := `
import.git "testImport" {
repository = "` + testRepo + `"
path = "math.river"
path = "math.alloy"
pull_frequency = "5s"
}
Expand All @@ -48,7 +48,7 @@ testImport.add "cc" {
init := exec.Command("git", "init", testRepo)
err := init.Run()
require.NoError(t, err)
math := filepath.Join(testRepo, "math.river")
math := filepath.Join(testRepo, "math.alloy")
err = os.WriteFile(math, []byte(contents), 0666)
require.NoError(t, err)
add := exec.Command("git", "add", ".")
Expand Down
107 changes: 57 additions & 50 deletions internal/alloy/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
"github.com/grafana/alloy/internal/alloy/logging"
"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/service"
"github.com/grafana/alloy/internal/util"
"github.com/stretchr/testify/require"
"golang.org/x/tools/txtar"

_ "github.com/grafana/alloy/internal/alloy/internal/testcomponents/module/string"
)

// use const to avoid lint error
const mainFile = "main.river"
const mainFile = "main.alloy"

// The tests are using the .txtar files stored in the testdata folder.
type testImportFile struct {
Expand All @@ -45,30 +46,30 @@ func buildTestImportFile(t *testing.T, filename string) testImportFile {
require.NoError(t, err)
var tc testImportFile
tc.description = string(archive.Comment)
for _, riverConfig := range archive.Files {
switch riverConfig.Name {
for _, alloyConfig := range archive.Files {
switch alloyConfig.Name {
case mainFile:
tc.main = string(riverConfig.Data)
case "module.river":
tc.module = string(riverConfig.Data)
case "nested_module.river":
tc.nestedModule = string(riverConfig.Data)
case "update/module.river":
tc.main = string(alloyConfig.Data)
case "module.alloy":
tc.module = string(alloyConfig.Data)
case "nested_module.alloy":
tc.nestedModule = string(alloyConfig.Data)
case "update/module.alloy":
require.Nil(t, tc.update)
tc.update = &updateFile{
name: "module.river",
updateConfig: string(riverConfig.Data),
name: "module.alloy",
updateConfig: string(alloyConfig.Data),
}
case "update/nested_module.river":
case "update/nested_module.alloy":
require.Nil(t, tc.update)
tc.update = &updateFile{
name: "nested_module.river",
updateConfig: string(riverConfig.Data),
name: "nested_module.alloy",
updateConfig: string(alloyConfig.Data),
}
case "reload_config.river":
tc.reloadConfig = string(riverConfig.Data)
case "other_nested_module.river":
tc.otherNestedModule = string(riverConfig.Data)
case "reload_config.alloy":
tc.reloadConfig = string(alloyConfig.Data)
case "other_nested_module.alloy":
tc.otherNestedModule = string(alloyConfig.Data)
}
}
return tc
Expand All @@ -79,15 +80,15 @@ func TestImportFile(t *testing.T) {
for _, file := range getTestFiles(directory, t) {
tc := buildTestImportFile(t, filepath.Join(directory, file.Name()))
t.Run(tc.description, func(t *testing.T) {
defer os.Remove("module.river")
require.NoError(t, os.WriteFile("module.river", []byte(tc.module), 0664))
defer os.Remove("module.alloy")
require.NoError(t, os.WriteFile("module.alloy", []byte(tc.module), 0664))
if tc.nestedModule != "" {
defer os.Remove("nested_module.river")
require.NoError(t, os.WriteFile("nested_module.river", []byte(tc.nestedModule), 0664))
defer os.Remove("nested_module.alloy")
require.NoError(t, os.WriteFile("nested_module.alloy", []byte(tc.nestedModule), 0664))
}
if tc.otherNestedModule != "" {
defer os.Remove("other_nested_module.river")
require.NoError(t, os.WriteFile("other_nested_module.river", []byte(tc.otherNestedModule), 0664))
defer os.Remove("other_nested_module.alloy")
require.NoError(t, os.WriteFile("other_nested_module.alloy", []byte(tc.otherNestedModule), 0664))
}

if tc.update != nil {
Expand All @@ -113,6 +114,12 @@ func TestImportString(t *testing.T) {
}

func TestImportGit(t *testing.T) {
// Extract repo.git.tar so tests can make use of it.
// Make repo.git.tar with:
// tar -C repo.git -cvf repo.git.tar .
_ = os.RemoveAll("./testdata/repo.tar")
require.NoError(t, util.Untar("./testdata/repo.git.tar", "./testdata/repo.git"))

directory := "./testdata/import_git"
for _, file := range getTestFiles(directory, t) {
archive, err := txtar.ParseFile(filepath.Join(directory, file.Name()))
Expand Down Expand Up @@ -149,29 +156,29 @@ func buildTestImportFileFolder(t *testing.T, filename string) testImportFileFold
require.NoError(t, err)
var tc testImportFileFolder
tc.description = string(archive.Comment)
for _, riverConfig := range archive.Files {
switch riverConfig.Name {
for _, alloyConfig := range archive.Files {
switch alloyConfig.Name {
case mainFile:
tc.main = string(riverConfig.Data)
case "module1.river":
tc.module1 = string(riverConfig.Data)
case "module2.river":
tc.module2 = string(riverConfig.Data)
case "added.river":
tc.added = string(riverConfig.Data)
case "removed.river":
tc.removed = string(riverConfig.Data)
case "update/module1.river":
tc.main = string(alloyConfig.Data)
case "module1.alloy":
tc.module1 = string(alloyConfig.Data)
case "module2.alloy":
tc.module2 = string(alloyConfig.Data)
case "added.alloy":
tc.added = string(alloyConfig.Data)
case "removed.alloy":
tc.removed = string(alloyConfig.Data)
case "update/module1.alloy":
require.Nil(t, tc.update)
tc.update = &updateFile{
name: "module1.river",
updateConfig: string(riverConfig.Data),
name: "module1.alloy",
updateConfig: string(alloyConfig.Data),
}
case "update/module2.river":
case "update/module2.alloy":
require.Nil(t, tc.update)
tc.update = &updateFile{
name: "module2.river",
updateConfig: string(riverConfig.Data),
name: "module2.alloy",
updateConfig: string(alloyConfig.Data),
}
}
}
Expand All @@ -188,27 +195,27 @@ func TestImportFileFolder(t *testing.T) {
defer os.RemoveAll(dir)

if tc.module1 != "" {
require.NoError(t, os.WriteFile(filepath.Join(dir, "module1.river"), []byte(tc.module1), 0700))
require.NoError(t, os.WriteFile(filepath.Join(dir, "module1.alloy"), []byte(tc.module1), 0700))
}

if tc.module2 != "" {
require.NoError(t, os.WriteFile(filepath.Join(dir, "module2.river"), []byte(tc.module2), 0700))
require.NoError(t, os.WriteFile(filepath.Join(dir, "module2.alloy"), []byte(tc.module2), 0700))
}

if tc.removed != "" {
require.NoError(t, os.WriteFile(filepath.Join(dir, "removed.river"), []byte(tc.removed), 0700))
require.NoError(t, os.WriteFile(filepath.Join(dir, "removed.alloy"), []byte(tc.removed), 0700))
}

// TODO: ideally we would like to check the health of the node but that's not yet possible for import nodes.
// We should expect that adding or removing files in the dir is gracefully handled and the node should be
// healthy once it polls the content of the dir again.
testConfig(t, tc.main, "", func() {
if tc.removed != "" {
os.Remove(filepath.Join(dir, "removed.river"))
os.Remove(filepath.Join(dir, "removed.alloy"))
}

if tc.added != "" {
require.NoError(t, os.WriteFile(filepath.Join(dir, "added.river"), []byte(tc.added), 0700))
require.NoError(t, os.WriteFile(filepath.Join(dir, "added.alloy"), []byte(tc.added), 0700))
}
if tc.update != nil {
require.NoError(t, os.WriteFile(filepath.Join(dir, tc.update.name), []byte(tc.update.updateConfig), 0700))
Expand All @@ -229,12 +236,12 @@ func buildTestImportError(t *testing.T, filename string) testImportError {
require.NoError(t, err)
var tc testImportError
tc.description = string(archive.Comment)
for _, riverConfig := range archive.Files {
switch riverConfig.Name {
for _, alloyConfig := range archive.Files {
switch alloyConfig.Name {
case mainFile:
tc.main = string(riverConfig.Data)
tc.main = string(alloyConfig.Data)
case "error":
tc.expectedError = string(riverConfig.Data)
tc.expectedError = string(alloyConfig.Data)
}
}
return tc
Expand Down
8 changes: 4 additions & 4 deletions internal/alloy/internal/controller/block_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"github.com/grafana/alloy/syntax/vm"
)

// BlockNode is a node in the DAG which manages a River block
// BlockNode is a node in the DAG which manages an Alloy block
// and can be evaluated.
type BlockNode interface {
dag.Node

// Block returns the current block managed by the node.
Block() *ast.BlockStmt

// Evaluate updates the arguments by re-evaluating the River block with the provided scope.
// Evaluate updates the arguments by re-evaluating the Alloy block with the provided scope.
//
// Evaluate will return an error if the River block cannot be evaluated or if
// Evaluate will return an error if the Alloy block cannot be evaluated or if
// decoding to arguments fails.
Evaluate(scope *vm.Scope) error

// UpdateBlock updates the River block used to construct arguments.
// UpdateBlock updates the Alloy block used to construct arguments.
UpdateBlock(b *ast.BlockStmt)
}
2 changes: 1 addition & 1 deletion internal/alloy/internal/controller/component_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ComponentNode interface {
// ComponentName returns the name of the component.
ComponentName() string

// ID returns the component ID of the managed component from its River block.
// ID returns the component ID of the managed component from its Alloy block.
ID() ComponentID

// ModuleIDs returns the current list of modules managed by the component.
Expand Down
2 changes: 1 addition & 1 deletion internal/alloy/internal/controller/component_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// will be (field_a, field_b, field_c).
type Traversal []*ast.Ident

// Reference describes an River expression reference to a BlockNode.
// Reference describes an Alloy expression reference to a BlockNode.
type Reference struct {
Target BlockNode // BlockNode being referenced

Expand Down
10 changes: 5 additions & 5 deletions internal/alloy/internal/controller/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"go.opentelemetry.io/otel/trace"
)

// The Loader builds and evaluates ComponentNodes from River blocks.
// The Loader builds and evaluates ComponentNodes from Alloy blocks.
type Loader struct {
log log.Logger
tracer trace.TracerProvider
Expand Down Expand Up @@ -111,7 +111,7 @@ func NewLoader(opts LoaderOptions) *Loader {
return l
}

// ApplyOptions are options that can be provided when loading a new River config.
// ApplyOptions are options that can be provided when loading a new Alloy config.
type ApplyOptions struct {
Args map[string]any // input values of a module (nil for the root module)

Expand All @@ -127,12 +127,12 @@ type ApplyOptions struct {
}

// Apply loads a new set of components into the Loader. Apply will drop any
// previously loaded component which is not described in the set of River
// previously loaded component which is not described in the set of Alloy
// blocks.
//
// Apply will reuse existing components if there is an existing component which
// matches the component ID specified by any of the provided River blocks.
// Reused components will be updated to point at the new River block.
// matches the component ID specified by any of the provided Alloy blocks.
// Reused components will be updated to point at the new Alloy block.
//
// Apply will perform an evaluation of all loaded components before returning.
// The provided parentContext can be used to provide global variables and
Expand Down
2 changes: 1 addition & 1 deletion internal/alloy/internal/controller/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ModuleController interface {

// CustomComponent is a controller for running components within a CustomComponent.
type CustomComponent interface {
// LoadBody loads a River AST body into the CustomComponent. LoadBody can be called
// LoadBody loads an Alloy AST body into the CustomComponent. LoadBody can be called
// multiple times, and called prior to [CustomComponent.Run].
// customComponentRegistry provides custom component definitions for the loaded config.
LoadBody(body ast.Body, args map[string]any, customComponentRegistry *CustomComponentRegistry) error
Expand Down
Loading

0 comments on commit 357ae19

Please sign in to comment.