-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
70 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
src/Elastic.Transport/Diagnostics/Auditing/AuditEventExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Elastic.Transport.Extensions; | ||
|
||
namespace Elastic.Transport.Diagnostics.Auditing; | ||
|
||
/// Collects <see cref="Audit"/> events | ||
public class Auditor : IReadOnlyCollection<Audit> | ||
{ | ||
private readonly DateTimeProvider _dateTimeProvider; | ||
private List<Audit>? _audits; | ||
|
||
internal Auditor(DateTimeProvider dateTimeProvider) => _dateTimeProvider = dateTimeProvider; | ||
|
||
/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/> | ||
public IEnumerator<Audit> GetEnumerator() => | ||
_audits?.GetEnumerator() ?? (IEnumerator<Audit>)new EmptyEnumerator<Audit>(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
||
internal Auditable Add(Auditable auditable) | ||
{ | ||
_audits ??= new List<Audit>(); | ||
_audits.Add(auditable.Audit); | ||
return auditable; | ||
} | ||
|
||
internal Auditable Add(AuditEvent type, DateTimeProvider dateTimeProvider, Node? node = null) | ||
{ | ||
_audits ??= new List<Audit>(); | ||
var auditable = new Auditable(type, dateTimeProvider, node); | ||
_audits.Add(auditable.Audit); | ||
return auditable; | ||
} | ||
|
||
/// Emits an event that does not need to track a duration | ||
public void Emit(AuditEvent type) => Add(type, _dateTimeProvider).Dispose(); | ||
|
||
/// Emits an event that does not need to track a duration | ||
public void Emit(AuditEvent type, Node node) => Add(type, _dateTimeProvider, node).Dispose(); | ||
|
||
/// <inheritdoc cref="IReadOnlyCollection{T}.Count"/> | ||
public int Count => _audits?.Count ?? 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters