Skip to content

Commit

Permalink
Merge branch 'main' into pablo/loki-write-drain-on-stop
Browse files Browse the repository at this point in the history
  • Loading branch information
thepalbi authored Nov 23, 2023
2 parents b64184b + 6404d29 commit a1033f7
Show file tree
Hide file tree
Showing 62 changed files with 612 additions and 705 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
with:
go-version: "1.21"
- name: Set OTEL Exporter Endpoint
run: echo "OTEL_EXPORTER_ENDPOINT=http://172.17.0.1:8080" >> $GITHUB_ENV
run: echo "OTEL_EXPORTER_ENDPOINT=172.17.0.1:4318" >> $GITHUB_ENV
- name: Run tests
run: make integration-test
27 changes: 18 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ Main (unreleased)

### Features

- Added support for `loki.write` to flush WAL on agent shutdown. (@thepalbi)
- Agent Management: Introduce support for templated configuration. (@jcreixell)

v0.38.0-rc.1 (2023-11-20)
-------------------------
- Added support for `loki.write` to flush WAL on agent shutdown. (@thepalbi)

### Enhancements

- Allow agent to start with `module.git` config if cached before. (@hainenber)
- Flow Windows service: Support environment variables. (@jkroepke)

### Bugfixes

- Fix default configuration file `grafana-agent-flow.river` used in downstream packages. (@bricewge)
- Permit `X-Faro-Session-ID` header in CORS requests for the `faro.receiver`
component (flow mode) and the `app_agent_receiver` integration (static mode).
(@cedricziel)

- Fix converter output for prometheus.exporter.windows to not unnecessarily add empty blocks. (@erikbaranowski)
- Fix issue with windows_exporter defaults not being set correctly. (@mattdurham)

v0.38.0-rc.0 (2023-11-16)
-------------------------
v0.38.0 (2023-11-21)
--------------------

### Breaking changes

Expand Down Expand Up @@ -123,6 +124,8 @@ v0.38.0-rc.0 (2023-11-16)

- Updated windows exporter to use prometheus-community/windows_exporter commit 1836cd1. (@mattdurham)

- Allow agent to start with `module.git` config if cached before. (@hainenber)

### Bugfixes

- Set exit code 1 on grafana-agentctl non-runnable command. (@fgouteroux)
Expand Down Expand Up @@ -174,6 +177,12 @@ v0.38.0-rc.0 (2023-11-16)
- Added Kubernetes service resolver to static node's loadbalancing exporter
and to Flow's `otelcol.exporter.loadbalancing`. (@ptodev)

- Fix default configuration file `grafana-agent-flow.river` used in downstream
packages. (@bricewge)

- Fix converter output for prometheus.exporter.windows to not unnecessarily add
empty blocks. (@erikbaranowski)

### Other changes

- Bump `mysqld_exporter` version to v0.15.0. (@marctc)
Expand Down
11 changes: 11 additions & 0 deletions cmd/grafana-agent-service/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type config struct {
// not included.
Args []string

// Environment holds environment variables for the Grafana Agent service.
// Each item represents an environment variable in form "key=value".
// All environments variables from the current process with be merged into Environment
Environment []string

// WorkingDirectory points to the working directory to run the Grafana Agent
// binary from.
WorkingDirectory string
Expand All @@ -42,9 +47,15 @@ func loadConfig() (*config, error) {
return nil, fmt.Errorf("failed to retrieve key Arguments: %w", err)
}

env, _, err := agentKey.GetStringsValue("Environment")
if err != nil {
return nil, fmt.Errorf("failed to retrieve key Environment: %w", err)
}

return &config{
ServicePath: servicePath,
Args: args,
Environment: env,
WorkingDirectory: filepath.Dir(servicePath),
}, nil
}
7 changes: 4 additions & 3 deletions cmd/grafana-agent-service/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ func main() {
}

cfg := serviceManagerConfig{
Path: managerConfig.ServicePath,
Args: managerConfig.Args,
Dir: managerConfig.WorkingDirectory,
Path: managerConfig.ServicePath,
Args: managerConfig.Args,
Environment: managerConfig.Environment,
Dir: managerConfig.WorkingDirectory,

// Send logs directly to the event logger.
Stdout: logger,
Expand Down
5 changes: 5 additions & 0 deletions cmd/grafana-agent-service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type serviceManagerConfig struct {
// Args of the binary to run, not including the command itself.
Args []string

// Environment of the binary to run, including the command environment itself.
Environment []string

// Dir specifies the working directory to run the binary from. If Dir is
// empty, the working directory of the current process is used.
Dir string
Expand Down Expand Up @@ -84,5 +87,7 @@ func (svc *serviceManager) buildCommand(ctx context.Context) *exec.Cmd {
cmd.Dir = svc.cfg.Dir
cmd.Stdout = svc.cfg.Stdout
cmd.Stderr = svc.cfg.Stderr
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, svc.cfg.Environment...)
return cmd
}
11 changes: 9 additions & 2 deletions cmd/grafana-agent-service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func Test_serviceManager(t *testing.T) {
listenHost := getListenHost(t)

mgr := newServiceManager(l, serviceManagerConfig{
Path: serviceBinary,
Args: []string{"-listen-addr", listenHost},
Path: serviceBinary,
Args: []string{"-listen-addr", listenHost},
Environment: []string{"LISTEN=" + listenHost},
})
go mgr.Run(componenttest.TestContext(t))

Expand All @@ -40,6 +41,12 @@ func Test_serviceManager(t *testing.T) {
require.NoError(t, err)
require.Equal(t, []byte("Hello, world!"), resp)
})

util.Eventually(t, func(t require.TestingT) {
resp, err := makeServiceRequest(listenHost, "/echo/env", nil)
require.NoError(t, err)
require.Contains(t, string(resp), "LISTEN="+listenHost)
})
})

t.Run("terminates service binary", func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions cmd/grafana-agent-service/testdata/example_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/http"
"os"
"strings"
)

func main() {
Expand Down Expand Up @@ -46,6 +47,9 @@ func run() error {
mux.HandleFunc("/echo/response", func(w http.ResponseWriter, r *http.Request) {
_, _ = io.Copy(w, r.Body)
})
mux.HandleFunc("/echo/env", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(strings.Join(os.Environ(), "\n")))
})

srv := &http.Server{Handler: mux}
_ = srv.Serve(lis)
Expand Down
2 changes: 1 addition & 1 deletion component/faro/receiver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (h *handler) Update(args ServerArguments) {
if len(args.CORSAllowedOrigins) > 0 {
h.cors = cors.New(cors.Options{
AllowedOrigins: args.CORSAllowedOrigins,
AllowedHeaders: []string{apiKeyHeader, "content-type"},
AllowedHeaders: []string{apiKeyHeader, "content-type", "x-faro-session-id"},
})
} else {
h.cors = nil // Disable cors.
Expand Down
71 changes: 0 additions & 71 deletions component/prometheus/exporter/windows/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,6 @@ import (
windows_integration "github.com/grafana/agent/pkg/integrations/windows_exporter"
)

// DefaultArguments holds non-zero default options for Arguments when it is
// unmarshaled from YAML.
//
// Some defaults are populated from init functions in the github.com/grafana/agent/pkg/integrations/windows_exporter package.

var DefaultArguments = Arguments{
EnabledCollectors: strings.Split(windows_integration.DefaultConfig.EnabledCollectors, ","),
Dfsr: DfsrConfig{
SourcesEnabled: strings.Split(windows_integration.DefaultConfig.Dfsr.SourcesEnabled, ","),
},
Exchange: ExchangeConfig{
EnabledList: strings.Split(windows_integration.DefaultConfig.Exchange.EnabledList, ","),
},
IIS: IISConfig{
AppBlackList: windows_integration.DefaultConfig.IIS.AppBlackList,
AppWhiteList: windows_integration.DefaultConfig.IIS.AppWhiteList,
SiteBlackList: windows_integration.DefaultConfig.IIS.SiteBlackList,
SiteWhiteList: windows_integration.DefaultConfig.IIS.SiteWhiteList,
AppInclude: windows_integration.DefaultConfig.IIS.AppInclude,
AppExclude: windows_integration.DefaultConfig.IIS.AppExclude,
SiteInclude: windows_integration.DefaultConfig.IIS.SiteInclude,
SiteExclude: windows_integration.DefaultConfig.IIS.SiteExclude,
},
LogicalDisk: LogicalDiskConfig{
BlackList: windows_integration.DefaultConfig.LogicalDisk.BlackList,
WhiteList: windows_integration.DefaultConfig.LogicalDisk.WhiteList,
Include: windows_integration.DefaultConfig.LogicalDisk.Include,
Exclude: windows_integration.DefaultConfig.LogicalDisk.Exclude,
},
MSMQ: MSMQConfig{
Where: windows_integration.DefaultConfig.MSMQ.Where,
},
MSSQL: MSSQLConfig{
EnabledClasses: strings.Split(windows_integration.DefaultConfig.MSSQL.EnabledClasses, ","),
},
Network: NetworkConfig{
BlackList: windows_integration.DefaultConfig.Network.BlackList,
WhiteList: windows_integration.DefaultConfig.Network.WhiteList,
Include: windows_integration.DefaultConfig.Network.Include,
Exclude: windows_integration.DefaultConfig.Network.Exclude,
},
Process: ProcessConfig{
BlackList: windows_integration.DefaultConfig.Process.BlackList,
WhiteList: windows_integration.DefaultConfig.Process.WhiteList,
Include: windows_integration.DefaultConfig.Process.Include,
Exclude: windows_integration.DefaultConfig.Process.Exclude,
},
ScheduledTask: ScheduledTaskConfig{
Include: windows_integration.DefaultConfig.ScheduledTask.Include,
Exclude: windows_integration.DefaultConfig.ScheduledTask.Exclude,
},
Service: ServiceConfig{
UseApi: windows_integration.DefaultConfig.Service.UseApi,
Where: windows_integration.DefaultConfig.Service.Where,
},
SMTP: SMTPConfig{
BlackList: windows_integration.DefaultConfig.SMTP.BlackList,
WhiteList: windows_integration.DefaultConfig.SMTP.WhiteList,
Include: windows_integration.DefaultConfig.SMTP.Include,
Exclude: windows_integration.DefaultConfig.SMTP.Exclude,
},
TextFile: TextFileConfig{
TextFileDirectory: windows_integration.DefaultConfig.TextFile.TextFileDirectory,
},
}

// Arguments is used for controlling for this exporter.
type Arguments struct {
// Collectors to mark as enabled
Expand All @@ -92,11 +26,6 @@ type Arguments struct {
TextFile TextFileConfig `river:"text_file,block,optional"`
}

// SetToDefault implements river.Defaulter.
func (a *Arguments) SetToDefault() {
*a = DefaultArguments
}

// Convert converts the component's Arguments to the integration's Config.
func (a *Arguments) Convert() *windows_integration.Config {
return &windows_integration.Config{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package windows

import (
"strings"
"testing"

windows_integration "github.com/grafana/agent/pkg/integrations/windows_exporter"
"github.com/grafana/river"
"github.com/stretchr/testify/require"
)
Expand All @@ -14,26 +12,26 @@ func TestRiverUnmarshalWithDefaultConfig(t *testing.T) {
err := river.Unmarshal([]byte(""), &args)
require.NoError(t, err)

require.Equal(t, strings.Split(windows_integration.DefaultConfig.EnabledCollectors, ","), args.EnabledCollectors)
require.Equal(t, strings.Split(windows_integration.DefaultConfig.Dfsr.SourcesEnabled, ","), args.Dfsr.SourcesEnabled)
require.Equal(t, strings.Split(windows_integration.DefaultConfig.Exchange.EnabledList, ","), args.Exchange.EnabledList)
require.Equal(t, windows_integration.DefaultConfig.IIS.AppExclude, args.IIS.AppExclude)
require.Equal(t, windows_integration.DefaultConfig.IIS.AppInclude, args.IIS.AppInclude)
require.Equal(t, windows_integration.DefaultConfig.IIS.SiteExclude, args.IIS.SiteExclude)
require.Equal(t, windows_integration.DefaultConfig.IIS.SiteInclude, args.IIS.SiteInclude)
require.Equal(t, windows_integration.DefaultConfig.LogicalDisk.Exclude, args.LogicalDisk.Exclude)
require.Equal(t, windows_integration.DefaultConfig.LogicalDisk.Include, args.LogicalDisk.Include)
require.Equal(t, windows_integration.DefaultConfig.MSMQ.Where, args.MSMQ.Where)
require.Equal(t, strings.Split(windows_integration.DefaultConfig.MSSQL.EnabledClasses, ","), args.MSSQL.EnabledClasses)
require.Equal(t, windows_integration.DefaultConfig.Network.Exclude, args.Network.Exclude)
require.Equal(t, windows_integration.DefaultConfig.Network.Include, args.Network.Include)
require.Equal(t, windows_integration.DefaultConfig.Process.Exclude, args.Process.Exclude)
require.Equal(t, windows_integration.DefaultConfig.Process.Include, args.Process.Include)
require.Equal(t, windows_integration.DefaultConfig.ScheduledTask.Exclude, args.ScheduledTask.Exclude)
require.Equal(t, windows_integration.DefaultConfig.ScheduledTask.Include, args.ScheduledTask.Include)
require.Equal(t, windows_integration.DefaultConfig.Service.UseApi, args.Service.UseApi)
require.Equal(t, windows_integration.DefaultConfig.Service.Where, args.Service.Where)
require.Equal(t, windows_integration.DefaultConfig.SMTP.Exclude, args.SMTP.Exclude)
require.Equal(t, windows_integration.DefaultConfig.SMTP.Include, args.SMTP.Include)
require.Equal(t, windows_integration.DefaultConfig.TextFile.TextFileDirectory, args.TextFile.TextFileDirectory)
require.Equal(t, DefaultArguments.EnabledCollectors, args.EnabledCollectors)
require.Equal(t, DefaultArguments.Dfsr.SourcesEnabled, args.Dfsr.SourcesEnabled)
require.Equal(t, DefaultArguments.Exchange.EnabledList, args.Exchange.EnabledList)
require.Equal(t, DefaultArguments.IIS.AppExclude, args.IIS.AppExclude)
require.Equal(t, DefaultArguments.IIS.AppInclude, args.IIS.AppInclude)
require.Equal(t, DefaultArguments.IIS.SiteExclude, args.IIS.SiteExclude)
require.Equal(t, DefaultArguments.IIS.SiteInclude, args.IIS.SiteInclude)
require.Equal(t, DefaultArguments.LogicalDisk.Exclude, args.LogicalDisk.Exclude)
require.Equal(t, DefaultArguments.LogicalDisk.Include, args.LogicalDisk.Include)
require.Equal(t, DefaultArguments.MSMQ.Where, args.MSMQ.Where)
require.Equal(t, DefaultArguments.MSSQL.EnabledClasses, args.MSSQL.EnabledClasses)
require.Equal(t, DefaultArguments.Network.Exclude, args.Network.Exclude)
require.Equal(t, DefaultArguments.Network.Include, args.Network.Include)
require.Equal(t, DefaultArguments.Process.Exclude, args.Process.Exclude)
require.Equal(t, DefaultArguments.Process.Include, args.Process.Include)
require.Equal(t, DefaultArguments.ScheduledTask.Exclude, args.ScheduledTask.Exclude)
require.Equal(t, DefaultArguments.ScheduledTask.Include, args.ScheduledTask.Include)
require.Equal(t, DefaultArguments.Service.UseApi, args.Service.UseApi)
require.Equal(t, DefaultArguments.Service.Where, args.Service.Where)
require.Equal(t, DefaultArguments.SMTP.Exclude, args.SMTP.Exclude)
require.Equal(t, DefaultArguments.SMTP.Include, args.SMTP.Include)
require.Equal(t, DefaultArguments.TextFile.TextFileDirectory, args.TextFile.TextFileDirectory)
}
75 changes: 75 additions & 0 deletions component/prometheus/exporter/windows/config_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package windows

import (
windows_integration "github.com/grafana/agent/pkg/integrations/windows_exporter"
col "github.com/prometheus-community/windows_exporter/pkg/collector"
"strings"
)

// DefaultArguments holds non-zero default options for Arguments when it is
// unmarshaled from YAML.
var DefaultArguments = Arguments{
EnabledCollectors: strings.Split(windows_integration.DefaultConfig.EnabledCollectors, ","),
Dfsr: DfsrConfig{
SourcesEnabled: strings.Split(col.ConfigDefaults.Dfsr.DfsrEnabledCollectors, ","),
},
Exchange: ExchangeConfig{
EnabledList: strings.Split(col.ConfigDefaults.Exchange.CollectorsEnabled, ","),
},
IIS: IISConfig{
AppBlackList: col.ConfigDefaults.Iis.AppExclude,
AppWhiteList: col.ConfigDefaults.Iis.AppInclude,
SiteBlackList: col.ConfigDefaults.Iis.SiteExclude,
SiteWhiteList: col.ConfigDefaults.Iis.SiteInclude,
AppInclude: col.ConfigDefaults.Iis.AppInclude,
AppExclude: col.ConfigDefaults.Iis.AppExclude,
SiteInclude: col.ConfigDefaults.Iis.SiteInclude,
SiteExclude: col.ConfigDefaults.Iis.SiteExclude,
},
LogicalDisk: LogicalDiskConfig{
BlackList: col.ConfigDefaults.LogicalDisk.VolumeExclude,
WhiteList: col.ConfigDefaults.LogicalDisk.VolumeInclude,
Include: col.ConfigDefaults.LogicalDisk.VolumeInclude,
Exclude: col.ConfigDefaults.LogicalDisk.VolumeExclude,
},
MSMQ: MSMQConfig{
Where: col.ConfigDefaults.Msmq.QueryWhereClause,
},
MSSQL: MSSQLConfig{
EnabledClasses: strings.Split(col.ConfigDefaults.Mssql.EnabledCollectors, ","),
},
Network: NetworkConfig{
BlackList: col.ConfigDefaults.Net.NicExclude,
WhiteList: col.ConfigDefaults.Net.NicInclude,
Include: col.ConfigDefaults.Net.NicInclude,
Exclude: col.ConfigDefaults.Net.NicExclude,
},
Process: ProcessConfig{
BlackList: col.ConfigDefaults.Process.ProcessExclude,
WhiteList: col.ConfigDefaults.Process.ProcessInclude,
Include: col.ConfigDefaults.Process.ProcessInclude,
Exclude: col.ConfigDefaults.Process.ProcessExclude,
},
ScheduledTask: ScheduledTaskConfig{
Include: col.ConfigDefaults.ScheduledTask.TaskInclude,
Exclude: col.ConfigDefaults.ScheduledTask.TaskExclude,
},
Service: ServiceConfig{
UseApi: "false",
Where: col.ConfigDefaults.Service.ServiceWhereClause,
},
SMTP: SMTPConfig{
BlackList: col.ConfigDefaults.Smtp.ServerExclude,
WhiteList: col.ConfigDefaults.Smtp.ServerInclude,
Include: col.ConfigDefaults.Smtp.ServerInclude,
Exclude: col.ConfigDefaults.Smtp.ServerExclude,
},
TextFile: TextFileConfig{
TextFileDirectory: col.ConfigDefaults.Textfile.TextFileDirectories,
},
}

// SetToDefault implements river.Defaulter.
func (a *Arguments) SetToDefault() {
*a = DefaultArguments
}
Loading

0 comments on commit a1033f7

Please sign in to comment.