-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce filter limits - Filters can include optional limits * Report progress at the start - Fixes progress not updating * Initial response validator - Verifies that the response does not contain an 'error' field * Include more examples of filters and limits * Perform validation outside time measurement * Add 'TracerValidator' - Responses can be stored into a new file * Document 'TracerValidator' - Disabled by default - Response tracing is ignored in dry mode * Make config help text more consistent * Capitalize * Change name of tracing to verbose * Update README.md * Use `-r|--responses` to store responses * Invert condition - Append if file exists - Create one if not * Make 'IJsonRpcValidator' take also request into consideration * Validate 'NewPayload' responses using custom strategy - 'TracerValidator' is no longer a decorator * Separate 'ResponseTracer' from Validator - Tracer should be independent - Add File and Null tracers - Simplify services setup * Validate and trace batch responses * Add TickSucceeded * Add temp sampleSize * Tick succeeded on batches too * Use 'CompleteReservoir' for sampling - Removes need for hack/magic numbers * Remove whitespace * Remove `IAuth` from `NullJsonRpcSubmitter` --------- Co-authored-by: Kamil Chodoła <43241881+kamilchodola@users.noreply.github.com> Co-authored-by: Kamil Chodoła <kamil@nethermind.io>
- Loading branch information
1 parent
1df2cf4
commit f3ed968
Showing
20 changed files
with
404 additions
and
49 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
45 changes: 45 additions & 0 deletions
45
tools/Nethermind.Tools.Kute/Extensions/CompleteReservoir.cs
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,45 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using App.Metrics; | ||
using App.Metrics.ReservoirSampling; | ||
using App.Metrics.ReservoirSampling.Uniform; | ||
|
||
namespace Nethermind.Tools.Kute.Extensions; | ||
|
||
public class CompleteReservoir : IReservoir | ||
{ | ||
private const int DefaultSize = 10_000; | ||
|
||
private readonly List<UserValueWrapper> _values; | ||
|
||
public CompleteReservoir() : this(DefaultSize) { } | ||
|
||
public CompleteReservoir(int size) | ||
{ | ||
_values = new List<UserValueWrapper>(size); | ||
} | ||
|
||
public IReservoirSnapshot GetSnapshot(bool resetReservoir) | ||
{ | ||
long count = _values.Count; | ||
double sum = _values.Sum(v => v.Value); | ||
IEnumerable<long> values = _values.Select(v => v.Value); | ||
|
||
if (resetReservoir) | ||
{ | ||
_values.Clear(); | ||
} | ||
|
||
return new UniformSnapshot(count, sum, values); | ||
} | ||
|
||
public IReservoirSnapshot GetSnapshot() => GetSnapshot(false); | ||
|
||
public void Reset() => _values.Clear(); | ||
|
||
public void Update(long value, string userValue) => _values.Add(new UserValueWrapper(value, userValue)); | ||
|
||
public void Update(long value) => _values.Add(new UserValueWrapper(value)); | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
tools/Nethermind.Tools.Kute/JsonRpcMethodFilter/LimitedJsonRpcMethodFilter.cs
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,33 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
namespace Nethermind.Tools.Kute.JsonRpcMethodFilter; | ||
|
||
class LimitedJsonRpcMethodFilter : IJsonRpcMethodFilter | ||
{ | ||
private readonly IJsonRpcMethodFilter _filter; | ||
|
||
private int _usagesLeft; | ||
|
||
public LimitedJsonRpcMethodFilter(IJsonRpcMethodFilter filter, int limit) | ||
{ | ||
_filter = filter; | ||
_usagesLeft = limit; | ||
} | ||
|
||
public bool ShouldSubmit(string methodName) | ||
{ | ||
if (_filter.ShouldSubmit(methodName)) | ||
{ | ||
if (_usagesLeft == 0) | ||
{ | ||
return false; | ||
} | ||
|
||
_usagesLeft--; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
19 changes: 13 additions & 6 deletions
19
tools/Nethermind.Tools.Kute/JsonRpcMethodFilter/PatternJsonRpcMethodFilter.cs
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 |
---|---|---|
@@ -1,18 +1,25 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Text.RegularExpressions; | ||
|
||
namespace Nethermind.Tools.Kute.JsonRpcMethodFilter; | ||
|
||
class PatternJsonRpcMethodFilter : IJsonRpcMethodFilter | ||
public class PatternJsonRpcMethodFilter : IJsonRpcMethodFilter | ||
{ | ||
private readonly Regex _pattern; | ||
private const char PatternSeparator = '='; | ||
|
||
private readonly IJsonRpcMethodFilter _filter; | ||
public PatternJsonRpcMethodFilter(string pattern) | ||
{ | ||
_pattern = new Regex(pattern); | ||
var splitted = pattern.Split(PatternSeparator); | ||
|
||
var regex = new RegexJsonRpcMethodFilter(splitted[0]); | ||
_filter = splitted.Length switch | ||
{ | ||
1 => regex, | ||
2 => new LimitedJsonRpcMethodFilter(regex, int.Parse(splitted[1])), | ||
_ => throw new ArgumentException($"Unexpected pattern: {pattern}"), | ||
}; | ||
} | ||
|
||
public bool ShouldSubmit(string methodName) => _pattern.IsMatch(methodName); | ||
public bool ShouldSubmit(string methodName) => _filter.ShouldSubmit(methodName); | ||
} |
18 changes: 18 additions & 0 deletions
18
tools/Nethermind.Tools.Kute/JsonRpcMethodFilter/RegexJsonRpcMethodFilter.cs
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,18 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Text.RegularExpressions; | ||
|
||
namespace Nethermind.Tools.Kute.JsonRpcMethodFilter; | ||
|
||
class RegexJsonRpcMethodFilter : IJsonRpcMethodFilter | ||
{ | ||
private readonly Regex _pattern; | ||
|
||
public RegexJsonRpcMethodFilter(string pattern) | ||
{ | ||
_pattern = new Regex(pattern); | ||
} | ||
|
||
public bool ShouldSubmit(string methodName) => _pattern.IsMatch(methodName); | ||
} |
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
4 changes: 3 additions & 1 deletion
4
tools/Nethermind.Tools.Kute/JsonRpcSubmitter/IJsonRpcSubmitter.cs
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Text.Json; | ||
|
||
namespace Nethermind.Tools.Kute.JsonRpcSubmitter; | ||
|
||
interface IJsonRpcSubmitter | ||
{ | ||
Task Submit(JsonRpc rpc); | ||
Task<JsonDocument?> Submit(JsonRpc rpc); | ||
} |
14 changes: 2 additions & 12 deletions
14
tools/Nethermind.Tools.Kute/JsonRpcSubmitter/NullJsonRpcSubmitter.cs
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 |
---|---|---|
@@ -1,22 +1,12 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Tools.Kute.Auth; | ||
using System.Text.Json; | ||
|
||
namespace Nethermind.Tools.Kute.JsonRpcSubmitter; | ||
|
||
class NullJsonRpcSubmitter : IJsonRpcSubmitter | ||
{ | ||
private readonly IAuth _auth; | ||
|
||
public NullJsonRpcSubmitter(IAuth auth) | ||
{ | ||
_auth = auth; | ||
} | ||
|
||
public Task Submit(JsonRpc rpc) | ||
{ | ||
_ = _auth.AuthToken; | ||
return Task.CompletedTask; | ||
} | ||
public Task<JsonDocument?> Submit(JsonRpc rpc) => Task.FromResult<JsonDocument?>(null); | ||
} |
18 changes: 18 additions & 0 deletions
18
tools/Nethermind.Tools.Kute/JsonRpcValidator/ComposedJsonRpcValidator.cs
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,18 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Text.Json; | ||
|
||
namespace Nethermind.Tools.Kute.JsonRpcValidator; | ||
|
||
public class ComposedJsonRpcValidator : IJsonRpcValidator | ||
{ | ||
private readonly IEnumerable<IJsonRpcValidator> _validators; | ||
|
||
public ComposedJsonRpcValidator(IEnumerable<IJsonRpcValidator> validators) | ||
{ | ||
_validators = validators; | ||
} | ||
|
||
public bool IsValid(JsonRpc request, JsonDocument? document) => _validators.All(validator => validator.IsValid(request, document)); | ||
} |
Oops, something went wrong.