Skip to content

Commit

Permalink
Adapt beat root cmd to processor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
simitt committed Mar 11, 2019
1 parent dd6d614 commit 93a21f5
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 52 deletions.
26 changes: 25 additions & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,37 @@ SOFTWARE.
--------------------------------------------------------------------
Dependency: github.com/elastic/beats
Version: 7.0
Revision: d7a5a79ff8ae5ca3289d150dd6c27bcf8b065831
Revision: 4756ec1fb3f316032ed12a744749b5eed2ddea6d
License type (autodetected): Apache-2.0
./vendor/github.com/elastic/beats/LICENSE.txt:
--------------------------------------------------------------------
Apache License 2.0


--------------------------------------------------------------------
Dependency: github.com/elastic/ecs
Revision: 337ddd4674d6a28da97e6d19010c04c43db09e58
License type (autodetected): Apache-2.0
./vendor/github.com/elastic/ecs/LICENSE.txt:
--------------------------------------------------------------------
Apache License 2.0

-------NOTICE.txt-----
Elastic Common Schema
Copyright 2018 Elasticsearch B.V.

Licensed 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.

--------------------------------------------------------------------
Dependency: github.com/elastic/go-lumber
Revision: 616041e345fc33c97bc0eb0fa6b388aa07bca3e1
Expand Down
35 changes: 15 additions & 20 deletions beater/beater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import (
"testing"
"time"

"github.com/gofrs/uuid"
"github.com/elastic/beats/libbeat/logp"

"github.com/elastic/beats/libbeat/publisher/processing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
Expand All @@ -39,7 +41,6 @@ import (
"github.com/elastic/beats/libbeat/publisher/pipeline"
"github.com/elastic/beats/libbeat/publisher/queue"
"github.com/elastic/beats/libbeat/publisher/queue/memqueue"
"github.com/elastic/beats/libbeat/version"
)

func TestBeatConfig(t *testing.T) {
Expand Down Expand Up @@ -293,12 +294,19 @@ func (d *DummyOutputClient) Publish(batch pubs.Batch) error {
func (d *DummyOutputClient) Close() error { return nil }
func (d *DummyOutputClient) String() string { return "" }

func DummyPipeline(clients ...outputs.Client) *pipeline.Pipeline {
func DummyPipeline(cfg *common.Config, info beat.Info, clients ...outputs.Client) *pipeline.Pipeline {
if len(clients) == 0 {
clients = []outputs.Client{&DummyOutputClient{}}
}
if cfg == nil {
cfg = common.NewConfig()
}
processors, err := processing.MakeDefaultObserverSupport(false)(info, logp.NewLogger("testbeat"), cfg)
if err != nil {
panic(err)
}
p, err := pipeline.New(
beat.Info{Name: "test-apm-server"},
info,
pipeline.Monitors{},
func(e queue.Eventer) (queue.Queue, error) {
return memqueue.NewBroker(nil, memqueue.Settings{
Expand All @@ -314,6 +322,7 @@ func DummyPipeline(clients ...outputs.Client) *pipeline.Pipeline {
pipeline.Settings{
WaitClose: 0,
WaitCloseMode: pipeline.NoWaitOnClose,
Processors: processors,
},
)
if err != nil {
Expand Down Expand Up @@ -383,21 +392,7 @@ func (bt *beater) smapElasticsearchHosts() []string {
return hosts
}

func setupBeater(t *testing.T, publisher beat.Pipeline, ucfg *common.Config, beatConfig *beat.BeatConfig) (*beater, func(), error) {
beatId, err := uuid.FromString("fbba762a-14dd-412c-b7e9-b79f903eb492")
require.NoError(t, err)
// create a beat
apmBeat := &beat.Beat{
Publisher: publisher,
Info: beat.Info{
Beat: "test-apm-server",
IndexPrefix: "test-apm-server",
Version: version.GetDefaultVersion(),
ID: beatId,
},
Config: beatConfig,
}

func setupBeater(t *testing.T, apmBeat *beat.Beat, ucfg *common.Config, beatConfig *beat.BeatConfig) (*beater, func(), error) {
// create our beater
beatBeater, err := New(apmBeat, ucfg)
assert.NoError(t, err)
Expand Down
26 changes: 23 additions & 3 deletions beater/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import (
"testing"
"time"

"github.com/gofrs/uuid"

"github.com/elastic/beats/libbeat/version"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -505,17 +509,33 @@ func setupServer(t *testing.T, cfg *common.Config, beatConfig *beat.BeatConfig,
require.NoError(t, err)
}

beatId, err := uuid.FromString("fbba762a-14dd-412c-b7e9-b79f903eb492")
require.NoError(t, err)
info := beat.Info{
Beat: "test-apm-server",
IndexPrefix: "test-apm-server",
Version: version.GetDefaultVersion(),
ID: beatId,
}

var pub beat.Pipeline
if events != nil {
// capture events
pubClient := NewChanClientWith(events)
pub = DummyPipeline(pubClient)
pub = DummyPipeline(cfg, info, pubClient)
} else {
// don't capture events
pub = DummyPipeline()
pub = DummyPipeline(cfg, info)
}

// create a beat
apmBeat := &beat.Beat{
Publisher: pub,
Info: info,
Config: beatConfig,
}

btr, stop, err := setupBeater(t, pub, baseConfig, beatConfig)
btr, stop, err := setupBeater(t, apmBeat, baseConfig, beatConfig)
if err == nil {
assert.NotEqual(t, btr.config.Host, "localhost:0", "config.Host unmodified")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"error": {
"culprit": "my.module.function_name",
"custom": {
Expand Down Expand Up @@ -317,6 +320,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"error": {
"exception": [
{
Expand Down Expand Up @@ -405,6 +411,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"error": {
"exception": [
{
Expand Down Expand Up @@ -493,6 +502,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"error": {
"grouping_key": "d6b3f958dfea98dc9ed2b57d5f0c48bb",
"id": "abcdef0123456789",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"error": {
"grouping_key": "d6b3f958dfea98dc9ed2b57d5f0c48bb",
"id": "abcdef0123456789",
Expand Down Expand Up @@ -74,6 +77,9 @@
"name": "elastic-node",
"version": "3.14.0"
},
"ecs": {
"version": "1.1.0-dev"
},
"observer": {
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
"hostname": "",
Expand Down Expand Up @@ -128,6 +134,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"host": {
"ip": "127.0.0.1"
},
Expand Down Expand Up @@ -198,6 +207,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"go": {
"memstats": {
"heap": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
}
},
"double_gauge": 3.141592653589793,
"ecs": {
"version": "1.1.0-dev"
},
"float_gauge": 9.16,
"integer_gauge": 42767,
"labels": {
Expand Down Expand Up @@ -78,6 +81,9 @@
"name": "elastic-node",
"version": "3.14.0"
},
"ecs": {
"version": "1.1.0-dev"
},
"go": {
"memstats": {
"heap": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"name": "elastic-node",
"version": "3.14.0"
},
"ecs": {
"version": "1.1.0-dev"
},
"observer": {
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
"hostname": "",
Expand Down Expand Up @@ -60,6 +63,9 @@
"name": "elastic-node",
"version": "3.14.0"
},
"ecs": {
"version": "1.1.0-dev"
},
"observer": {
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
"hostname": "",
Expand Down Expand Up @@ -110,6 +116,9 @@
"name": "elastic-node",
"version": "3.14.0"
},
"ecs": {
"version": "1.1.0-dev"
},
"labels": {
"tag1": "value1",
"tag2": 123,
Expand Down Expand Up @@ -167,6 +176,9 @@
"name": "elastic-node",
"version": "3.14.0"
},
"ecs": {
"version": "1.1.0-dev"
},
"observer": {
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
"hostname": "",
Expand Down Expand Up @@ -220,6 +232,9 @@
"name": "elastic-ruby",
"version": "2.2"
},
"ecs": {
"version": "1.1.0-dev"
},
"observer": {
"ephemeral_id": "00000000-0000-0000-0000-000000000000",
"hostname": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"host": {
"architecture": "x64",
"hostname": "prod1.example.com",
Expand Down Expand Up @@ -110,6 +113,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"host": {
"architecture": "x64",
"hostname": "prod1.example.com",
Expand Down Expand Up @@ -294,6 +300,9 @@
"container": {
"id": "container-id"
},
"ecs": {
"version": "1.1.0-dev"
},
"host": {
"architecture": "x64",
"hostname": "prod1.example.com",
Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
package cmd

import (
"github.com/spf13/pflag"

"github.com/elastic/apm-server/beater"
"github.com/elastic/apm-server/idxmgmt"
"github.com/elastic/apm-server/idxmgmt/ilm"

"github.com/elastic/apm-server/beater"
_ "github.com/elastic/apm-server/include"
"github.com/elastic/beats/libbeat/cmd"
"github.com/elastic/beats/libbeat/cmd/instance"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/monitoring/report"
"github.com/elastic/beats/libbeat/publisher/processing"
"github.com/spf13/pflag"
)

// Name of the beat (apm-server).
Expand Down Expand Up @@ -76,6 +75,7 @@ func init() {
},
ILM: ilm.MakeDefaultSupporter,
IndexManagement: idxmgmt.MakeDefaultSupporter,
Processing: processing.MakeDefaultObserverSupport(false),
})
// remove dashboard from export commands
for _, cmd := range RootCmd.ExportCmd.Commands() {
Expand Down
Loading

0 comments on commit 93a21f5

Please sign in to comment.