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

Beatless initial PR #8485

Merged
merged 102 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
9a4b449
Initial version of beatless
ph Aug 27, 2018
03efcf3
update function
ph Sep 25, 2018
e3cbcd5
Will be in another PR.
ph Sep 25, 2018
04761ea
remove trace
ph Sep 25, 2018
73105ea
Correctly report double licensed project and allow to skip file
ph Sep 25, 2018
cb4cfbf
oops
ph Sep 25, 2018
38a23ed
wrong config in the yaml
ph Sep 26, 2018
2468b2e
first round of comments from kvch
ph Sep 28, 2018
e78044f
pep8
ph Sep 28, 2018
f7be0bc
cleanup and fix a issue with the rebase.
ph Sep 28, 2018
4343913
missing file
ph Sep 28, 2018
558941a
Initial version of beatless
ph Aug 27, 2018
2f639bd
bad type
ph Sep 25, 2018
be469c7
Correctly report double licensed project and allow to skip file
ph Sep 25, 2018
aff6606
oops
ph Sep 25, 2018
9441f00
More refactoring a lot cleaner
ph Sep 27, 2018
d6e3d93
Adding logs and removal of subscription
ph Sep 27, 2018
fe92882
typo
ph Sep 27, 2018
ab02ae6
working on update
ph Sep 27, 2018
9e7a875
reorder methods and create an alias on the function
ph Sep 27, 2018
43f89ab
update alias
ph Sep 27, 2018
8098a38
cleaning the code.
ph Sep 28, 2018
897affa
Missing headers
ph Sep 28, 2018
f1c705f
Adding tests and renamed executer to executor
ph Sep 28, 2018
31c736e
fix failure
ph Sep 28, 2018
243c184
renaming adding tests
ph Sep 28, 2018
af5dc0d
what?
ph Sep 28, 2018
9b32a2b
Adding sanity check for cloudwatch logs
ph Sep 28, 2018
b5b0285
align problems
ph Sep 28, 2018
d430e82
sanity check for kinesis
ph Sep 28, 2018
acb0726
Adding SQS test
ph Sep 28, 2018
3b46144
adding headers
ph Sep 28, 2018
f5216f8
adding test for api gateway proxy
ph Sep 28, 2018
6b9d789
Trying out serverless framework with beatless
ph Oct 2, 2018
ee3e628
ok work as dependencies
ph Oct 2, 2018
cc6dc0a
Cloud formation
ph Oct 3, 2018
7ed21c5
Not needed
ph Oct 3, 2018
63c2947
make it work with waiting
ph Oct 3, 2018
e2e7bbe
update cloudformation
ph Oct 3, 2018
14ccd23
move it forward
ph Oct 3, 2018
0ad5a16
working here
ph Oct 3, 2018
a605ac5
Update / deploy works
ph Oct 3, 2018
40248b9
cleanup
ph Oct 3, 2018
cda83d9
now ok wait check
ph Oct 3, 2018
f09b187
correctly work
ph Oct 3, 2018
f2a38a6
cleaned
ph Oct 3, 2018
878ea98
one method
ph Oct 3, 2018
ff8767d
refactor
ph Oct 3, 2018
3749a1d
it work
ph Oct 3, 2018
4cece4b
move zip outside
ph Oct 3, 2018
ad3db4f
You can now remove function on lambda
ph Oct 3, 2018
d869dcb
Wait for deletion
ph Oct 3, 2018
3b62460
can generate a stand alone package.
ph Oct 3, 2018
4db9ed0
add headers
ph Oct 3, 2018
44bb82a
Overrides the types of goformation
ph Oct 3, 2018
cea697e
no more context in the executor
ph Oct 4, 2018
d8d9b1f
use the right default for unreserved concurrency
ph Oct 4, 2018
c5e5d2b
Allow overrides
ph Oct 4, 2018
d436947
add clougwatch log stream
ph Oct 4, 2018
59b4efc
Make sure that we have write lambda logs to cloudwatch
ph Oct 4, 2018
919cf63
optimize
ph Oct 4, 2018
8082fdd
Update the configuration
ph Oct 4, 2018
a18af76
allow to generate a package
ph Oct 4, 2018
ba5a9fb
better wording
ph Oct 4, 2018
0743221
first round kvch
ph Oct 4, 2018
a94fe85
not needed for this PR
ph Oct 4, 2018
f1772be
remove non used code
ph Oct 4, 2018
37166f8
missing test
ph Oct 4, 2018
1a73ddc
Minor: Hide the Registry under feature.GlobalRegistry()
ph Oct 16, 2018
c6fd6eb
Minor: Add missing license type
ph Oct 16, 2018
32de16c
Remove: use user defined ignore instead of project ignore.
ph Oct 16, 2018
20fa668
REMOVE: left over comments when debugging the notice generator
ph Oct 16, 2018
8608abb
MINOR: Small corrections in the configuration files
ph Oct 16, 2018
5f8a21c
MINOR: link the max_bulk_size with the max events for queue flush
ph Oct 16, 2018
1b5d79c
MINOR: move the clientFactory inline method into his own function
ph Oct 16, 2018
196790e
MAJOR: it's over 9000
ph Oct 16, 2018
2f5b195
MINOR: refactor, use function pointer instead of redefining the same
ph Oct 16, 2018
cec8df9
MINOR: typo
ph Oct 16, 2018
1c6618c
MINOR: use ioutil.ReadCloser and create a wrapper function for
ph Oct 16, 2018
e7b3ef8
MINOR: refactor with urso's comments
ph Oct 16, 2018
1460744
MINOR: FeatureRegistry to Registry
ph Oct 16, 2018
a6a47b0
MINOR: use Swap
ph Oct 16, 2018
4f4ba1e
MINOR: adjust logging/error
ph Oct 16, 2018
0e9d453
MINOR: check err
ph Oct 16, 2018
b8b241a
MINOR: Add random with the host list.
ph Oct 16, 2018
ab1ec7a
MINOR: do zero allocation for nullcli
ph Oct 17, 2018
5ed8466
MINOR: formatting + use handler type for AWS functions.
ph Oct 17, 2018
6d799dc
MINOR: Added doc
ph Oct 17, 2018
d9a32f4
MINOR: typo
ph Oct 17, 2018
d7c0415
MINOR: cleanups
ph Oct 17, 2018
3f932ae
Fix fmt
ph Oct 17, 2018
d80ad14
hound comment
ph Oct 17, 2018
fd4ab64
CHANGE: make update, deploy and remove top level command.
ph Oct 18, 2018
423a85c
use new uuid library
ph Oct 18, 2018
39ed4cf
uuid again
ph Oct 18, 2018
38c77b7
better formatting for the reference file.
ph Oct 18, 2018
bf69342
use a function instead of a method on a struct
ph Oct 18, 2018
417d211
Fix a few issue with logging
ph Oct 18, 2018
ea2c451
return directly
ph Oct 18, 2018
72cb211
Ensure capitalization on all logger message are following the
ph Oct 19, 2018
0f84be5
rewording
ph Oct 19, 2018
406b0fa
Better logging messages
ph Oct 19, 2018
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
1 change: 1 addition & 0 deletions dev-tools/generate_notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import csv
import re
import pdb
import copy


Expand Down
13 changes: 9 additions & 4 deletions libbeat/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

// Registry is the global plugin registry, this variable is meant to be temporary to move all the
// internal factory to receive a context that include the current beat registry.
var Registry = newRegistry()
var registry = NewRegistry()

// Featurable implements the description of a feature.
type Featurable interface {
Expand Down Expand Up @@ -96,10 +96,15 @@ func New(namespace, name string, factory interface{}, description Describer) *Fe
}
}

// GlobalRegistry return the configured global registry.
func GlobalRegistry() *Registry {
return registry
}

// RegisterBundle registers a bundle of features.
func RegisterBundle(bundle *Bundle) error {
for _, f := range bundle.Features() {
err := Registry.Register(f)
err := GlobalRegistry().Register(f)
if err != nil {
return err
}
Expand All @@ -119,7 +124,7 @@ func MustRegisterBundle(bundle *Bundle) {
// implementation.
func OverwriteBundle(bundle *Bundle) error {
for _, f := range bundle.Features() {
err := Registry.Register(f)
err := GlobalRegistry().Register(f)
if err != nil {
return err
}
Expand All @@ -138,7 +143,7 @@ func MustOverwriteBundle(bundle *Bundle) {

// Register register a new feature on the global registry.
func Register(feature Featurable) error {
return Registry.Register(feature)
return GlobalRegistry().Register(feature)
}

// MustRegister register a new Feature on the global registry and panic on error.
Expand Down
20 changes: 10 additions & 10 deletions libbeat/feature/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ import (

type mapper map[string]map[string]Featurable

// Registry implements a global registry for any kind of feature in beats.
// Registry implements a global FeatureRegistry for any kind of feature in beats.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on exported type FeatureRegistry should be of the form "FeatureRegistry ..." (with optional leading article)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment indeed reads somewhat funny.

// feature are grouped by namespace, a namespace is a kind of plugin like outputs, inputs, or queue.
// The feature name must be unique.
type registry struct {
type Registry struct {
sync.RWMutex
namespaces mapper
log *logp.Logger
}

// NewRegistry returns a new registry.
func newRegistry() *registry {
return &registry{
func NewRegistry() *Registry {
return &Registry{
namespaces: make(mapper),
log: logp.NewLogger("registry"),
}
}

// Register registers a new feature into a specific namespace, namespace are lazy created.
// Feature name must be unique.
func (r *registry) Register(feature Featurable) error {
func (r *Registry) Register(feature Featurable) error {
r.Lock()
defer r.Unlock()

Expand Down Expand Up @@ -97,7 +97,7 @@ func (r *registry) Register(feature Featurable) error {
}

// Unregister removes a feature from the registry.
func (r *registry) Unregister(namespace, name string) error {
func (r *Registry) Unregister(namespace, name string) error {
r.Lock()
defer r.Unlock()
ns := normalize(namespace)
Expand All @@ -117,7 +117,7 @@ func (r *registry) Unregister(namespace, name string) error {
}

// Lookup searches for a Feature by the namespace-name pair.
func (r *registry) Lookup(namespace, name string) (Featurable, error) {
func (r *Registry) Lookup(namespace, name string) (Featurable, error) {
r.RLock()
defer r.RUnlock()

Expand All @@ -138,7 +138,7 @@ func (r *registry) Lookup(namespace, name string) (Featurable, error) {
}

// LookupAll returns all the features for a specific namespace.
func (r *registry) LookupAll(namespace string) ([]Featurable, error) {
func (r *Registry) LookupAll(namespace string) ([]Featurable, error) {
r.RLock()
defer r.RUnlock()

Expand All @@ -160,7 +160,7 @@ func (r *registry) LookupAll(namespace string) ([]Featurable, error) {
}

// Overwrite allow to replace an existing feature with a new implementation.
func (r *registry) Overwrite(feature Featurable) error {
func (r *Registry) Overwrite(feature Featurable) error {
_, err := r.Lookup(feature.Namespace(), feature.Name())
if err == nil {
err := r.Unregister(feature.Namespace(), feature.Name())
Expand All @@ -173,7 +173,7 @@ func (r *registry) Overwrite(feature Featurable) error {
}

// Size returns the number of registered features in the registry.
func (r *registry) Size() int {
func (r *Registry) Size() int {
r.RLock()
defer r.RUnlock()

Expand Down
24 changes: 12 additions & 12 deletions libbeat/feature/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ func TestRegister(t *testing.T) {
f := func() {}

t.Run("when the factory is nil", func(t *testing.T) {
r := newRegistry()
r := NewRegistry()
err := r.Register(New("outputs", "null", nil, defaultDetails))
if !assert.Error(t, err) {
return
}
})

t.Run("namespace and feature doesn't exist", func(t *testing.T) {
r := newRegistry()
r := NewRegistry()
err := r.Register(New("outputs", "null", f, defaultDetails))
if !assert.NoError(t, err) {
return
Expand All @@ -47,7 +47,7 @@ func TestRegister(t *testing.T) {
})

t.Run("namespace exists and feature doesn't exist", func(t *testing.T) {
r := newRegistry()
r := NewRegistry()
r.Register(New("processor", "bar", f, defaultDetails))
err := r.Register(New("processor", "foo", f, defaultDetails))
if !assert.NoError(t, err) {
Expand All @@ -58,7 +58,7 @@ func TestRegister(t *testing.T) {
})

t.Run("namespace exists and feature exists and not the same factory", func(t *testing.T) {
r := newRegistry()
r := NewRegistry()
r.Register(New("processor", "foo", func() {}, defaultDetails))
err := r.Register(New("processor", "foo", f, defaultDetails))
if !assert.Error(t, err) {
Expand All @@ -69,7 +69,7 @@ func TestRegister(t *testing.T) {

t.Run("when the exact feature is already registered", func(t *testing.T) {
feature := New("processor", "foo", f, defaultDetails)
r := newRegistry()
r := NewRegistry()
r.Register(feature)
err := r.Register(feature)
if !assert.NoError(t, err) {
Expand All @@ -82,7 +82,7 @@ func TestRegister(t *testing.T) {
func TestFeature(t *testing.T) {
f := func() {}

r := newRegistry()
r := NewRegistry()
r.Register(New("processor", "foo", f, defaultDetails))
r.Register(New("HOLA", "fOO", f, defaultDetails))

Expand Down Expand Up @@ -112,7 +112,7 @@ func TestFeature(t *testing.T) {
func TestLookup(t *testing.T) {
f := func() {}

r := newRegistry()
r := NewRegistry()
r.Register(New("processor", "foo", f, defaultDetails))
r.Register(New("processor", "foo2", f, defaultDetails))
r.Register(New("HELLO", "fOO", f, defaultDetails))
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestUnregister(t *testing.T) {
f := func() {}

t.Run("when the namespace and the feature exists", func(t *testing.T) {
r := newRegistry()
r := NewRegistry()
r.Register(New("processor", "foo", f, defaultDetails))
assert.Equal(t, 1, r.Size())
err := r.Unregister("processor", "foo")
Expand All @@ -157,7 +157,7 @@ func TestUnregister(t *testing.T) {
})

t.Run("when the namespace exist and the feature doesn't", func(t *testing.T) {
r := newRegistry()
r := NewRegistry()
r.Register(New("processor", "foo", f, defaultDetails))
assert.Equal(t, 1, r.Size())
err := r.Unregister("processor", "bar")
Expand All @@ -168,7 +168,7 @@ func TestUnregister(t *testing.T) {
})

t.Run("when the namespace doesn't exists", func(t *testing.T) {
r := newRegistry()
r := NewRegistry()
r.Register(New("processor", "foo", f, defaultDetails))
assert.Equal(t, 1, r.Size())
err := r.Unregister("outputs", "bar")
Expand All @@ -182,15 +182,15 @@ func TestUnregister(t *testing.T) {
func TestOverwrite(t *testing.T) {
t.Run("when the feature doesn't exist", func(t *testing.T) {
f := func() {}
r := newRegistry()
r := NewRegistry()
assert.Equal(t, 0, r.Size())
r.Overwrite(New("processor", "foo", f, defaultDetails))
assert.Equal(t, 1, r.Size())
})

t.Run("overwrite when the feature exists", func(t *testing.T) {
f := func() {}
r := newRegistry()
r := NewRegistry()
r.Register(New("processor", "foo", f, defaultDetails))
assert.Equal(t, 1, r.Size())

Expand Down
2 changes: 1 addition & 1 deletion libbeat/management/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Register(name string, fn FactoryFunc, stability feature.Stability) {
// Factory retrieves config manager constructor. If no one is registered
// it will create a nil manager
func Factory() FactoryFunc {
factories, err := feature.Registry.LookupAll(Namespace)
factories, err := feature.GlobalRegistry().LookupAll(Namespace)
if err != nil {
return nilFactory
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/publisher/queue/queue_reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func RegisterType(name string, fn Factory) {

// FindFactory retrieves a queue types constructor. Returns nil if queue type is unknown
func FindFactory(name string) Factory {
f, err := feature.Registry.Lookup(Namespace, name)
f, err := feature.GlobalRegistry().Lookup(Namespace, name)
if err != nil {
return nil
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/beatless/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.vscode
/*/_meta/kibana.generated
beatless
beatless.test
build
data
fields.yml
Expand Down
16 changes: 16 additions & 0 deletions x-pack/beatless/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.10.3
MAINTAINER Pier-Hugues Pellerin <ph@elastic.co>

RUN set -x && \
apt-get update && \
apt-get install -y --no-install-recommends \
netcat python-pip rsync virtualenv && \
apt-get clean

RUN pip install --upgrade setuptools

# Setup work environment
ENV BEATLESS_PATH /go/src/github.com/elastic/beats/x-pack/beatless

RUN mkdir -p $BEATLESS_PATH/build/coverage
WORKDIR $BEATLESS_PATH
8 changes: 7 additions & 1 deletion x-pack/beatless/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ LICENSE=Elastic
BEAT_TITLE?=Beatless
SYSTEM_TESTS?=true
BEAT_PATH?=github.com/elastic/beats/x-pack/${BEAT_NAME}
TEST_ENVIRONMENT?=false
TEST_ENVIRONMENT?=true
GOX_FLAGS=-arch="amd64 386 arm ppc64 ppc64le"
ES_BEATS?=../../
FIELDS_FILE_PATH=module
Expand All @@ -14,3 +14,9 @@ include $(ES_BEATS)/libbeat/scripts/Makefile
# Runs all collection steps and updates afterwards
.PHONY: collect
collect:

# TODO(ph) This is used for debugging until we change the build to create 2 artifacts,
# we will do this in another PR.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue we can reference? We should create one if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a followup PR.

.PHONY: linux
linux:
GOOS=linux go build -o pkg/beatless
49 changes: 49 additions & 0 deletions x-pack/beatless/_meta/beat.reference.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
########################## Beatless Configuration ###########################

# This file is a full configuration example documenting all non-deprecated
# options in comments. For a shorter configuration example, that contains only
# the most common options, please see beatless.yml in the same directory.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/beatless/index.html
#
#============================ Provider ===============================
# Configure functions to run on AWS Lambda, currently we assume that the credentials
# are present in the environment to correctly create the function when using the CLI.
#
beatless.provider.aws.functions:
# Define the list of function availables, each function required to have a unique name.
- name: fn_cloudwatch_logs
type: cloudwatch_logs

# Description of the method to help identify them when you run multiples functions.
description: "lambda function for cloudwatch logs"

# Concurrency, is the reserved number of instances for that function.
# Default is unreserved.
#
# Note: There is a hard limit of 1000 functions of any kind per account.
#concurrency: 5

# The maximum memory allocated for this function, the configured size must be a factor of 64.
# There is a hard limit of 3008MiB for each function. Default is 128MiB.
#memory_size: 128MiB

# Dead letter queue configuration, this must be set to an ARN pointing to a SQS queue.
# dead_letter_config.target_arn:
ph marked this conversation as resolved.
Show resolved Hide resolved

# Optional fields that you can specify to add additional information to the
# output. Fields can be scalar values, arrays, dictionaries, or any nested
# combination of these.
#fields:
# env: staging

# List of cloudwatch log group registered to that function.
triggers:
- log_group_name: /aws/lambda/beatless-cloudwatch_logs
filter_pattern: mylog_

# Define custom processors for this function.
#processors:
# - dissect:
# tokenizer: "%{key1} %{key2}"
38 changes: 35 additions & 3 deletions x-pack/beatless/_meta/beat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
################### Beatless Configuration Example #########################
###################### Beatless Configuration Example #######################

############################# Beatless ######################################
# This file is an example configuration file highlighting only the most common
# options. The beatless.reference.yml file from the same directory contains all the
# supported options with more comments. You can use it as a reference.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/beatless/index.html
#

beatless:
#============================ Provider ===============================
# Configure functions to run on AWS Lambda, currently we assume that the credentials
# are present in the environment to correctly create the function when using the CLI.
#
beatless.provider.aws.functions:
# Accepts events from a cloudwatch log group.
- name: fn_cloudwatch_logs
type: cloudwatch_logs
# The IAM role that the lambda will take when executing your function.
role: iam
# List of cloudwatch streams registered to this function.
triggers:
- log_group_name: /aws/lambda/beatless-cloudwatch_logs
filter_name: myfiltername
filter_pattern: mylog_

# Accepts events from a SQS queue.
# - name: fn_sqs
# type: sqs
#
# Accepts events form a Kinesis stream
# - name: fn_kinesis
# type: kinesis
#
# Accepts events from an api gateway proxy call.
# - name: fn_apigateway_proxy
# type: api_gateway_proxy
Loading