Skip to content

Commit

Permalink
use custom args instead of local.file args for import.file
Browse files Browse the repository at this point in the history
import.file should not have "isSecret" arg because the imported module is not exported.
It should then not use the same args as local.file
  • Loading branch information
wildum committed Feb 16, 2024
1 parent e543e32 commit 1221f5d
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions pkg/flow/internal/importsource/import_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"time"

"github.com/grafana/agent/component"
"github.com/grafana/agent/component/local/file"
Expand Down Expand Up @@ -31,13 +32,28 @@ func NewImportFile(managedOpts component.Options, eval *vm.Evaluator, onContentC
}
}

// Arguments holds values which are used to configure the local.file component.
type Arguments struct {
// Filename indicates the file to watch.
Filename string `river:"filename,attr"`
// Type indicates how to detect changes to the file.
Type file.Detector `river:"detector,attr,optional"`
// PollFrequency determines the frequency to check for changes when Type is Poll.
PollFrequency time.Duration `river:"poll_frequency,attr,optional"`
}

var DefaultArguments = Arguments{
Type: file.DetectorFSNotify,
PollFrequency: time.Minute,
}

type importFileConfigBlock struct {
LocalFileArguments file.Arguments `river:",squash"`
LocalFileArguments Arguments `river:",squash"`
}

// SetToDefault implements river.Defaulter.
func (a *importFileConfigBlock) SetToDefault() {
a.LocalFileArguments = file.DefaultArguments
a.LocalFileArguments = DefaultArguments
}

func (im *ImportFile) Evaluate(scope *vm.Scope) error {
Expand All @@ -47,7 +63,13 @@ func (im *ImportFile) Evaluate(scope *vm.Scope) error {
}
if im.fileComponent == nil {
var err error
im.fileComponent, err = file.New(im.managedOpts, arguments.LocalFileArguments)
im.fileComponent, err = file.New(im.managedOpts, file.Arguments{
Filename: arguments.LocalFileArguments.Filename,
Type: arguments.LocalFileArguments.Type,
PollFrequency: arguments.LocalFileArguments.PollFrequency,
// isSecret is only used for exported values; modules are not exported
IsSecret: false,
})
if err != nil {
return fmt.Errorf("creating file component: %w", err)
}
Expand Down

0 comments on commit 1221f5d

Please sign in to comment.