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

Merge agent to master #16494

Merged
merged 116 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
c7b7b2b
Moved agent into beats repo (#14163)
michalpristas Oct 25, 2019
56ffef0
ca cannot be shorthand (#14366)
michalpristas Nov 1, 2019
20cfcdd
revisiting sample configuration and bringin it up to date (#14367)
michalpristas Nov 1, 2019
4389042
Agent: updated transpile rules for metricbeat (#14403)
michalpristas Nov 11, 2019
565c4ad
Moved agent into beats repo (#14163)
michalpristas Oct 25, 2019
471be1d
ca cannot be shorthand (#14366)
michalpristas Nov 1, 2019
073aa0b
revisiting sample configuration and bringin it up to date (#14367)
michalpristas Nov 1, 2019
9c124fc
Agent: updated transpile rules for metricbeat (#14403)
michalpristas Nov 11, 2019
c8c8c24
conflicts resolved
michalpristas Nov 25, 2019
e2ac4ab
merged conflicts
michalpristas Nov 25, 2019
441bde5
Refactor: Rename pipeline into stream (#14593)
ph Nov 26, 2019
ce8bff4
Merge branch 'master' into fleet
michalpristas Dec 2, 2019
b85351b
Change from Enrollment token to use Elasticsearch API key (#14869)
ph Dec 2, 2019
5d49777
Change the Authentication mechanism for fleet. (#14867)
ph Dec 2, 2019
b17619f
Agent add support for multiples outputs (#14830)
ph Dec 3, 2019
fa0d309
add delta wait to ensure bucket ticked (#14932)
michalpristas Dec 4, 2019
bdf28d9
Add required API calls to retrieve configuration from Fleet. (#14871)
ph Dec 4, 2019
1bc5895
[Fleet] Enable log introspections (#14390)
michalpristas Dec 5, 2019
aef8334
Fakewebapi simulare a Fleet API endpoint for testing the checkin (#14…
ph Dec 5, 2019
a379823
resolved conflicts with master
michalpristas Dec 10, 2019
1743bbc
[Agent] Grpc support for agent to beat communication (#14835)
michalpristas Dec 11, 2019
9394639
Store access token missing (#15089)
ph Dec 16, 2019
38591b9
Update ecslog to fix an infinite loop (#15142)
ph Dec 17, 2019
73fc672
Update notice (#15189)
ph Dec 18, 2019
4b479d2
The MapVisitor didn't handle correctly Uint and Uin64 (#15187)
ph Dec 18, 2019
0b978c7
[Agent] Make default config congestable by agent (#15191)
michalpristas Dec 18, 2019
f307368
[Agent] Include beats in agent package (#15046)
michalpristas Dec 18, 2019
06a7a0f
Allow the Agent to retrieve configuration from the Fleet API. (#15027)
ph Dec 18, 2019
e25649f
[Agent] Agent UUID step 1 (#15144)
michalpristas Dec 19, 2019
7104867
[Agent] Parse and pass correct configuration sections into correspond…
michalpristas Dec 19, 2019
7a26160
Agent/fix api fleet issues (#15228)
ph Dec 20, 2019
992ef0c
[Agent] Workaround the API format returned by Fleet. (#15244)
ph Dec 20, 2019
c863b03
[Agent] Cleanup yaml and remove OS and Arch (#15267)
michalpristas Dec 31, 2019
e91114b
[Agent] Persist UUID (#15243)
michalpristas Dec 31, 2019
358dab5
[Agent] refactor reporter (#15237)
michalpristas Jan 2, 2020
372b905
[Agent] Fix flaky tests concerning the TockenBucket (#15282)
ph Jan 2, 2020
792b5b0
[Agent] Onboard custom errors package - part 2 (#15294)
michalpristas Jan 2, 2020
6ff0e87
conflicts on master
michalpristas Jan 3, 2020
9539116
Scheduler now add some jitter when waiting on Tick. (#15325)
ph Jan 6, 2020
aeaae85
Enroll delay (#15327)
ph Jan 6, 2020
af4a428
[Agent] Onboard to custom errors type (#15340)
michalpristas Jan 6, 2020
13b34a0
Retries on error when communicating with Fleet (#15309)
ph Jan 7, 2020
a1f7e85
StateResolve fix issues with should state and current State (#15299)
ph Jan 7, 2020
31e9bfb
[Agent] Combine spec with translation rules together with app info sp…
michalpristas Jan 8, 2020
2c80800
[Agent] ACK action events on a handler level (#15352)
michalpristas Jan 9, 2020
a1b2547
Fix the tick than wait strategy for the PeriodicJitter (#15393)
ph Jan 9, 2020
bfe43ff
Increase polling frequency to provide quicker feedback (#15406)
ph Jan 9, 2020
f292179
fixed casing in spec and binary path resolution (#15410)
michalpristas Jan 10, 2020
604a42f
Keep only Filebeat and Metricbeat enabled (#15390)
ph Jan 10, 2020
8242a93
[Agent] Ignore not supported applications on operator level (#15408)
michalpristas Jan 13, 2020
a4be561
[Agent] Send hostname when enrolling (#15496)
michalpristas Jan 13, 2020
0691879
[Agent] Batch ACKs together (#15413)
michalpristas Jan 13, 2020
520da69
[Agent] Remove workaround outpout url returned by Fleet (#15398)
nchaulet Jan 13, 2020
4e04894
[Agent] Fleet auth round tripper nil ptr (#15472)
ph Jan 13, 2020
b30f3a4
Scheduler close ordering (#15481)
ph Jan 13, 2020
c53d18e
[Agent] Send meta with every checkin request (#15499)
michalpristas Jan 13, 2020
a9a71ca
Disable ILM setup and template setup (#15468)
ph Jan 13, 2020
42507a2
[Agent] Fix panic on backoff Retry (#15533)
michalpristas Jan 14, 2020
dfa954a
When the Agent received no streams in the configuration we should sto…
ph Jan 14, 2020
b0dd953
Make sure the xpack fleet is enabled (#15578)
ph Jan 15, 2020
b4622dd
[Agent] Small fixes from local testing (#15573)
michalpristas Jan 16, 2020
5396c6d
[Agent] Fix empty policy handler (#15626)
michalpristas Jan 20, 2020
87b725b
[Agent] Incorporate new ACK endpoint (#15454)
michalpristas Jan 20, 2020
7675097
interrupt on stop (#15673)
michalpristas Jan 20, 2020
7857d48
[Agent] Enable usage of path variables in configuration (#15576)
michalpristas Jan 20, 2020
fce54f7
Persist the last good ActionPolicyChange on disk (#15641)
ph Jan 20, 2020
6ec6288
[Agent] Re-introduce STOPPING event subtype (#15672)
michalpristas Jan 21, 2020
e562629
[Agent] Rule extracting items from array (#15809)
michalpristas Jan 28, 2020
71bab46
resolved conflicts
michalpristas Jan 29, 2020
47c43a9
[Agent] Wait for GRPC on start (#15954)
michalpristas Feb 3, 2020
9886329
Merge branch 'master' into fleet
ph Feb 10, 2020
93a6f77
Agent Configuration examples (#15940)
ph Feb 11, 2020
888beee
Metricbeat fix imports in magefile (#16214)
michalpristas Feb 12, 2020
662d0b4
Agent configuration tweaks (#16240)
ph Feb 12, 2020
02c6156
Agent/ca sha256 (#16217)
ph Feb 12, 2020
6f27724
Ensure Kibana version is checked (#16258)
ph Feb 12, 2020
c975340
[Agent] Using context propagated to (#16020)
michalpristas Feb 13, 2020
32b4ef7
Migration of Fleet -> ingest_manager affect the API paths (#16314)
ph Feb 13, 2020
e0b3e9c
Merge branch 'master' of github.com:elastic/beats into feature-ingest
ph Feb 17, 2020
368af58
Merge pull request #16375 from ph/agent-merges/feb17
ph Feb 18, 2020
77f5f68
Make spec_test idempotent (#16392)
ph Feb 24, 2020
caff56c
Merge remote-tracking branch 'origin' into feature-ingest
ph Feb 24, 2020
112d2d6
Merge remote-tracking branch 'origin/feature-ingest' into feature-ingest
ph Feb 24, 2020
3ef7ccb
Example of a Suricata datasource configuration (#16496)
ph Feb 25, 2020
1ca0933
Move release package and custom kibana where it is used the most. (#1…
ph Feb 25, 2020
be23233
Merge remote-tracking branch 'origin/feature-ingest' into feature-ingest
ph Feb 25, 2020
f6d0d9f
Move specific gitignore into agent directory (#16607)
ph Feb 26, 2020
3bb0545
Guard against double slashes (#16559)
ph Feb 26, 2020
657451b
Merge remote-tracking branch 'origin/feature-ingest' into merge-agent…
ph Feb 26, 2020
9b5d675
[Agent] Include agentID in event payload (#16327)
michalpristas Mar 2, 2020
bc9c170
Merge remote-tracking branch 'origin/feature-ingest' into merge-agent…
ph Mar 2, 2020
3c1bd80
Merge remote-tracking branch 'origin/master' into merge-agent-in-master
ph Mar 2, 2020
1e32eb3
Conflicts
ph Mar 2, 2020
9ab83df
Fixit
ph Mar 2, 2020
d662fbc
Merge remote-tracking branch 'origin/master' into merge-agent-in-master
ph Mar 3, 2020
404cf03
use go modules
ph Mar 3, 2020
589bb21
Migrating to modules
ph Mar 3, 2020
6127f41
Fix for go modules
ph Mar 3, 2020
f27903e
match magetools
ph Mar 3, 2020
49df8aa
Align deps
ph Mar 3, 2020
773e8d1
What?
ph Mar 3, 2020
563df87
Why it is removed?
ph Mar 3, 2020
8ab4c79
Will need another pair of eye on this problem
ph Mar 3, 2020
b8ec22b
Disable suite followup in https://github.com/elastic/beats/issues/16771
ph Mar 3, 2020
38a913d
mage vendor
ph Mar 3, 2020
388c906
tag v0.0.1 for ecslog
ph Mar 4, 2020
5887bdd
notice
ph Mar 4, 2020
84ee7cf
Fix windows build
ph Mar 5, 2020
f2bf6aa
Merge remote-tracking branch 'origin/master' into merge-agent-in-master
ph Mar 5, 2020
8538f4d
package has been moved..
ph Mar 5, 2020
05d37e0
Merge remote-tracking branch 'origin/master' into merge-agent-in-master
ph Mar 5, 2020
b9a239c
Fixing windows tests #1
ph Mar 5, 2020
462f2c6
Fix and skipped more tests
ph Mar 5, 2020
309365c
More skip on windows
ph Mar 5, 2020
4609c06
placeholder for windows. system test.
ph Mar 6, 2020
7baf137
Fixit.
ph Mar 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ x-pack/dockerlogbeat/temproot.tar
*.test
*.prof
*.pyc

# agent
ph marked this conversation as resolved.
Show resolved Hide resolved
agent/core/plugin/operation/tests/scripts/configurable/1.0/configurable
x-pack/agent/build/
x-pack/agent/agent.dev.yml
x-pack/agent/pkg/agent/operation/tests/scripts/short--1.0.yml
x-pack/agent/pkg/agent/operation/tests/scripts/configurable-1.0-darwin-x86/configurable
x-pack/agent/pkg/agent/operation/tests/scripts/configurablebyfile-1.0-darwin-x86/configurablebyfile
x-pack/agent/pkg/agent/application/fleet.yml
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ jobs:
go: $TRAVIS_GO_VERSION
stage: test

# Agent
Copy link
Member

Choose a reason for hiding this comment

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

Do we have this also in our jenkins build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

- os: linux
env: TARGETS="-C x-pack/agent testsuite"
go: $TRAVIS_GO_VERSION
stage: test
- os: osx
env: TARGETS="TEST_ENVIRONMENT=0 -C x-pack/agent testsuite"
go: $TRAVIS_GO_VERSION
stage: test

# Generators
- os: linux
env: TARGETS="-C generator/metricbeat test test-package"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BUILD_DIR=$(CURDIR)/build
COVERAGE_DIR=$(BUILD_DIR)/coverage
BEATS?=auditbeat filebeat heartbeat journalbeat metricbeat packetbeat winlogbeat x-pack/functionbeat
BEATS?=auditbeat filebeat heartbeat journalbeat metricbeat packetbeat winlogbeat x-pack/functionbeat x-pack/agent
PROJECTS=libbeat $(BEATS)
PROJECTS_ENV=libbeat filebeat metricbeat
PYTHON_ENV?=$(BUILD_DIR)/python-env
Expand Down
800 changes: 800 additions & 0 deletions NOTICE.txt

Large diffs are not rendered by default.

223 changes: 223 additions & 0 deletions agent/kibana/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
// 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.

package kibana

import (
"context"
"io"
"net/http"
"net/url"
"strings"
"time"

"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/outputs/transport"
"github.com/elastic/beats/x-pack/agent/pkg/config"
"github.com/elastic/beats/x-pack/agent/pkg/core/logger"
)

const kibanaPort = 5601

type requestFunc func(string, string, url.Values, io.Reader) (*http.Request, error)
type wrapperFunc func(rt http.RoundTripper) (http.RoundTripper, error)

type clienter interface {
Send(
method string,
path string,
params url.Values,
headers http.Header,
body io.Reader,
) (*http.Response, error)
Close() error
}

// Client wraps an http.Client and takes care of making the raw calls to kibana, the client should
// stay simple and specificals should be implemented in external action instead of adding new methods
// to the client. For authenticated calls or sending fields on every request, create customer RoundTripper
// implementations that will take care of the boiler plates.
type Client struct {
log *logger.Logger
request requestFunc
client http.Client
config *Config
}

// New creates new Kibana API client.
func New(
log *logger.Logger,
factory requestFunc,
cfg *Config,
httpClient http.Client,
) (*Client, error) {
c := &Client{
log: log,
request: factory,
client: httpClient,
config: cfg,
}
return c, nil
}

// NewConfigFromURL returns a Kibana Config based on a received host.
func NewConfigFromURL(kURL string) (*Config, error) {
u, err := url.Parse(kURL)
if err != nil {
return nil, errors.Wrap(err, "could not parse Kibana url")
}

var username, password string
if u.User != nil {
username = u.User.Username()
// _ is true when password is set.
password, _ = u.User.Password()
}

c := defaultClientConfig()
c.Protocol = Protocol(u.Scheme)
c.Host = u.Host
c.Path = u.Path
c.Username = username
c.Password = password

return &c, nil
}

// NewWithRawConfig returns a new Kibana client with a specified configuration.
func NewWithRawConfig(log *logger.Logger, config *config.Config, wrapper wrapperFunc) (*Client, error) {
l := log
if l == nil {
log, err := logger.New()
if err != nil {
return nil, err
}
l = log
}

cfg := &Config{}
if err := config.Unpack(cfg); err != nil {
return nil, errors.Wrap(err, "invidate configuration")
}

return NewWithConfig(l, cfg, wrapper)
}

// NewWithConfig takes a Kibana Config and return a client.
func NewWithConfig(log *logger.Logger, cfg *Config, wrapper wrapperFunc) (*Client, error) {
var transport http.RoundTripper
transport, err := makeTransport(cfg.Timeout, cfg.TLS)
if err != nil {
return nil, err
}

if cfg.IsBasicAuth() {
// Pass basic auth credentials to all the underlying calls.
transport = NewBasicAuthRoundTripper(transport, cfg.Username, cfg.Password)
}

if wrapper != nil {
transport, err = wrapper(transport)
if err != nil {
return nil, errors.Wrap(err, "fail to create transport client")
}
}

httpClient := http.Client{
Transport: transport,
Timeout: cfg.Timeout,
}

p := strings.Join([]string{cfg.Path, cfg.SpaceID}, "/")

kibanaURL, err := common.MakeURL(string(cfg.Protocol), p, cfg.Host, kibanaPort)
if err != nil {
return nil, errors.Wrap(err, "invalid Kibana endpoint")
}

return New(log, prefixRequestFactory(kibanaURL), cfg, httpClient)
}

// Send executes a direct calls agains't the Kibana API, the method will takes cares of cloning
// also add necessary headers for Kibana likes: "Content-Type", "Accept", and "kbn-xsrf".
// No assumptions is done on the response concerning the received format, this will be the responsability
// of the implementation to correctly unpack any received data.
//
// NOTE:
// - The caller of this method is free to overrides any values found in the headers.
// - The magic of unpack kibana errors is not done in the Send method, an helper methods is provided.
func (c *Client) Send(
ctx context.Context,
method, path string,
params url.Values,
headers http.Header,
body io.Reader,
) (*http.Response, error) {
c.log.Debugf("Request method: %s, path: %s", method, path)

req, err := c.request(method, path, params, body)
if err != nil {
return nil, errors.Wrapf(err, "fail to create HTTP request using method %s to %s", method, path)
}

// Add generals headers to the request, we are dealing exclusively with JSON.
// Content-Type / Accepted type can be override from the called.
req.Header.Set("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
req.Header.Set("kbn-xsrf", "1") // Without this Kibana will refuse to answer the request.

// copy headers.
for header, values := range headers {
for _, v := range values {
req.Header.Add(header, v)
}
}

return c.client.Do(req.WithContext(ctx))
}

// URI returns the remote URI.
func (c *Client) URI() string {
return string(c.config.Protocol) + "://" + c.config.Host + "/" + c.config.Path
}

func prefixRequestFactory(URL string) requestFunc {
return func(method, path string, params url.Values, body io.Reader) (*http.Request, error) {
path = strings.TrimPrefix(path, "/")
newPath := strings.Join([]string{URL, path, "?", params.Encode()}, "")
return http.NewRequest(method, newPath, body)
}
}

// makeTransport create a transport object based on the TLS configuration.
func makeTransport(timeout time.Duration, tls *tlscommon.Config) (*http.Transport, error) {
tlsConfig, err := tlscommon.LoadTLSConfig(tls)
if err != nil {
return nil, errors.Wrap(err, "invalid TLS configuration")
}
dialer := transport.NetDialer(timeout)
tlsDialer, err := transport.TLSDialer(dialer, tlsConfig, timeout)
if err != nil {
return nil, errors.Wrap(err, "fail to create TLS dialer")
}

// TODO: Dial is deprecated we need to move to DialContext.
return &http.Transport{Dial: dialer.Dial, DialTLS: tlsDialer.Dial}, nil
}
Loading