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

Add Moxy tool to apm-perf #158

Merged
merged 1 commit into from
Sep 25, 2024
Merged

Add Moxy tool to apm-perf #158

merged 1 commit into from
Sep 25, 2024

Conversation

1pkg
Copy link
Member

@1pkg 1pkg commented Sep 18, 2024

This PR is a part of the work on the issue.
To introduce a new benchmarks mode in APM Server we need a tool that simulates ElasticSearch API (Moxy).

@1pkg 1pkg requested a review from a team as a code owner September 18, 2024 20:59
@rubvs
Copy link
Contributor

rubvs commented Sep 19, 2024

A general question for new code, specially smaller ones like this, wouldn't it be better to use the more minimal: https://pkg.go.dev/log/slog package?

@inge4pres
Copy link
Contributor

A general question for new code, specially smaller ones like this, wouldn't it be better to use the more minimal: https://pkg.go.dev/log/slog package?

That might work (not sure if the API is similar to zap) although the proposition here may be that a consistent logger across services makes it easier to parse/aggregate in the external components collecting and storing the data.

Copy link
Contributor

@inge4pres inge4pres left a comment

Choose a reason for hiding this comment

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

👍🏼

@1pkg 1pkg merged commit 499ba2a into main Sep 25, 2024
5 checks passed
payload io.Reader
headers http.Header
options []StubESOption
expectedCode int
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename this to expectedStatusCode

options := []proxy.StubESOption{
proxy.StubESWithLogger(logger),
}
if *username != "" && *password != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a mock. I'd set username and password to a default. Then maybe add an explicit check to ensure both are set. It makes no sense to continue of either are empty. Unless, you want to have auth optional which seems to be the case here. But this weird to me, since it is a mock:

if *username == "" {
  // fatal error
}
if *password == "" {
  // fatal error
}
options = append(options, proxy.StubESWithAuth(*username, *password))

If you want auth to be optional, maybe add a comment why? Maybe for performance testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Auth there is just for an extra check that nobody sends unsolicited traffic when it's exposed publicly, otherwise it's optional.

_, _ = w.Write(h.license)
return
case "/_bulk":
first := true
Copy link
Contributor

Choose a reason for hiding this comment

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

Move first := true to line 123.

}`
)

var memPool = sync.Pool{
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting use of sync pool with buffering. Maybe add a comment or a link to this trick?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm of the opinion to use []byte rather than bytes.Buffer. Either use sync.Pool or bytes.Buffer. Don't merge them:

  1. sync.Pool is already an abstraction. Use the lowest-level "primitive" which is []byte, rather than dealing with a higher-level abstraction like bytes.Buffer.
  2. With []byte you can simple reset the slice length. bytes.Buffer has more internal state to manage.
  3. bytes.Buffer is more efficient to stream data, like appending, since it avoids frequent reallocations. However, in pooling you'd rather want a static "container" that move in-and-out of the pool.
  4. You don't have need to use bytes.Buffer API and all the abstraction overhead that comes with it.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed separately bytes.Buffer and sync.Pool can compliment each other when reducing GC footprint for frequent allocations where the intermediate memory buffer size is unknown.

@rubvs rubvs deleted the add_moxy_tool branch September 27, 2024 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants