Skip to content

Commit

Permalink
add a discard output
Browse files Browse the repository at this point in the history
  • Loading branch information
leehinman committed Apr 10, 2024
1 parent 44cc349 commit e1f8943
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Add support for Active Directory an entity analytics provider. {pull}37919[37919]
- Add debugging breadcrumb to logs when writing request trace log. {pull}38636[38636]
- added benchmark input {pull}37437[37437]
- added benchmark input and discard output {pull}37437[37437]

*Auditbeat*

Expand Down
10 changes: 10 additions & 0 deletions libbeat/docs/outputs-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ endif::[]
ifndef::no_console_output[]
* <<console-output>>
endif::[]
ifndef::no_discard_output[]
* <<discard-output>>
endif::[]

//# end::outputs-list[]

Expand Down Expand Up @@ -77,6 +80,13 @@ endif::[]
include::{libbeat-outputs-dir}/console/docs/console.asciidoc[]
endif::[]

ifndef::no_discard_output[]
ifdef::requires_xpack[]
[role="xpack"]
endif::[]
include::{libbeat-outputs-dir}/discard/docs/discard.asciidoc[]
endif::[]

ifndef::no_codec[]
ifdef::requires_xpack[]
[role="xpack"]
Expand Down
30 changes: 30 additions & 0 deletions libbeat/outputs/discard/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 discard

import (
"github.com/elastic/elastic-agent-libs/config"
)

type discardOutConfig struct {
Queue config.Namespace `config:"queue"`
}

func defaultConfig() discardOutConfig {
return discardOutConfig{}
}
82 changes: 82 additions & 0 deletions libbeat/outputs/discard/discard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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 discard

import (
"context"

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/outputs"
"github.com/elastic/beats/v7/libbeat/publisher"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp"
)

func init() {
outputs.RegisterType("discard", makeDiscard)
}

type discardOutput struct {
log *logp.Logger
beat beat.Info
observer outputs.Observer
}

func makeDiscard(
_ outputs.IndexManager,
beat beat.Info,
observer outputs.Observer,
cfg *config.C,
) (outputs.Group, error) {
out := &discardOutput{
log: logp.NewLogger("discard"),
beat: beat,
observer: observer,
}
doConfig := defaultConfig()
if err := cfg.Unpack(&doConfig); err != nil {
return outputs.Fail(err)
}

// disable bulk support in publisher pipeline
_ = cfg.SetInt("bulk_max_size", -1, -1)
out.log.Infof("Initialized discard output")
return outputs.Success(doConfig.Queue, -1, 0, out)
}

// Implement Outputer
func (out *discardOutput) Close() error {
return nil
}

func (out *discardOutput) Publish(_ context.Context, batch publisher.Batch) error {
defer batch.ACK()

st := out.observer
events := batch.Events()
st.NewBatch(len(events))
for range events {
st.WriteError(nil)
}
st.Acked(len(events))
return nil
}

func (out *discardOutput) String() string {
return "discard"
}
34 changes: 34 additions & 0 deletions libbeat/outputs/discard/docs/discard.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[[discard-output]]
=== Configure the Discard output

++++
<titleabbrev>Discard</titleabbrev>
++++

The Discard output throws away data.

WARNING: The Discard output should be used only for development or
debugging issues. Data is lost.

This can be useful if you want to work on your input configuration
without needing to configure an output. It can also be useful to test
how changes in input and processor configuration affect performance.

Example configuration:

["source","yaml",subs="attributes"]
------------------------------------------------------------------------------
output.discard:
enabled: true
------------------------------------------------------------------------------

==== Configuration options

You can specify the following `output.discard` options in the +{beatname_lc}.yml+ config file:

===== `enabled`

The enabled config is a boolean setting to enable or disable the output. If set
to false, the output is disabled.

The default value is `true`.
1 change: 1 addition & 0 deletions libbeat/publisher/includes/includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
_ "github.com/elastic/beats/v7/libbeat/outputs/codec/format"
_ "github.com/elastic/beats/v7/libbeat/outputs/codec/json"
_ "github.com/elastic/beats/v7/libbeat/outputs/console"
_ "github.com/elastic/beats/v7/libbeat/outputs/discard"
_ "github.com/elastic/beats/v7/libbeat/outputs/elasticsearch"
_ "github.com/elastic/beats/v7/libbeat/outputs/fileout"
_ "github.com/elastic/beats/v7/libbeat/outputs/kafka"
Expand Down
6 changes: 3 additions & 3 deletions x-pack/filebeat/docs/inputs/input-benchmark.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
=== Benchmark input

++++
<titleabbrev>generic event generator</titleabbrev>
<titleabbrev>Benchmark</titleabbrev>
++++

beta[]

The benchmark input generates generic events and sends them to the output. This can be useful when you want to benchmark the difference between outputs or output settings.
The Benchmark input generates generic events and sends them to the output. This can be useful when you want to benchmark the difference between outputs or output settings.

Example configurations:

Expand Down Expand Up @@ -49,7 +49,7 @@ Send 5 events per second example:

==== Configuration options

The `benchmark` input supports the following configuration options plus the
The Benchmark input supports the following configuration options plus the
<<{beatname_lc}-input-{type}-common-options>> described later.

[float]
Expand Down

0 comments on commit e1f8943

Please sign in to comment.