Skip to content

Commit

Permalink
Merge branch 'main' into fix-aws-terraform-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bhapas committed Jul 13, 2023
2 parents 5657bb3 + 5d974fd commit b0f7b9a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
14 changes: 1 addition & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def cloud(Map args = [:]) {
withCloudTestEnv(args) {
startCloudTestEnv(name: args.directory, dirs: args.dirs, withAWS: args.withAWS)
try {
targetWithoutNode(context: args.context, command: args.command, directory: args.directory, label: args.label, withModule: args.withModule, isMage: true, id: args.id, name: args.directory)
targetWithoutNode(context: args.context, command: args.command, directory: args.directory, label: args.label, withModule: args.withModule, isMage: true, id: args.id)
} finally {
terraformCleanup(name: args.directory, dir: args.directory, withAWS: args.withAWS)
}
Expand Down Expand Up @@ -590,25 +590,13 @@ def targetWithoutNode(Map args = [:]) {
def enableRetry = args.get('enableRetry', false)
def withGCP = args.get('withGCP', false)
def withNodejs = args.get('withNodejs', false)
// def dirs = args.get('dirs',[])
String name = normalise(args.name)
withGithubNotify(context: "${context}") {
withBeatsEnv(archive: true, withModule: withModule, directory: directory, id: args.id) {
dumpVariables()
withTools(k8s: installK8s, gcp: withGCP, nodejs: withNodejs) {
// make commands use -C <folder> while mage commands require the dir(folder)
// let's support this scenario with the location variable.
dir(isMage ? directory : '') {
// unstash in the same directory where the files were stashed
// dir('input/awss3/_meta/terraform'){
// echo "terraform-${name}"
// try {
// unstash(name: "terraform-${name}")
// sh "ls -la ${pwd()}"
// } catch (error) {
// echo "error unstashing: ${error}"
// }
// }
if (enableRetry) {
// Retry the same command to bypass any kind of flakiness.
// Downside: genuine failures will be repeated.
Expand Down
34 changes: 22 additions & 12 deletions metricbeat/internal/sysinit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package sysinit

import (
"flag"
"fmt"
"sync"

"github.com/elastic/beats/v7/libbeat/common/cfgwarn"
Expand All @@ -39,21 +40,24 @@ type HostFSConfig struct {
HostFS string `config:"hostfs"`
}

// MetricbeatHostFSConfig
// MetricbeatHostFSConfig carries config information for the hostfs setting
type MetricbeatHostFSConfig struct {
HostFS string `config:"system.hostfs"`
}

// Init either the system or linux module. This will produce different modules depending on if we're running under agent or not.
// InitSystemModule initializes either either the system or linux module. This will produce different modules depending on if we're running under agent or not.
func InitSystemModule(base mb.BaseModule) (mb.Module, error) {
// common code for the base use case of `hostfs` being set at the module-level
logger := logp.L()
hostfs, userSet := findConfigValue(base)
hostfs, userSet, err := findConfigValue(base)
if err != nil {
return nil, fmt.Errorf("error fetching config value: %w", err)
}
if fleetmode.Enabled() {
logger.Infof("initializing HostFS values under agent: %s", hostfs)
return fleetInit(base, hostfs, userSet)
}
return metricbeatInit(base, hostfs, userSet)
return metricbeatInit(base, hostfs)
}

func fleetInit(base mb.BaseModule, modulepath string, moduleSet bool) (mb.Module, error) {
Expand All @@ -71,12 +75,11 @@ func fleetInit(base mb.BaseModule, modulepath string, moduleSet bool) (mb.Module
}

// Deal with the legacy configs available to metricbeat
func metricbeatInit(base mb.BaseModule, modulePath string, moduleSet bool) (mb.Module, error) {
func metricbeatInit(base mb.BaseModule, modulePath string) (mb.Module, error) {
var hostfs = modulePath
var userSet bool
// allow the CLI to override other settings
if hostfsCLI != nil && *hostfsCLI != "" {
cfgwarn.Deprecate("8.0.0", "The --system.hostfs flag will be removed in the future and replaced by a config value.")
hostfs = *hostfsCLI
userSet = true
}
Expand All @@ -91,22 +94,29 @@ func metricbeatInit(base mb.BaseModule, modulePath string, moduleSet bool) (mb.M
// A user can supply either `system.hostfs` or `hostfs`.
// In additon, we will probably want to change Integration Config values to `hostfs` as well.
// We need to figure out which one we got, if any.
func findConfigValue(base mb.BaseModule) (string, bool) {
// Returns false if no config value was set
func findConfigValue(base mb.BaseModule) (string, bool, error) {
partialConfig := HostFSConfig{}
base.UnpackConfig(&partialConfig)
err := base.UnpackConfig(&partialConfig)
if err != nil {
return "", false, fmt.Errorf("error unpacking hostfs config: %w", err)
}
// if the newer value is set, just use that.
if partialConfig.HostFS != "" {
return partialConfig.HostFS, true
return partialConfig.HostFS, true, nil
}

legacyConfig := MetricbeatHostFSConfig{}
base.UnpackConfig(&legacyConfig)
err = base.UnpackConfig(&legacyConfig)
if err != nil {
return "", false, fmt.Errorf("error unpacking legacy config: %w", err)
}
if legacyConfig.HostFS != "" {
cfgwarn.Deprecate("8.0.0", "The system.hostfs config value will be removed, use `hostfs` from within the module config.")
// Only fallback to this if the user didn't set anything else
return legacyConfig.HostFS, true
return legacyConfig.HostFS, true, nil
}

return "/", false
return "/", false, nil

}

0 comments on commit b0f7b9a

Please sign in to comment.