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

Use receivertest package to test beats receivers #41888

Open
mauri870 opened this issue Dec 4, 2024 · 2 comments
Open

Use receivertest package to test beats receivers #41888

mauri870 opened this issue Dec 4, 2024 · 2 comments
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@mauri870
Copy link
Member

mauri870 commented Dec 4, 2024

The open telemetry project has a receivertest module that can be used to test a receiver's contract. I'm particularly interested in the CheckConsumerContract function that is used to test the contract between the receiver and the next consumer in the pipeline.

This test has a couple of interesting scenarios such as:

  • Always succeed. We expect all data to be delivered as is.
  • Random non-permanent error
  • Random permanent error
  • Random error

This test is based on a Generator that is responsible to produce the data used during the test. For this to work properly the beats receiver must implement the ReceiveLogs(data plog.Logs) function to receive the logs from this external source. In the case of beats receivers, the beats themselves produce their own data, so we need to come up with a way to adapt this generator concept or implement said function. I believe the messages should be unique, so perhaps the benchmark input being able to output unique strings or an integer counter should be enough.

This seems quite handy to setup once and use the same machinery to test every beats receiver.

Here is an example test:

// TestConsumeContract is an example of testing of the receiver for the contract between the
// receiver and next consumer.
func TestConsumeContract(t *testing.T) {
	// Number of log records to send per scenario.
	const logsPerTest = 100

	generator := &exampleLogGenerator{t: t}
	cfg := &exampleReceiverConfig{generator: generator}

	params := CheckConsumeContractParams{
		T:             t,
		Factory:       newExampleFactory(),
		Signal:        pipeline.SignalLogs,
		Config:        cfg,
		Generator:     generator,
		GenerateCount: logsPerTest,
	}

	// Run the contract checker. This will trigger test failures if any problems are found.
	CheckConsumeContract(params)
}

During my initial experimentation with this I found a bug with global state in libbeat that is now resolved by #41475.

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 4, 2024
@mauri870 mauri870 added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team and removed needs_team Indicates that the issue/PR needs a Team:* label labels Dec 4, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

No branches or pull requests

2 participants