Skip to content

Commit

Permalink
Merge pull request #76 from grafana/rename-flowmode-flow-packages
Browse files Browse the repository at this point in the history
Rename internal/flowmode and internal/flow
  • Loading branch information
rfratto authored Mar 25, 2024
2 parents e8e6707 + 0e044c0 commit 0250859
Show file tree
Hide file tree
Showing 296 changed files with 452 additions and 452 deletions.
4 changes: 2 additions & 2 deletions cmd/alloy/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"github.com/grafana/alloy/internal/alloycli"
"github.com/grafana/alloy/internal/build"
"github.com/grafana/alloy/internal/flowmode"
"github.com/prometheus/client_golang/prometheus"

// Register Prometheus SD components
Expand All @@ -22,5 +22,5 @@ func init() {
}

func main() {
flowmode.Run()
alloycli.Run()
}
4 changes: 2 additions & 2 deletions docs/sources/reference/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The following flags are supported:
* `--cluster.advertise-interfaces`: List of interfaces used to infer an address to advertise. Set to `all` to use all available network interfaces on the system. (default `"eth0,en0"`).
* `--cluster.max-join-peers`: Number of peers to join from the discovered set (default `5`).
* `--cluster.name`: Name to prevent nodes without this identifier from joining the cluster (default `""`).
* `--config.format`: The format of the source file. Supported formats: `flow`, `prometheus`, `promtail`, `static` (default `"flow"`).
* `--config.format`: The format of the source file. Supported formats: `alloy`, `prometheus`, `promtail`, `static` (default `"alloy"`).
* `--config.bypass-conversion-errors`: Enable bypassing errors when converting (default `false`).
* `--config.extra-args`: Extra arguments from the original format used by the converter.

Expand Down Expand Up @@ -128,7 +128,7 @@ The current state of a clustered {{< param "PRODUCT_ROOT_NAME" >}} is shown on t

## Configuration conversion (beta)

When you use the `--config.format` command-line argument with a value other than `flow`, {{< param "PRODUCT_ROOT_NAME" >}} converts the configuration file from the source format to River and immediately starts running with the new configuration.
When you use the `--config.format` command-line argument with a value other than `alloy`, {{< param "PRODUCT_ROOT_NAME" >}} converts the configuration file from the source format to River and immediately starts running with the new configuration.
This conversion uses the converter API described in the [grafana-alloy convert][] docs.

If you include the `--config.bypass-conversion-errors` command-line argument,
Expand Down
58 changes: 29 additions & 29 deletions internal/flow/flow.go → internal/alloy/alloy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package flow implements the Flow component graph system. Flow configuration
// sources are parsed from River, which contain a listing of components to run.
// Package alloy implements the Alloy component graph system. Alloy configuration
// sources are parsed from Alloy syntax, which contain a listing of components to run.
//
// # Components
//
Expand All @@ -23,7 +23,7 @@
// and a message providing more detail for the health state.
//
// Components can report their own health states. The health state reported by
// a component is merged with the Flow-level health of that component: an error
// a component is merged with the Alloy-level health of that component: an error
// when evaluating the configuration for a component will always be reported as
// unhealthy until the next successful evaluation.
//
Expand All @@ -43,32 +43,32 @@
// state if a node shuts down or is given an invalid config. This prevents
// a domino effect of a single failed node taking down other node
// which are otherwise healthy.
package flow
package alloy

import (
"context"
"fmt"
"sync"
"time"

"github.com/grafana/alloy/internal/alloy/internal/controller"
"github.com/grafana/alloy/internal/alloy/internal/worker"
"github.com/grafana/alloy/internal/alloy/logging"
"github.com/grafana/alloy/internal/alloy/logging/level"
"github.com/grafana/alloy/internal/alloy/tracing"
"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/flow/internal/controller"
"github.com/grafana/alloy/internal/flow/internal/worker"
"github.com/grafana/alloy/internal/flow/logging"
"github.com/grafana/alloy/internal/flow/logging/level"
"github.com/grafana/alloy/internal/flow/tracing"
"github.com/grafana/alloy/internal/service"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/atomic"
)

// Options holds static options for a flow controller.
// Options holds static options for an Alloy controller.
type Options struct {
// ControllerID is an identifier used to represent the controller.
// ControllerID is used to generate a globally unique display name for
// components in a binary where multiple controllers are used.
//
// If running multiple Flow controllers, each controller must have a
// If running multiple Alloy controllers, each controller must have a
// different value for ControllerID to be able to differentiate between
// components in telemetry data.
ControllerID string
Expand All @@ -84,7 +84,7 @@ type Options struct {
// Directory where components can write data. Constructed components will be
// given a subdirectory of DataPath using the local ID of the component.
//
// If running multiple Flow controllers, each controller must have a
// If running multiple Alloy controllers, each controller must have a
// different value for DataPath to prevent components from colliding.
DataPath string

Expand All @@ -101,15 +101,15 @@ type Options struct {
// loaded config source.
OnExportsChange func(exports map[string]any)

// List of Services to run with the Flow controller.
// List of Services to run with the Alloy controller.
//
// Services are configured when LoadFile is invoked. Services are started
// when the Flow controller runs after LoadFile is invoked at least once.
// when the Alloy controller runs after LoadFile is invoked at least once.
Services []service.Service
}

// Flow is the Flow system.
type Flow struct {
// Alloy is the Alloy system.
type Alloy struct {
log *logging.Logger
tracer *tracing.Tracer
opts controllerOptions
Expand All @@ -125,8 +125,8 @@ type Flow struct {
loadedOnce atomic.Bool
}

// New creates a new, unstarted Flow controller. Call Run to run the controller.
func New(o Options) *Flow {
// New creates a new, unstarted Alloy controller. Call Run to run the controller.
func New(o Options) *Alloy {
return newController(controllerOptions{
Options: o,
ModuleRegistry: newModuleRegistry(),
Expand All @@ -135,7 +135,7 @@ func New(o Options) *Flow {
})
}

// controllerOptions are internal options used to create both root Flow
// controllerOptions are internal options used to create both root Alloy
// controller and controllers for modules.
type controllerOptions struct {
Options
Expand All @@ -147,10 +147,10 @@ type controllerOptions struct {
WorkerPool worker.Pool
}

// newController creates a new, unstarted Flow controller with a specific
// newController creates a new, unstarted Alloy controller with a specific
// moduleRegistry. Modules created by the controller will be passed to the
// given modReg.
func newController(o controllerOptions) *Flow {
func newController(o controllerOptions) *Alloy {
var (
log = o.Logger
tracer = o.Tracer
Expand All @@ -171,7 +171,7 @@ func newController(o controllerOptions) *Flow {
workerPool = worker.NewDefaultWorkerPool()
}

f := &Flow{
f := &Alloy{
log: log,
tracer: tracer,
opts: o,
Expand Down Expand Up @@ -231,12 +231,12 @@ func newController(o controllerOptions) *Flow {
return f
}

// Run starts the Flow controller, blocking until the provided context is
// Run starts the Alloy controller, blocking until the provided context is
// canceled. Run must only be called once.
func (f *Flow) Run(ctx context.Context) {
func (f *Alloy) Run(ctx context.Context) {
defer func() { _ = f.sched.Close() }()
defer f.loader.Cleanup(!f.opts.IsModule)
defer level.Debug(f.log).Log("msg", "flow controller exiting")
defer level.Debug(f.log).Log("msg", "Alloy controller exiting")

for {
select {
Expand Down Expand Up @@ -290,12 +290,12 @@ func (f *Flow) Run(ctx context.Context) {
// The controller will only start running components after Load is called once
// without any configuration errors.
// LoadSource uses default loader configuration.
func (f *Flow) LoadSource(source *Source, args map[string]any) error {
func (f *Alloy) LoadSource(source *Source, args map[string]any) error {
return f.loadSource(source, args, nil)
}

// Same as above but with a customComponentRegistry that provides custom component definitions.
func (f *Flow) loadSource(source *Source, args map[string]any, customComponentRegistry *controller.CustomComponentRegistry) error {
func (f *Alloy) loadSource(source *Source, args map[string]any, customComponentRegistry *controller.CustomComponentRegistry) error {
f.loadMut.Lock()
defer f.loadMut.Unlock()

Expand Down Expand Up @@ -323,7 +323,7 @@ func (f *Flow) loadSource(source *Source, args map[string]any, customComponentRe
return diags.ErrorOrNil()
}

// Ready returns whether the Flow controller has finished its initial load.
func (f *Flow) Ready() bool {
// Ready returns whether the Alloy controller has finished its initial load.
func (f *Alloy) Ready() bool {
return f.loadedOnce.Load()
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package flow
package alloy

import (
"fmt"

"github.com/grafana/alloy/internal/alloy/internal/controller"
"github.com/grafana/alloy/internal/alloy/internal/dag"
"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/flow/internal/controller"
"github.com/grafana/alloy/internal/flow/internal/dag"
)

// GetComponent implements [component.Provider].
func (f *Flow) GetComponent(id component.ID, opts component.InfoOptions) (*component.Info, error) {
func (f *Alloy) GetComponent(id component.ID, opts component.InfoOptions) (*component.Info, error) {
f.loadMut.RLock()
defer f.loadMut.RUnlock()

Expand Down Expand Up @@ -38,7 +38,7 @@ func (f *Flow) GetComponent(id component.ID, opts component.InfoOptions) (*compo
}

// ListComponents implements [component.Provider].
func (f *Flow) ListComponents(moduleID string, opts component.InfoOptions) ([]*component.Info, error) {
func (f *Alloy) ListComponents(moduleID string, opts component.InfoOptions) ([]*component.Info, error) {
f.loadMut.RLock()
defer f.loadMut.RUnlock()

Expand All @@ -63,7 +63,7 @@ func (f *Flow) ListComponents(moduleID string, opts component.InfoOptions) ([]*c
return detail, nil
}

func (f *Flow) getComponentDetail(cn controller.ComponentNode, graph *dag.Graph, opts component.InfoOptions) *component.Info {
func (f *Alloy) getComponentDetail(cn controller.ComponentNode, graph *dag.Graph, opts component.InfoOptions) *component.Info {
var references, referencedBy []string

// Skip over any edge which isn't between two component nodes. This is a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package flow
package alloy

import (
"context"

"github.com/grafana/alloy/internal/flow/internal/controller"
"github.com/grafana/alloy/internal/flow/internal/dag"
"github.com/grafana/alloy/internal/flow/internal/worker"
"github.com/grafana/alloy/internal/alloy/internal/controller"
"github.com/grafana/alloy/internal/alloy/internal/dag"
"github.com/grafana/alloy/internal/alloy/internal/worker"
"github.com/grafana/alloy/internal/service"
)

// GetServiceConsumers implements [service.Host]. It returns a slice of
// [component.Component] and [service.Service]s which declared a dependency on
// the named service.
func (f *Flow) GetServiceConsumers(serviceName string) []service.Consumer {
func (f *Alloy) GetServiceConsumers(serviceName string) []service.Consumer {
consumers := serviceConsumersForGraph(f.loader.OriginalGraph(), serviceName, true)

// Iterate through all modules to find other components that depend on the
Expand All @@ -28,7 +28,7 @@ func (f *Flow) GetServiceConsumers(serviceName string) []service.Consumer {

// GetService implements [service.Host]. It looks up a [service.Service] by
// name.
func (f *Flow) GetService(name string) (service.Service, bool) {
func (f *Alloy) GetService(name string) (service.Service, bool) {
for _, svc := range f.opts.Services {
if svc.Definition().Name == name {
return svc, true
Expand Down Expand Up @@ -67,9 +67,9 @@ func serviceConsumersForGraph(graph *dag.Graph, serviceName string, includePeerS
return consumers
}

// NewController returns a new, unstarted, isolated Flow controller so that
// NewController returns a new, unstarted, isolated Alloy controller so that
// services can instantiate their own components.
func (f *Flow) NewController(id string) service.Controller {
func (f *Alloy) NewController(id string) service.Controller {
return serviceController{
f: newController(controllerOptions{
Options: Options{
Expand All @@ -90,7 +90,7 @@ func (f *Flow) NewController(id string) service.Controller {
}

type serviceController struct {
f *Flow
f *Alloy
}

func (sc serviceController) Run(ctx context.Context) { sc.f.Run(ctx) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package flow
package alloy

import (
"context"
"testing"
"time"

"github.com/grafana/alloy/internal/alloy/internal/controller"
"github.com/grafana/alloy/internal/alloy/internal/testcomponents"
"github.com/grafana/alloy/internal/alloy/internal/testservices"
"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/flow/internal/controller"
"github.com/grafana/alloy/internal/flow/internal/testcomponents"
"github.com/grafana/alloy/internal/flow/internal/testservices"
"github.com/grafana/alloy/internal/service"
"github.com/grafana/alloy/internal/util"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestServices_Configurable_Optional(t *testing.T) {
require.NoError(t, updateCalled.Wait(5*time.Second), "Service was not configured")
}

func TestFlow_GetServiceConsumers(t *testing.T) {
func TestAlloy_GetServiceConsumers(t *testing.T) {
defer verifyNoGoroutineLeaks(t)
var (
svcA = &testservices.Fake{
Expand Down
12 changes: 6 additions & 6 deletions internal/flow/flow_test.go → internal/alloy/alloy_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package flow
package alloy

import (
"context"
"os"
"testing"

"github.com/grafana/alloy/internal/alloy/internal/controller"
"github.com/grafana/alloy/internal/alloy/internal/dag"
"github.com/grafana/alloy/internal/alloy/internal/testcomponents"
"github.com/grafana/alloy/internal/alloy/logging"
"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/flow/internal/controller"
"github.com/grafana/alloy/internal/flow/internal/dag"
"github.com/grafana/alloy/internal/flow/internal/testcomponents"
"github.com/grafana/alloy/internal/flow/logging"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ func testOptions(t *testing.T) Options {
}
}

func cleanUpController(ctrl *Flow) {
func cleanUpController(ctrl *Alloy) {
// To avoid leaking goroutines and clean-up, we need to run and shut down the controller.
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package flow
package alloy

import (
"context"
"testing"
"time"

"github.com/grafana/alloy/internal/flow/internal/testcomponents"
"github.com/grafana/alloy/internal/flow/internal/worker"
"github.com/grafana/alloy/internal/alloy/internal/testcomponents"
"github.com/grafana/alloy/internal/alloy/internal/worker"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -370,7 +370,7 @@ func TestController_Updates_WithLaggingComponent(t *testing.T) {
require.Equal(t, 10, in.(testcomponents.SummationConfig).Input)
}

func newTestController(t *testing.T) *Flow {
func newTestController(t *testing.T) *Alloy {
return newController(controllerOptions{
Options: testOptions(t),
ModuleRegistry: newModuleRegistry(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package componenttest provides utilities for testing Flow components.
// Package componenttest provides utilities for testing components.
package componenttest

import (
Expand All @@ -14,8 +14,8 @@ import (
"go.uber.org/atomic"

"github.com/go-kit/log"
"github.com/grafana/alloy/internal/alloy/logging"
"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/flow/logging"
"go.opentelemetry.io/otel/trace/noop"
)

Expand Down
File renamed without changes.
Loading

0 comments on commit 0250859

Please sign in to comment.