From 55a2c856172798159ace7985adebc3306262f00f Mon Sep 17 00:00:00 2001 From: Robert Fratto Date: Mon, 20 Nov 2023 16:04:39 -0500 Subject: [PATCH] [release-v0.38] prepare for release v0.38.0-rc.1 (#5822) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * packaging: fix grafana-agent-flow.river (#5802) (#5809) * packaging: fix grafana-agent-flow.river (#5802) Add needed label in default `grafana-agent-flow.river` default configuration used in downstream packages. * Update CHANGELOG.md (cherry picked from commit eac661ff0b2f85c1baeb0e2d2bf52a7770a1fd0c) * misc: fix changelog entry (#5812) PR #5802 accidentally added the changelog entry to a published release. (cherry picked from commit bc3babc3b6c9f31792f5997c5e4c9ddb271c223b) * feat(module/git): allow module.git use cached content when failed to fetch (#5712) Signed-off-by: hainenber (cherry picked from commit 39b78a8cf967679018fe8e1da6e684155da4d684) * Fix converter output for prometheus.exporter.windows to not unnecessarily add empty blocks (#5817) (cherry picked from commit 165914bc6c83b2b097375071ccef5fd2f5286833) * delete obsolete broken windows test (#5818) (cherry picked from commit bcbc7abfa5da407fedc01e30be5037d0504386f0) * prepare for release v0.38.0-rc.1 (#5821) (cherry picked from commit 7d775c1fb9ef35a6556c6ffa3f9e876b73aabd45) --------- Co-authored-by: Brice Waegeneire Co-authored-by: Đỗ Trọng Hải <41283691+hainenber@users.noreply.github.com> Co-authored-by: Erik Baranowski <39704712+erikbaranowski@users.noreply.github.com> --- CHANGELOG.md | 13 ++++ component/module/git/git.go | 18 ++++- component/module/git/internal/vcs/git.go | 28 +++++--- .../internal/build/windows_exporter.go | 10 +-- .../testdata-v2_windows/integrations_v2.river | 8 +-- .../testdata_windows/integrations.river | 8 +-- docs/sources/_index.md | 2 +- .../grafana-agent-flow.river | 4 +- .../windows_exporter/config_windows_test.go | 70 ------------------- pkg/operator/defaults.go | 2 +- tools/gen-versioned-files/agent-version.txt | 2 +- 11 files changed, 60 insertions(+), 105 deletions(-) delete mode 100644 pkg/integrations/windows_exporter/config_windows_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c4b5dc5b418..2da23f2e9b75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,19 @@ internal API changes are not present. Main (unreleased) ----------------- +v0.38.0-rc.1 (2023-11-20) +------------------------- + +### Enhancements + +- Allow agent to start with `module.git` config if cached before. (@hainenber) + +### Bugfixes + +- 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) + v0.38.0-rc.0 (2023-11-16) ------------------------- diff --git a/component/module/git/git.go b/component/module/git/git.go index 42ac468477de..6a211fdc8843 100644 --- a/component/module/git/git.go +++ b/component/module/git/git.go @@ -3,6 +3,7 @@ package git import ( "context" + "errors" "path/filepath" "reflect" "sync" @@ -91,8 +92,15 @@ func New(o component.Options, args Arguments) (*Component, error) { argsChanged: make(chan struct{}, 1), } + // Only acknowledge the error from Update if it's not a + // vcs.UpdateFailedError; vcs.UpdateFailedError means that the Git repo + // exists but we were just unable to update it. if err := c.Update(args); err != nil { - return nil, err + if errors.As(err, &vcs.UpdateFailedError{}) { + level.Error(c.log).Log("msg", "failed to update repository", "err", err) + } else { + return nil, err + } } return c, nil } @@ -193,10 +201,16 @@ func (c *Component) Update(args component.Arguments) (err error) { } // Create or update the repo field. + // Failure to update repository makes the module loader temporarily use cached contents on disk if c.repo == nil || !reflect.DeepEqual(repoOpts, c.repoOpts) { r, err := vcs.NewGitRepo(context.Background(), repoPath, repoOpts) if err != nil { - return err + if errors.As(err, &vcs.UpdateFailedError{}) { + level.Error(c.log).Log("msg", "failed to update repository", "err", err) + c.updateHealth(err) + } else { + return err + } } c.repo = r c.repoOpts = repoOpts diff --git a/component/module/git/internal/vcs/git.go b/component/module/git/internal/vcs/git.go index 8209190b90da..dece43c10b2f 100644 --- a/component/module/git/internal/vcs/git.go +++ b/component/module/git/internal/vcs/git.go @@ -58,16 +58,24 @@ func NewGitRepo(ctx context.Context, storagePath string, opts GitRepoOptions) (* } // Fetch the latest contents. This may be a no-op if we just did a clone. - err = repo.FetchContext(ctx, &git.FetchOptions{ + fetchRepoErr := repo.FetchContext(ctx, &git.FetchOptions{ RemoteName: "origin", Force: true, Auth: opts.Auth.Convert(), }) - if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { - return nil, UpdateFailedError{ - Repository: opts.Repository, - Inner: err, + if fetchRepoErr != nil && !errors.Is(fetchRepoErr, git.NoErrAlreadyUpToDate) { + workTree, err := repo.Worktree() + if err != nil { + return nil, err } + return &GitRepo{ + opts: opts, + repo: repo, + workTree: workTree, + }, UpdateFailedError{ + Repository: opts.Repository, + Inner: fetchRepoErr, + } } // Finally, hard reset to our requested revision. @@ -92,7 +100,7 @@ func NewGitRepo(ctx context.Context, storagePath string, opts GitRepoOptions) (* opts: opts, repo: repo, workTree: workTree, - }, nil + }, err } func isRepoCloned(dir string) bool { @@ -103,15 +111,16 @@ func isRepoCloned(dir string) bool { // Update updates the repository by fetching new content and re-checking out to // latest version of Revision. func (repo *GitRepo) Update(ctx context.Context) error { - err := repo.repo.FetchContext(ctx, &git.FetchOptions{ + var err error + fetchRepoErr := repo.repo.FetchContext(ctx, &git.FetchOptions{ RemoteName: "origin", Force: true, Auth: repo.opts.Auth.Convert(), }) - if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { + if fetchRepoErr != nil && !errors.Is(fetchRepoErr, git.NoErrAlreadyUpToDate) { return UpdateFailedError{ Repository: repo.opts.Repository, - Inner: err, + Inner: fetchRepoErr, } } @@ -120,7 +129,6 @@ func (repo *GitRepo) Update(ctx context.Context) error { if err != nil { return InvalidRevisionError{Revision: repo.opts.Revision} } - err = repo.workTree.Reset(&git.ResetOptions{ Commit: hash, Mode: git.HardReset, diff --git a/converter/internal/staticconvert/internal/build/windows_exporter.go b/converter/internal/staticconvert/internal/build/windows_exporter.go index 100a8761ccfc..27e9679887b8 100644 --- a/converter/internal/staticconvert/internal/build/windows_exporter.go +++ b/converter/internal/staticconvert/internal/build/windows_exporter.go @@ -1,6 +1,8 @@ package build import ( + "strings" + "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/windows" "github.com/grafana/agent/pkg/integrations/windows_exporter" @@ -13,12 +15,12 @@ func (b *IntegrationsConfigBuilder) appendWindowsExporter(config *windows_export func toWindowsExporter(config *windows_exporter.Config) *windows.Arguments { return &windows.Arguments{ - EnabledCollectors: splitByCommaNullOnEmpty(config.EnabledCollectors), + EnabledCollectors: strings.Split(config.EnabledCollectors, ","), Dfsr: windows.DfsrConfig{ - SourcesEnabled: splitByCommaNullOnEmpty(config.Dfsr.SourcesEnabled), + SourcesEnabled: strings.Split(config.Dfsr.SourcesEnabled, ","), }, Exchange: windows.ExchangeConfig{ - EnabledList: splitByCommaNullOnEmpty(config.Exchange.EnabledList), + EnabledList: strings.Split(config.Exchange.EnabledList, ","), }, IIS: windows.IISConfig{ AppBlackList: config.IIS.AppBlackList, @@ -40,7 +42,7 @@ func toWindowsExporter(config *windows_exporter.Config) *windows.Arguments { Where: config.MSMQ.Where, }, MSSQL: windows.MSSQLConfig{ - EnabledClasses: splitByCommaNullOnEmpty(config.MSSQL.EnabledClasses), + EnabledClasses: strings.Split(config.MSSQL.EnabledClasses, ","), }, Network: windows.NetworkConfig{ BlackList: config.Network.BlackList, diff --git a/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.river b/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.river index e01818b3faad..903d7f0c9a9c 100644 --- a/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.river +++ b/converter/internal/staticconvert/testdata-v2_windows/integrations_v2.river @@ -9,13 +9,7 @@ prometheus.remote_write "metrics_default" { } } -prometheus.exporter.windows "integrations_windows_exporter" { - exchange { } - - network { - exclude = ".+" - } -} +prometheus.exporter.windows "integrations_windows_exporter" { } prometheus.scrape "integrations_windows" { targets = prometheus.exporter.windows.integrations_windows_exporter.targets diff --git a/converter/internal/staticconvert/testdata_windows/integrations.river b/converter/internal/staticconvert/testdata_windows/integrations.river index d550abac368e..14c12b899530 100644 --- a/converter/internal/staticconvert/testdata_windows/integrations.river +++ b/converter/internal/staticconvert/testdata_windows/integrations.river @@ -22,13 +22,7 @@ http { } } -prometheus.exporter.windows "integrations_windows_exporter" { - exchange { } - - network { - exclude = ".+" - } -} +prometheus.exporter.windows "integrations_windows_exporter" { } prometheus.scrape "integrations_windows_exporter" { targets = prometheus.exporter.windows.integrations_windows_exporter.targets diff --git a/docs/sources/_index.md b/docs/sources/_index.md index ecbe02c29237..15df6d9c3174 100644 --- a/docs/sources/_index.md +++ b/docs/sources/_index.md @@ -9,7 +9,7 @@ title: Grafana Agent description: Grafana Agent is a flexible, performant, vendor-neutral, telemetry collector weight: 350 cascade: - AGENT_RELEASE: v0.38.0-rc.0 + AGENT_RELEASE: v0.38.0-rc.1 OTEL_VERSION: v0.87.0 --- diff --git a/packaging/grafana-agent-flow/grafana-agent-flow.river b/packaging/grafana-agent-flow/grafana-agent-flow.river index b965ff0599e1..4d74fc7aa9cb 100644 --- a/packaging/grafana-agent-flow/grafana-agent-flow.river +++ b/packaging/grafana-agent-flow/grafana-agent-flow.river @@ -5,14 +5,14 @@ logging { level = "warn" } -prometheus.exporter.unix { +prometheus.exporter.unix "default" { include_exporter_metrics = true disable_collectors = ["mdadm"] } prometheus.scrape "default" { targets = concat( - prometheus.exporter.unix.targets, + prometheus.exporter.unix.default.targets, [{ // Self-collect metrics job = "agent", diff --git a/pkg/integrations/windows_exporter/config_windows_test.go b/pkg/integrations/windows_exporter/config_windows_test.go deleted file mode 100644 index 5546426c9e0f..000000000000 --- a/pkg/integrations/windows_exporter/config_windows_test.go +++ /dev/null @@ -1,70 +0,0 @@ -//go:build windows - -package windows_exporter - -import ( - "testing" - - "github.com/alecthomas/kingpin/v2" - "github.com/prometheus-community/windows_exporter/pkg/collector" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" -) - -func TestConfig(t *testing.T) { - built, total := testConfig(t, "") - // Default which is windows_exporter defaults minus textfile - require.Len(t, built, 7) - // Total should be 50 - require.Len(t, total, 50) -} - -func TestMultipleConfig(t *testing.T) { - cfg1 := ` -enabled_collectors: "mssql,os" -mssql: - enabled_classes: "accessmethods,availreplica" -` - cfg2 := ` -enabled_collectors: "mssql,os,cpu" -mssql: - enabled_classes: "accessmethods,availreplica,bufman" -` - cfg3 := ` -enabled_collectors: "mssql,os" -mssql: {} -` - built1, total1 := testConfig(t, cfg1) - built2, total2 := testConfig(t, cfg2) - built3, total3 := testConfig(t, cfg3) - require.Len(t, built1, 2) - require.Len(t, built2, 3) - require.Len(t, built3, 2) - total1mssql := "accessmethods,availreplica" - require.True(t, *total1["mssql"].Settings.(*collector.MSSqlSettings).ClassesEnabled == total1mssql) - total2mssql := "accessmethods,availreplica,bufman" - require.True(t, *total2["mssql"].Settings.(*collector.MSSqlSettings).ClassesEnabled == total2mssql) - total3mssql := "accessmethods,availreplica,bufman,databases,dbreplica,genstats,locks,memmgr,sqlstats,sqlerrors,transactions,waitstats" - require.True(t, *total3["mssql"].Settings.(*collector.MSSqlSettings).ClassesEnabled == total3mssql) -} - -func testConfig(t *testing.T, cfg string) (map[string]collector.Collector, map[string]*collector.Initializer) { - c := DefaultConfig - err := yaml.Unmarshal([]byte(cfg), &c) - require.NoError(t, err) - collectors := collector.CreateInitializers() - windowsExporter := kingpin.New("", "") - // We only need this to fill in the appropriate settings structs so we can override them. - collector.RegisterCollectorsFlags(collectors, windowsExporter) - // Override the settings structs with our own - err = c.toExporterConfig(collectors) - require.NoError(t, err) - // Register the performance monitors - collector.RegisterCollectors(collectors) - // Filter down to the enabled collectors - enabledCollectorNames := enabledCollectors(c.EnabledCollectors) - // Finally build the collectors that we need to run. - builtCollectors, err := buildCollectors(collectors, enabledCollectorNames) - require.NoError(t, err) - return builtCollectors, collectors -} diff --git a/pkg/operator/defaults.go b/pkg/operator/defaults.go index d1da8136fa40..27d19feb218d 100644 --- a/pkg/operator/defaults.go +++ b/pkg/operator/defaults.go @@ -2,7 +2,7 @@ package operator // Supported versions of the Grafana Agent. var ( - DefaultAgentVersion = "v0.38.0-rc.0" + DefaultAgentVersion = "v0.38.0-rc.1" DefaultAgentBaseImage = "grafana/agent" DefaultAgentImage = DefaultAgentBaseImage + ":" + DefaultAgentVersion ) diff --git a/tools/gen-versioned-files/agent-version.txt b/tools/gen-versioned-files/agent-version.txt index 0419d9c65489..840190248a93 100644 --- a/tools/gen-versioned-files/agent-version.txt +++ b/tools/gen-versioned-files/agent-version.txt @@ -1 +1 @@ -v0.38.0-rc.0 +v0.38.0-rc.1