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

Several improvements to Elasticsearch.Ext.Logging #97

Merged
merged 5 commits into from
Aug 5, 2020

Conversation

Mpdreamz
Copy link
Member

  • Add some basic integration tests to assert the logs make it in the right index
  • Rename ElasticsearchDataProcessor to ElasticsearchDataShipper
  • Move enrichtment of LogEvent out of the shipper and into static helper class.
  • Rely on elasticsearch to generate ids
  • Move to PostData.StreamHandler to serialize directly to the IO stream.

relates: #95

@Mpdreamz Mpdreamz added enhancement New feature or request v1.6.0 labels Jul 16, 2020
@apmmachine
Copy link
Contributor

apmmachine commented Jul 16, 2020

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #97 updated]

  • Start Time: 2020-07-20T16:31:11.836+0000

  • Duration: 10 min 32 sec

Test stats 🧪

Test Results
Failed 0
Passed 52
Skipped 4
Total 56

- Add some basic integration tests to assert the logs make it in the right index
- Rename `ElasticsearchDataProcessor` to `ElasticsearchDataShipper`
- Move enrichtment of `LogEvent` out of the shipper and into static helper class.
- Rely on elasticsearch to generate ids
- Move to PostData.StreamHandler to serialize directly to the IO stream.
@Mpdreamz Mpdreamz force-pushed the feature/ext-logging-improvements branch from 7f5d9da to 5f49309 Compare July 16, 2020 15:23
Copy link
Contributor

@russcam russcam left a comment

Choose a reason for hiding this comment

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

I've had a look through and left some general comments

{
_outputThread.Join(1500); // with timeout in case writer is locked
}
catch (ThreadStateException) { }
Copy link
Contributor

Choose a reason for hiding this comment

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

is there an internal logger to which this exception can be written?

Copy link
Member Author

@Mpdreamz Mpdreamz Jul 21, 2020

Choose a reason for hiding this comment

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

I looked into fallback loggers in the Mic.Ext.Logging world but there is no such concept. The best we can do is expose callbacks to allow to user to log manually to fallback locations in their application configuration.

This is a carry over of #85 (introduced there not here) that is rewritten in #99 .

settings = new ConnectionConfiguration(nodes[0]);
else
{
settings = new ConnectionConfiguration(connectionPool);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like _options.ShipTo.CreateConnectionPool(); can return null:

internal IConnectionPool? CreateConnectionPool()
{
switch (ConnectionPoolType)
{
// TODO: Add option to randomize pool
case Logging.ConnectionPoolType.Unknown:
case Logging.ConnectionPoolType.Sniffing:
return new SniffingConnectionPool(NodeUris);
case Logging.ConnectionPoolType.Static:
return new StaticConnectionPool(NodeUris);
case Logging.ConnectionPoolType.Sticky:
return new StickyConnectionPool(NodeUris);
// case ConnectionPoolType.StickySniffing:
case Logging.ConnectionPoolType.Cloud:
if (!string.IsNullOrEmpty(ApiKey))
{
var apiKeyCredentials = new ApiKeyAuthenticationCredentials(ApiKey);
return new CloudConnectionPool(CloudId, apiKeyCredentials);
}
var basicAuthCredentials = new BasicAuthenticationCredentials(Username, Password);
return new CloudConnectionPool(CloudId, basicAuthCredentials);
default:
return null;
}
}

but ConnectionConfiguration does not guard against null:

https://github.com/elastic/elasticsearch-net/blob/f1ffbf260132eb83ea4e7950c1bcf19ef679ee6f/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs#L210

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!, this is a carry over from #98, will update the meta ticket #95 to follow up in a separate PR


var lowlevelClient = new ElasticLowLevelClient(settings);

_ = Interlocked.Exchange(ref _lowLevelClient, lowlevelClient);
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 struggling to see what benefit this provides over assigning to the field directly in this case, as the original value is not used and field assignment is atomic on all .NET platforms AFAIK. Is there a benefit that I'm missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is not, carry over from #85 we can address that in a follow up PR.

Comment on lines +94 to +105
try
{
foreach (var logEvent in _messageQueue.GetConsumingEnumerable()) PostEvent(logEvent);
}
catch
{
try
{
_messageQueue.CompleteAdding();
}
catch { }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand this correctly, an exception in posting the event will mark the blocking collection as no longer accepting items, causing any subsequent items to be sent to PostEvent directly in EnqueueMessage. Would we want to distinguish the types of exceptions that should cause this behaviour vs. those that shouldn't e.g. are there exceptions the client could throw where this behaviour is undesirable?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a carry over from #85 and is now rewritten to move away from BlockingCollection to Channels in #99

var index = string.Format(_options.Index, indexTime);

var localClient = _lowLevelClient;
var response = localClient.Index<StringResponse>(index,
Copy link
Contributor

Choose a reason for hiding this comment

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

I had a question about bulk, but see that this is addressed in #99 😄

logger.LogError("an error occured");

// TODO make sure we can await something here on ElasticsearchDataShipper
await Task.Delay(TimeSpan.FromSeconds(5));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the logger expose a property/event to ascertain that it has sent or is sending events?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my intend but I knew the shipper had to be rewritten so I left the TODO :)

Once #99 lands we can expose more callbacks and stats

@Mpdreamz
Copy link
Member Author

Thanks for the review @russcam I think most comments should be addressed in #99

Noted the need for CreateConnectionPool not to return null in the meta ticket so we can address this in a smaller dedicated PR.

@Mpdreamz Mpdreamz requested a review from russcam July 21, 2020 08:00
@Mpdreamz Mpdreamz merged commit 032ce01 into master Aug 5, 2020
@Mpdreamz Mpdreamz deleted the feature/ext-logging-improvements branch August 5, 2020 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v1.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants