Skip to content

Add metadata header on requests #5190

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

Merged
merged 9 commits into from
Jan 6, 2021
Merged

Add metadata header on requests #5190

merged 9 commits into from
Jan 6, 2021

Conversation

stevejgordon
Copy link
Contributor

@stevejgordon stevejgordon commented Dec 17, 2020

Adds a x-elastic-client-meta header to HTTP requests sent by Elasticsearch.NET. This header contains information about the runtime environment that is meant to allow analysing usage by collecting this information on the receiving side of requests, like a proxy server in front of ES.

The information in this header has been specified by the clients team to be consistent across language clients. It contains the versions of the client, the language runtime (.NET in this case) and its HTTP library, and the use of the high level client.

This header is sent by default and can be disabled by setting DisableMetaHeader on the ConnectionSettings passed to the client.

There is a little more work to do on this PR after an initial review of the approaches taken.

Remaining tasks:

  • Update configuration documentation
  • Add additional tests
  • Final QA against different runtimes
  • Review/update XML comments
  • Manual porting to Elastic.Transport and master as appropriate

@stevejgordon
Copy link
Contributor Author

@Mpdreamz I've refactored this a fair bit taking your suggestions onboard. I'm happier with this approach now. Would welcome a check to see if it matches what you were thinking?

@Mpdreamz
Copy link
Member

Aye much cleaner!

I am still unsure if we need:

private readonly List<IHeaderProvider> _customerHeaderProviders = new List<IHeaderProvider> { new MetaHeaderProvider() };

And IHeaderProvider since the instance we plan to maintain for the foreseeable future is the one producing: x-elastic-client-meta".

For users wanting to inject we already have .Headers on ConnectionSettings and RequestConfiguration.

SyncMetaDataHeader = new MetaDataHeader(clientVersionInfo, "es", false);
}

public MetaDataHeader AsyncMetaDataHeader { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public MetaDataHeader AsyncMetaDataHeader { get; private set; }
public MetaDataHeader AsyncMetaDataHeader { get; }

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a good first record ? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it could be. I want to read up on using records for older targets since I believe we may need to include code for a couple of attributes which may be required for them to work after compilation.


namespace Elasticsearch.Net
{
internal sealed class MetaDataHeaders : IMetaDataHeaders
Copy link
Member

Choose a reason for hiding this comment

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

both internal and sealed are used very sparingly. Siding on the side of being public by default has some benefits.

Not sure we need IMetaDataHeaders if this class is public? It also allows us to unit test this in isolation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, I think I probably agree 😄. I tend to lean the other way, internal and sealed until they need to be since we can change them freely without breaking changes to consumers. But when I've done that in other libs, it can cause some headaches for testing. Here, I think loosing the interface is better.

Copy link
Contributor Author

@stevejgordon stevejgordon Jan 5, 2021

Choose a reason for hiding this comment

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

@Mpdreamz In the latest update to this PR I've been able to avoid exposing this on the configuration entirely and been able to move its logic into the provider directly.

Add tests to ensure that observables make requests with the expected
request meta data helper value, including the reindex helper with calls
other helpers.

These tests also highlight two errors in the snapshot and restore
observable which have been fixed.
@stevejgordon
Copy link
Contributor Author

@Mpdreamz I think we're ready for a final review on this please. I've refactored and simplified this further on the basis of YAGNI.

I also added MetaHeaderHelperTests which uses a custom InMemoryConnection to simulate responses necessary to fully exercise the observables. This is mainly to support verification of expected helper on the RequestMetaHeader but has the nice side effect of exercising the flow of requests in general.

@stevejgordon stevejgordon requested a review from Mpdreamz January 6, 2021 11:06
Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

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

LGTM

@stevejgordon stevejgordon merged commit fec16ef into 7.11 Jan 6, 2021
@stevejgordon stevejgordon deleted the feature/meta-header branch January 6, 2021 14:09
github-actions bot pushed a commit that referenced this pull request Jan 6, 2021
Implement meta header for client requests
stevejgordon added a commit that referenced this pull request Jan 7, 2021
Implement meta header for client requests

Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
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.

2 participants