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 authored and Steffen Siering committed Aug 6, 2018
1 parent 235a689 commit c4df1be
Show file tree
Hide file tree
Showing 26 changed files with 2,107 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ check: python-env
.PHONY: check-headers
check-headers:
@go get github.com/elastic/go-licenser
@go-licenser -d
@go-licenser -d -exclude x-pack
@go-licenser -d -license Elastic x-pack

.PHONY: add-headers
add-headers:
@go get github.com/elastic/go-licenser
@go-licenser
@go-licenser -exclude x-pack
@go-licenser -license Elastic x-pack

# Corrects spelling errors
.PHONY: misspell
Expand Down
7 changes: 4 additions & 3 deletions libbeat/scripts/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### VARIABLE SETUP ###
### Application using libbeat may override the following variables in their Makefile
BEAT_NAME?=libbeat## @packaging Name of the binary
LICENSE?=ASL2
BEAT_TITLE?=${BEAT_NAME}## @packaging Title of the application
BEAT_PATH?=github.com/elastic/beats/${BEAT_NAME}
BEAT_PACKAGE_NAME?=${BEAT_NAME}
Expand Down Expand Up @@ -123,14 +124,14 @@ check: check-headers python-env prepare-tests ## @build Checks project and sourc
check-headers:
ifndef CHECK_HEADERS_DISABLED
@go get github.com/elastic/go-licenser
@go-licenser -d
@go-licenser -d -license ${LICENSE}
endif

.PHONY: add-headers
add-headers:
ifndef CHECK_HEADERS_DISABLED
@go get github.com/elastic/go-licenser
@go-licenser
@go-licenser -license ${LICENSE}
endif

.PHONY: fmt
Expand Down Expand Up @@ -332,7 +333,7 @@ endif

ifneq ($(shell [[ $(BEAT_NAME) == libbeat || $(BEAT_NAME) == metricbeat ]] && echo true ),true)
mkdir -p include
go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -pkg include -in fields.yml -out include/fields.go $(BEAT_NAME)
go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -pkg include -in fields.yml -out include/fields.go $(BEAT_NAME)
endif

ifneq ($(shell [[ $(BEAT_NAME) == libbeat ]] && echo true ),true)
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 c4df1be

Please sign in to comment.