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

Test command #4590

Merged
merged 6 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha2...master[Check the HEAD d
- Rename `*.full.yml` config files to `*.reference.yml`. {pull}4563[4563]
- The `scripts/import_dashboards` is removed from packages. Use the `setup` command instead. {pull}4586[4586]
- Change format of the saved kibana dashboards to have a single JSON file for each dashboard {pull}4413[4413]
- Rename `configtest` command to `test config`. {pull}4590[4590]

*Filebeat*

Expand Down Expand Up @@ -67,6 +68,7 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha2...master[Check the HEAD d
- Allow source path matching in `add_docker_metadata` processor. {pull}4495[4495]
- Add support for analyzers and multifields in fields.yml. {pull}4574[4574]
- Add support for JSON logging. {pull}4523[4523]
- Add `test output` command, to test Elasticsearch and Logstash output settings. {pull}4590[4590]

*Filebeat*

Expand Down
72 changes: 72 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,34 @@ License type (autodetected): Apache License 2.0
Apache License 2.0


--------------------------------------------------------------------
Dependency: github.com/fatih/color
Version: v1.5.0
Revision: 570b54cabe6b8eb0bc2dfce68d964677d63b5260
License type (autodetected): MIT license
./vendor/github.com/fatih/color/LICENSE.md:
--------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2013 Fatih Arslan

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------
Dependency: github.com/fsnotify/fsevents
Revision: 3ceee05210c3babaa38cdc9181dabdcc83076a44
Expand Down Expand Up @@ -1621,6 +1649,50 @@ The above copyright notice and this permission notice shall be included in all c

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------
Dependency: github.com/mattn/go-colorable
Revision: 941b50ebc6efddf4c41c8e4537a5f68a4e686b24
License type (autodetected): MIT license
./vendor/github.com/mattn/go-colorable/LICENSE:
--------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2016 Yasuhiro Matsumoto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--------------------------------------------------------------------
Dependency: github.com/mattn/go-isatty
Revision: fc9e8d8ef48496124e79ae0df75490096eccf6fe
License type (autodetected): MIT license
./vendor/github.com/mattn/go-isatty/LICENSE:
--------------------------------------------------------------------
Copyright (c) Yasuhiro MATSUMOTO <[email protected]>

MIT License (Expat)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------
Dependency: github.com/matttproud/golang_protobuf_extensions
Revision: c12348ce28de40eed0136aa2b644d0ee0650e56c
Expand Down
2 changes: 1 addition & 1 deletion filebeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {

RootCmd = cmd.GenRootCmdWithRunFlags(Name, "", beater.New, runFlags)
RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("M"))
RootCmd.ConfigTestCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules"))
RootCmd.TestCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules"))
RootCmd.SetupCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules"))
RootCmd.AddCommand(cmd.GenModulesCmd(Name, "", buildModulesManager))
}
6 changes: 3 additions & 3 deletions libbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type BeatsRootCmd struct {
RunCmd *cobra.Command
SetupCmd *cobra.Command
VersionCmd *cobra.Command
ConfigTestCmd *cobra.Command
CompletionCmd *cobra.Command
ExportCmd *cobra.Command
TestCmd *cobra.Command
}

// GenRootCmd returns the root command to use for your beat. It takes
Expand All @@ -50,9 +50,9 @@ func GenRootCmdWithRunFlags(name, version string, beatCreator beat.Creator, runF
rootCmd.RunCmd = genRunCmd(name, version, beatCreator, runFlags)
rootCmd.SetupCmd = genSetupCmd(name, version, beatCreator)
rootCmd.VersionCmd = genVersionCmd(name, version)
rootCmd.ConfigTestCmd = genConfigTestCmd(name, version, beatCreator)
rootCmd.CompletionCmd = genCompletionCmd(name, version, rootCmd)
rootCmd.ExportCmd = genExportCmd(name, version, beatCreator)
rootCmd.TestCmd = genTestCmd(name, version, beatCreator)

// Root command is an alias for run
rootCmd.Run = rootCmd.RunCmd.Run
Expand All @@ -77,9 +77,9 @@ func GenRootCmdWithRunFlags(name, version string, beatCreator beat.Creator, runF
rootCmd.AddCommand(rootCmd.RunCmd)
rootCmd.AddCommand(rootCmd.SetupCmd)
rootCmd.AddCommand(rootCmd.VersionCmd)
rootCmd.AddCommand(rootCmd.ConfigTestCmd)
rootCmd.AddCommand(rootCmd.CompletionCmd)
rootCmd.AddCommand(rootCmd.ExportCmd)
rootCmd.AddCommand(rootCmd.TestCmd)

return rootCmd
}
20 changes: 20 additions & 0 deletions libbeat/cmd/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/cmd/test"
)

func genTestCmd(name, beatVersion string, beatCreator beat.Creator) *cobra.Command {
exportCmd := &cobra.Command{
Use: "test",
Short: "Test config",
}

exportCmd.AddCommand(test.GenTestConfigCmd(name, beatVersion, beatCreator))
exportCmd.AddCommand(test.GenTestOutputCmd(name, beatVersion))

return exportCmd
}
6 changes: 3 additions & 3 deletions libbeat/cmd/configtest.go → libbeat/cmd/test/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package test

import (
"fmt"
Expand All @@ -9,9 +9,9 @@ import (
"github.com/elastic/beats/libbeat/beat"
)

func genConfigTestCmd(name, version string, beatCreator beat.Creator) *cobra.Command {
func GenTestConfigCmd(name, version string, beatCreator beat.Creator) *cobra.Command {
configTestCmd := cobra.Command{
Use: "configtest",
Use: "config",
Short: "Test configuration settings",
Run: func(cmd *cobra.Command, args []string) {
b, err := beat.New(name, version)
Expand Down
49 changes: 49 additions & 0 deletions libbeat/cmd/test/output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package test

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/testing"
)

func GenTestOutputCmd(name, beatVersion string) *cobra.Command {
return &cobra.Command{
Use: "output",
Short: "Test output works with current settings",
Run: func(cmd *cobra.Command, args []string) {
b, err := beat.New(name, beatVersion)
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
}

err = b.Init()
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
}

output, err := outputs.Load(b.Info, b.Config.Output.Name(), b.Config.Output.Config())
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing output: %s\n", err)
os.Exit(1)
}

for _, client := range output.Clients {
tClient, ok := client.(testing.Testable)
if !ok {
fmt.Printf("%s output doesn't support testing\n", b.Config.Output.Name())
os.Exit(1)
}

// Perform test:
tClient.Test(testing.NewConsoleDriver(os.Stdout))
}
},
}
}
5 changes: 5 additions & 0 deletions libbeat/monitoring/report/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/elastic/beats/libbeat/common"
esout "github.com/elastic/beats/libbeat/outputs/elasticsearch"
"github.com/elastic/beats/libbeat/publisher"
"github.com/elastic/beats/libbeat/testing"
)

type publishClient struct {
Expand Down Expand Up @@ -94,3 +95,7 @@ func (c *publishClient) Publish(batch publisher.Batch) error {
batch.ACK()
return err
}

func (c *publishClient) Test(d testing.Driver) {
c.es.Test(d)
}
11 changes: 11 additions & 0 deletions libbeat/outputs/backoff.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package outputs

import (
"errors"
"time"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/publisher"
"github.com/elastic/beats/libbeat/testing"
)

type backoffClient struct {
Expand Down Expand Up @@ -49,3 +51,12 @@ func (b *backoffClient) Publish(batch publisher.Batch) error {
func (b *backoffClient) Client() NetworkClient {
return b.client
}

func (b *backoffClient) Test(d testing.Driver) {
c, ok := b.client.(testing.Testable)
if !ok {
d.Fatal("output", errors.New("client doesn't support testing"))
}

c.Test(d)
}
33 changes: 33 additions & 0 deletions libbeat/outputs/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/elastic/beats/libbeat/outputs/transport"
"github.com/elastic/beats/libbeat/publisher"
"github.com/elastic/beats/libbeat/publisher/beat"
"github.com/elastic/beats/libbeat/testing"
)

// Client is an elasticsearch client.
Expand Down Expand Up @@ -577,6 +578,38 @@ func (client *Client) GetVersion() string {
return client.Connection.version
}

func (client *Client) Test(d testing.Driver) {
d.Run("elasticsearch: "+client.URL, func(d testing.Driver) {
u, err := url.Parse(client.URL)
d.Fatal("parse url", err)

address := u.Hostname()
if u.Port() != "" {
address += ":" + u.Port()
}
d.Run("connection", func(d testing.Driver) {
netDialer := transport.TestNetDialer(d, client.timeout)
_, err = netDialer.Dial("tcp", address)
d.Fatal("dial up", err)
})

if u.Scheme != "https" {
d.Warn("TLS", "secure connection disabled")
} else {
d.Run("TLS", func(d testing.Driver) {
netDialer := transport.NetDialer(client.timeout)
tlsDialer, err := transport.TestTLSDialer(d, netDialer, client.tlsConfig, client.timeout)
_, err = tlsDialer.Dial("tcp", address)
d.Fatal("dial up", err)
})
}

err = client.Connect()
d.Fatal("talk to server", err)
d.Info("version", client.version)
})
}

// Connect connects the client.
func (conn *Connection) Connect() error {
var err error
Expand Down
14 changes: 14 additions & 0 deletions libbeat/outputs/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package outputs

import (
"errors"
"fmt"
"math/rand"

"github.com/elastic/beats/libbeat/publisher"
"github.com/elastic/beats/libbeat/testing"
)

type failoverClient struct {
Expand Down Expand Up @@ -78,3 +80,15 @@ func (f *failoverClient) Publish(batch publisher.Batch) error {
}
return f.clients[f.active].Publish(batch)
}

func (f *failoverClient) Test(d testing.Driver) {
for i, client := range f.clients {
c, ok := client.(testing.Testable)
d.Run(fmt.Sprintf("Client %d", i), func(d testing.Driver) {
if !ok {
d.Fatal("output", errors.New("client doesn't support testing"))
}
c.Test(d)
})
}
}
Loading