Skip to content

Commit

Permalink
Beatless initial PR (#7837)
Browse files Browse the repository at this point in the history
* Beatless initial PR

Add a new beat inside the x-pack folder under the Elastic License,
minimal requirement changes to have a build and a test running.

Main makefile exclude ASL2 for x-pack but check for Elastic.
Beats can override the license in their Makefile.
  • Loading branch information
ph committed Oct 18, 2018
1 parent 78ef120 commit 5361576
Show file tree
Hide file tree
Showing 24 changed files with 2,099 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ jobs:
go: $GO_VERSION
stage: test

# Beatless
- os: linux
env: TARGETS="-C x-pack/beatless testsuite"
go: $GO_VERSION
stage: test
- os: osx
env: TARGETS="TEST_ENVIRONMENT=0 -C x-pack/beatless testsuite"
go: $GO_VERSION
stage: test

# Generators
- os: linux
env: TARGETS="-C generator/metricbeat test"
Expand Down
9 changes: 9 additions & 0 deletions x-pack/beatless/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea
.vagrant
.vscode
/*/_meta/kibana.generated
beatless
build
data
fields.yml
logs
16 changes: 16 additions & 0 deletions x-pack/beatless/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEAT_NAME?=beatless
LICENSE=Elastic
BEAT_TITLE?=Beatless
SYSTEM_TESTS?=true
BEAT_PATH?=github.com/elastic/beats/x-pack/${BEAT_NAME}
TEST_ENVIRONMENT?=false
GOX_FLAGS=-arch="amd64 386 arm ppc64 ppc64le"
ES_BEATS?=../../
FIELDS_FILE_PATH=module

# Path to the libbeat Makefile
include $(ES_BEATS)/libbeat/scripts/Makefile

# Runs all collection steps and updates afterwards
.PHONY: collect
collect:
5 changes: 5 additions & 0 deletions x-pack/beatless/_meta/beat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
################### Beatless Configuration Example #########################

############################# Beatless ######################################

beatless:
9 changes: 9 additions & 0 deletions x-pack/beatless/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- key: beatless
title: beatless
description:
fields:
- name: counter
type: long
required: true
description: >
PLEASE UPDATE DOCUMENTATION
72 changes: 72 additions & 0 deletions x-pack/beatless/beater/beatless.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package beater

import (
"fmt"

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"

"github.com/elastic/beats/x-pack/beatless/bus"
"github.com/elastic/beats/x-pack/beatless/config"
)

// Beatless configuration.
type Beatless struct {
done chan struct{}
config config.Config
log *logp.Logger

// TODO: Add registry reference here.
}

// New creates an instance of beatless.
func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) {
c := config.DefaultConfig
if err := cfg.Unpack(&c); err != nil {
return nil, fmt.Errorf("error reading config file: %v", err)
}

bt := &Beatless{
done: make(chan struct{}),
config: c,
log: logp.NewLogger("beatless"),
}
return bt, nil
}

// Run starts beatless.
func (bt *Beatless) Run(b *beat.Beat) error {
bt.log.Info("beatless is running")
defer bt.log.Info("beatless stopped running")

client, err := b.Publisher.Connect()
if err != nil {
return err
}
defer client.Close()

// NOTE: Do not review below, this is the minimal to have a working PR.
bus := bus.New(client)
// TODO: noop
bus.Listen()

// Stop until we are tell to shutdown.
// TODO this is where the events catcher starts.
select {
case <-bt.done:
// Stop catching events.
}
return nil
}

// Stop stops beatless.
func (bt *Beatless) Stop() {
bt.log.Info("beatless is stopping")
defer bt.log.Info("beatless is stopped")
close(bt.done)
}
Loading

0 comments on commit 5361576

Please sign in to comment.