Skip to content

Commit

Permalink
Add error if the logging or tracing config block exists in a module (g…
Browse files Browse the repository at this point in the history
…rafana#3289)

* Add error if the logging or tracing config block exists in a module
* Return err if a module component fails to start in module.string.go
  • Loading branch information
erikbaranowski committed Mar 15, 2023
1 parent d9c4e55 commit 4ba5062
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
42 changes: 3 additions & 39 deletions component/module/string/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package string
import (
"context"
"net/http"
"sync"
"time"

"github.com/go-kit/log"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -51,15 +49,11 @@ type Component struct {
opts component.Options
log log.Logger
ctrl *flow.Flow

healthMut sync.RWMutex
health component.Health
}

var (
_ component.Component = (*Component)(nil)
_ component.HealthComponent = (*Component)(nil)
_ component.HTTPComponent = (*Component)(nil)
_ component.Component = (*Component)(nil)
_ component.HTTPComponent = (*Component)(nil)
)

// New creates a new module.string component.
Expand Down Expand Up @@ -101,25 +95,6 @@ func (c *Component) Run(ctx context.Context) error {
return nil
}

func (c *Component) updateHealth(err error) {
c.healthMut.Lock()
defer c.healthMut.Unlock()

if err == nil {
c.health = component.Health{
Health: component.HealthTypeHealthy,
Message: "module updated",
UpdateTime: time.Now(),
}
} else {
c.health = component.Health{
Health: component.HealthTypeUnhealthy,
Message: err.Error(),
UpdateTime: time.Now(),
}
}
}

// Update implements component.Component.
func (c *Component) Update(args component.Arguments) error {
newArgs := args.(Arguments)
Expand All @@ -129,18 +104,7 @@ func (c *Component) Update(args component.Arguments) error {
return err
}

err = c.ctrl.LoadFile(f, newArgs.Arguments)
c.updateHealth(err)

return nil
}

// CurrentHealth implements component.HealthComponent.
func (c *Component) CurrentHealth() component.Health {
c.healthMut.RLock()
defer c.healthMut.RUnlock()

return c.health
return c.ctrl.LoadFile(f, newArgs.Arguments)
}

// Handler implements component.HTTPComponent.
Expand Down
18 changes: 17 additions & 1 deletion pkg/flow/internal/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,30 @@ func NewConfigNode(blocks []*ast.BlockStmt, globals ComponentGlobals, isInModule
case loggingBlockID:
loggingBlock = *b
foundLogging = true
if isInModule {
diags.Add(diag.Diagnostic{
Severity: diag.SeverityLevelError,
Message: "logging block not allowed inside a module",
StartPos: ast.StartPos(b).Position(),
EndPos: ast.EndPos(b).Position(),
})
}
case tracingBlockID:
tracingBlock = *b
foundTracing = true
if isInModule {
diags.Add(diag.Diagnostic{
Severity: diag.SeverityLevelError,
Message: "tracing block not allowed inside a module",
StartPos: ast.StartPos(b).Position(),
EndPos: ast.EndPos(b).Position(),
})
}
case exportBlockID:
if !isInModule {
diags.Add(diag.Diagnostic{
Severity: diag.SeverityLevelError,
Message: "export blocks not allowed when not using modules",
Message: "export blocks only allowed inside a module",
StartPos: ast.StartPos(b).Position(),
EndPos: ast.EndPos(b).Position(),
})
Expand Down

0 comments on commit 4ba5062

Please sign in to comment.