Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x](backport #41041) fix(filebeat): do not import kubernetes provider on unsupported platforms #41049

Open
wants to merge 1 commit into
base: 8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions filebeat/autodiscover/builder/hints/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/elastic/beats/v7/filebeat/fileset"
"github.com/elastic/beats/v7/filebeat/harvester"
"github.com/elastic/beats/v7/libbeat/autodiscover"
"github.com/elastic/beats/v7/libbeat/autodiscover/providers/kubernetes"
"github.com/elastic/beats/v7/libbeat/autodiscover/template"
"github.com/elastic/beats/v7/libbeat/beat"
conf "github.com/elastic/elastic-agent-libs/config"
Expand Down Expand Up @@ -126,38 +125,38 @@ func (l *logHints) CreateConfig(event bus.Event, options ...ucfg.Option) []*conf
// multiline options should be under multiline parser in filestream input
parsersTempCfg := []mapstr.M{}
mlineTempCfg := mapstr.M{}
kubernetes.ShouldPut(mlineTempCfg, multiline, mline, l.log)
shouldPut(mlineTempCfg, multiline, mline, l.log)
parsersTempCfg = append(parsersTempCfg, mlineTempCfg)
kubernetes.ShouldPut(tempCfg, parsers, parsersTempCfg, l.log)
shouldPut(tempCfg, parsers, parsersTempCfg, l.log)
} else {
kubernetes.ShouldPut(tempCfg, multiline, mline, l.log)
shouldPut(tempCfg, multiline, mline, l.log)
}
}
if ilines := l.getIncludeLines(h); len(ilines) != 0 {
kubernetes.ShouldPut(tempCfg, includeLines, ilines, l.log)
shouldPut(tempCfg, includeLines, ilines, l.log)
}
if elines := l.getExcludeLines(h); len(elines) != 0 {
kubernetes.ShouldPut(tempCfg, excludeLines, elines, l.log)
shouldPut(tempCfg, excludeLines, elines, l.log)
}

if procs := l.getProcessors(h); len(procs) != 0 {
kubernetes.ShouldPut(tempCfg, processors, procs, l.log)
shouldPut(tempCfg, processors, procs, l.log)
}

if pip := l.getPipeline(h); len(pip) != 0 {
kubernetes.ShouldPut(tempCfg, pipeline, pip, l.log)
shouldPut(tempCfg, pipeline, pip, l.log)
}

if jsonOpts := l.getJSONOptions(h); len(jsonOpts) != 0 {
if inputType == harvester.FilestreamType {
// json options should be under ndjson parser in filestream input
parsersTempCfg := []mapstr.M{}
ndjsonTempCfg := mapstr.M{}
kubernetes.ShouldPut(ndjsonTempCfg, ndjson, jsonOpts, l.log)
shouldPut(ndjsonTempCfg, ndjson, jsonOpts, l.log)
parsersTempCfg = append(parsersTempCfg, ndjsonTempCfg)
kubernetes.ShouldPut(tempCfg, parsers, parsersTempCfg, l.log)
shouldPut(tempCfg, parsers, parsersTempCfg, l.log)
} else {
kubernetes.ShouldPut(tempCfg, json, jsonOpts, l.log)
shouldPut(tempCfg, json, jsonOpts, l.log)
}

}
Expand Down Expand Up @@ -309,3 +308,10 @@ func (l *logHints) getInputs(hints mapstr.M) []mapstr.M {

return output
}

func shouldPut(event mapstr.M, field string, value interface{}, logger *logp.Logger) {
_, err := event.Put(field, value)
if err != nil {
logger.Debugf("Failed to put field '%s' with value '%s': %s", field, value, err)
}
}
2 changes: 1 addition & 1 deletion filebeat/autodiscover/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build !aix
//go:build linux || darwin || windows

package autodiscover

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// specific language governing permissions and limitations
// under the License.

//go:build aix
//go:build !(linux || darwin || windows)

package autodiscover

// InitializeModule initializes this module.
func InitializeModule() {
// does nothing on aix
// does nothing if kubernetes and docker are not supported
}
Loading