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

Build docker and kubernetes features only on supported platforms #13509

Merged
Merged
2 changes: 2 additions & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The list below covers the major changes between 7.0.0-rc2 and master only.

- Move Fields from package libbeat/common to libbeat/mapping. {pull}11198[11198]
- For "metricbeat style" generated custom beats, the mage target `GoTestIntegration` has changed to `GoIntegTest` and `GoTestUnit` has changed to `GoUnitTest`. {pull}13341[13341]
- Build docker and kubernetes features only on supported platforms. {pull}13509[13509]
- Need to register new processors to be used in the JS processor in their `init` functions. {pull}13509[13509]

==== Bugfixes

Expand Down
38 changes: 38 additions & 0 deletions filebeat/tests/system/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from filebeat import BaseTest
import io
import os
import unittest
import sys

"""
Contains tests for filtering.
Expand Down Expand Up @@ -300,6 +302,42 @@ def test_decode_csv_fields_all_options(self):
["42", "hello world", "string\twith tabs and \"broken\" quotes"],
])

def test_javascript_processor_add_host_metadata(self):
"""
Check JS processor with add_host_metadata
"""

self._test_javascript_processor_with_source("""\'var processor = require("processor");
var addHostMetadata = new processor.AddHostMetadata({"netinfo.enabled": true});

function process(evt) {
addHostMetadata.Run(evt);
}\'
""")

output = self.read_output()
for evt in output:
assert "host.hostname" in evt

def _test_javascript_processor_with_source(self, script_source):
self.render_config_template(
path=os.path.abspath(self.working_dir) + "/test.log",
processors=[
{
"script": {
"lang": "javascript",
"source": script_source,
},
},
]
)

self._init_and_read_test_input([
u"test line 1\n",
u"test line 2\n",
u"test line 3\n",
])

def _init_and_read_test_input(self, input_lines):
with io.open(self.working_dir + "/test.log", "w", encoding="utf-8") as f:
for line in input_lines:
Expand Down
6 changes: 5 additions & 1 deletion heartbeat/scripts/generate_imports_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ def imports(mode):
package = "monitors/{}".format(mode)
return [format(package, m) for m in collect_monitors(package)]

return sorted(imports("active") + imports("passive"))
return [{
"file_suffix": "",
"build_tags": "",
"imported_lines": sorted(imports("active") + imports("passive"))
}]


def collect_monitors(package):
Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package docker

import (
Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package docker

import (
Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package kubernetes

import (
Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package kubernetes

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ package instance

import (
_ "github.com/elastic/beats/libbeat/autodiscover/appenders/config" // Register autodiscover appenders
_ "github.com/elastic/beats/libbeat/autodiscover/providers/docker" // Register autodiscover providers
_ "github.com/elastic/beats/libbeat/autodiscover/providers/jolokia"
_ "github.com/elastic/beats/libbeat/autodiscover/providers/kubernetes"
_ "github.com/elastic/beats/libbeat/monitoring/report/elasticsearch" // Register default monitoring reporting
_ "github.com/elastic/beats/libbeat/processors/actions" // Register default processors.
_ "github.com/elastic/beats/libbeat/processors/add_cloud_metadata"
_ "github.com/elastic/beats/libbeat/processors/add_docker_metadata"
_ "github.com/elastic/beats/libbeat/processors/add_host_metadata"
_ "github.com/elastic/beats/libbeat/processors/add_kubernetes_metadata"
_ "github.com/elastic/beats/libbeat/processors/add_locale"
_ "github.com/elastic/beats/libbeat/processors/add_observer_metadata"
_ "github.com/elastic/beats/libbeat/processors/add_process_metadata"
Expand Down
27 changes: 27 additions & 0 deletions libbeat/cmd/instance/imports_docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package instance

import (
_ "github.com/elastic/beats/libbeat/autodiscover/providers/docker" // Register autodiscover providers
_ "github.com/elastic/beats/libbeat/autodiscover/providers/kubernetes"
_ "github.com/elastic/beats/libbeat/processors/add_docker_metadata"
_ "github.com/elastic/beats/libbeat/processors/add_kubernetes_metadata"
)
2 changes: 2 additions & 0 deletions libbeat/common/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package docker

import (
Expand Down
1 change: 1 addition & 0 deletions libbeat/common/docker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

// +build integration
// +build linux darwin windows

package docker

Expand Down
2 changes: 2 additions & 0 deletions libbeat/common/docker/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package docker

import (
Expand Down
2 changes: 2 additions & 0 deletions libbeat/common/docker/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package docker

import (
Expand Down
3 changes: 3 additions & 0 deletions libbeat/processors/actions/add_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/processors"
"github.com/elastic/beats/libbeat/processors/checks"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

type addFields struct {
Expand All @@ -40,6 +41,8 @@ func init() {
checks.ConfigChecked(CreateAddFields,
checks.RequireFields(FieldsKey),
checks.AllowedFields(FieldsKey, "target", "when")))

jsprocessor.RegisterPlugin("AddFields", CreateAddFields)
}

// CreateAddFields constructs an add_fields processor from config.
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/actions/copy_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
"github.com/elastic/beats/libbeat/processors/checks"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

type copyFields struct {
Expand All @@ -45,6 +46,7 @@ func init() {
checks.RequireFields("fields"),
),
)
jsprocessor.RegisterPlugin("CopyFields", NewCopyFields)
}

// NewCopyFields returns a new copy_fields processor.
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/actions/decode_base64_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
"github.com/elastic/beats/libbeat/processors/checks"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

const (
Expand All @@ -50,6 +51,7 @@ func init() {
checks.ConfigChecked(NewDecodeBase64Field,
checks.RequireFields("field"),
checks.AllowedFields("field", "when", "ignore_missing", "fail_on_error")))
jsprocessor.RegisterPlugin("DecodeBase64Field", NewDecodeBase64Field)
}

// NewDecodeBase64Field construct a new decode_base64_field processor.
Expand Down
3 changes: 3 additions & 0 deletions libbeat/processors/actions/decode_json_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
"github.com/elastic/beats/libbeat/processors/checks"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

type decodeJSONFields struct {
Expand Down Expand Up @@ -66,6 +67,8 @@ func init() {
checks.ConfigChecked(NewDecodeJSONFields,
checks.RequireFields("fields"),
checks.AllowedFields("fields", "max_depth", "overwrite_keys", "add_error_key", "process_array", "target", "when")))

jsprocessor.RegisterPlugin("DecodeJSONFields", NewDecodeJSONFields)
}

// NewDecodeJSONFields construct a new decode_json_fields processor.
Expand Down
3 changes: 3 additions & 0 deletions libbeat/processors/actions/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
"github.com/elastic/beats/libbeat/processors/checks"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

type renameFields struct {
Expand All @@ -48,6 +49,8 @@ func init() {
processors.RegisterPlugin("rename",
checks.ConfigChecked(NewRenameFields,
checks.RequireFields("fields")))

jsprocessor.RegisterPlugin("Rename", NewRenameFields)
}

// NewRenameFields returns a new rename processor.
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/actions/truncate_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
"github.com/elastic/beats/libbeat/processors/checks"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

type truncateFieldsConfig struct {
Expand All @@ -54,6 +55,7 @@ func init() {
checks.MutuallyExclusiveRequiredFields("max_bytes", "max_characters"),
),
)
jsprocessor.RegisterPlugin("TruncateFields", NewTruncateFields)
}

// NewTruncateFields returns a new truncate_fields processor.
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/add_cloud_metadata/add_cloud_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

const (
Expand All @@ -53,6 +54,7 @@ var debugf = logp.MakeDebug("filters")
// init registers the add_cloud_metadata processor.
func init() {
processors.RegisterPlugin("add_cloud_metadata", New)
jsprocessor.RegisterPlugin("AddCloudMetadata", New)
}

type schemaConv func(m map[string]interface{}) common.MapStr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package add_docker_metadata

import (
Expand All @@ -35,6 +37,7 @@ import (
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
"github.com/elastic/beats/libbeat/processors/actions"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

const (
Expand All @@ -49,6 +52,7 @@ var processCgroupPaths = cgroup.ProcessCgroupPaths

func init() {
processors.RegisterPlugin(processorName, New)
jsprocessor.RegisterPlugin("AddDockerMetadata", New)
}

type addDockerMetadata struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package add_docker_metadata

import (
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/add_docker_metadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package add_docker_metadata

import (
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/add_host_metadata/add_host_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ import (
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/metric/system/host"
"github.com/elastic/beats/libbeat/processors"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
"github.com/elastic/beats/libbeat/processors/util"
"github.com/elastic/go-sysinfo"
)

func init() {
processors.RegisterPlugin("add_host_metadata", New)
jsprocessor.RegisterPlugin("AddHostMetadata", New)
}

type addHostMetadata struct {
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/add_kubernetes_metadata/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package add_kubernetes_metadata

import (
Expand Down
4 changes: 4 additions & 0 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

// +build linux darwin windows

package add_kubernetes_metadata

import (
Expand All @@ -26,6 +28,7 @@ import (
"github.com/elastic/beats/libbeat/common/kubernetes"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
jsprocessor "github.com/elastic/beats/libbeat/processors/script/javascript/module/processor"
)

const (
Expand All @@ -41,6 +44,7 @@ type kubernetesAnnotator struct {

func init() {
processors.RegisterPlugin("add_kubernetes_metadata", New)
jsprocessor.RegisterPlugin("AddKubernetesMetadata", New)

// Register default indexers
Indexing.AddIndexer(PodNameIndexerName, NewPodNameIndexer)
Expand Down
Loading