Repository navigation
Include ref.parent matches in events by-reference navigation
#2280
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
Open
Copilot
wants to merge
19
commits into
main
Choose a base branch
from
copilot/fix-parent-url-navigation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+692
−33
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
46c440c
fix(events): include parent references in by-ref navigation
Copilot cdf1f6d
test(http): cover event by-reference routes
niemyjski 22d506f
fix(events): keep parent navigation available on free plans
niemyjski 18b9d65
fix(events): index parent references for free plans
niemyjski ded4306
fix(events): validate and align reference filters
niemyjski b6e9cec
fix(events): backfill retained parent references
niemyjski ba02eb1
fix(events): align free parent reference navigation
niemyjski 00db448
fix(events): preserve legacy references and migration safety
niemyjski da31aeb
fix(events): backfill cased parent references
niemyjski 900e9a0
fix(events): report truncated reference results
niemyjski 3c3ad74
fix(events): recognize reference field names
niemyjski f217dc0
fix(migrations): assign parent backfill version 6
niemyjski ad2c754
fix(events): match built-in references case-insensitively
niemyjski a2da68b
fix(events): align reference name validation
niemyjski a91445f
Fix parent reference normalization and migration ordering
niemyjski f813f07
Keep parent backfill registration coverage stable
niemyjski 709d378
Merge remote-tracking branch 'origin/main' into HEAD
niemyjski 102a487
Handle legacy parent reference values in event filters
niemyjski d75bddc
Merge main into parent-reference navigation fix
niemyjski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
118 changes: 118 additions & 0 deletions
118
src/Exceptionless.Core/Migrations/010_BackfillParentReferences.cs
This file contains hidden or 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,118 @@ | ||
| using System.Diagnostics; | ||
| using System.Text.Json; | ||
| using Elastic.Clients.Elasticsearch; | ||
| using Elastic.Clients.Elasticsearch.Tasks; | ||
| using Exceptionless.Core.Models; | ||
| using Exceptionless.Core.Repositories.Configuration; | ||
| using Foundatio.Repositories.Elasticsearch.Extensions; | ||
| using Foundatio.Repositories.Migrations; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Exceptionless.Core.Migrations; | ||
|
|
||
| public sealed class BackfillParentReferences : MigrationBase | ||
| { | ||
| private readonly ElasticsearchClient _client; | ||
| private readonly ExceptionlessElasticConfiguration _config; | ||
| private readonly TimeProvider _timeProvider; | ||
|
|
||
| public BackfillParentReferences(ExceptionlessElasticConfiguration configuration, TimeProvider timeProvider, ILoggerFactory loggerFactory) : base(loggerFactory) | ||
| { | ||
| _config = configuration; | ||
| _client = configuration.Client; | ||
| _timeProvider = timeProvider; | ||
|
|
||
| MigrationType = MigrationType.VersionedAndResumable; | ||
| Version = 10; | ||
| } | ||
|
|
||
| public override async Task RunAsync(MigrationContext context) | ||
| { | ||
| string referenceKey = $"@ref:{Event.KnownReferenceNames.Parent}"; | ||
| string indexKey = $"{Event.KnownReferenceNames.Parent}-r"; | ||
| // Painless trim() only handles ASCII whitespace; match CopyDataToIndex's String.Trim(). | ||
| string whitespace = String.Concat(Enumerable.Range(Char.MinValue, Char.MaxValue + 1) | ||
| .Select(value => (char)value).Where(Char.IsWhiteSpace)); | ||
| string script = $$""" | ||
| def parentReference = null; | ||
| if (ctx._source.data != null) { | ||
| for (def entry : ctx._source.data.entrySet()) { | ||
| String key = entry.getKey(); | ||
| int start = 0; | ||
| int end = key.length(); | ||
| while (start < end && params.whitespace.indexOf(key.substring(start, start + 1)) >= 0) start++; | ||
| while (end > start && params.whitespace.indexOf(key.substring(end - 1, end)) >= 0) end--; | ||
| if (key.substring(start, end).equalsIgnoreCase('{{referenceKey}}')) { | ||
| parentReference = entry.getValue(); | ||
| } | ||
| } | ||
| } | ||
| if (parentReference != null) { | ||
| if (ctx._source.idx == null) ctx._source.idx = [:]; | ||
| ctx._source.idx['{{indexKey}}'] = parentReference.toString(); | ||
| } else { | ||
| ctx.op = 'noop'; | ||
| } | ||
| """; | ||
|
|
||
| _logger.LogInformation("Backfilling retained event parent references"); | ||
| var stopwatch = Stopwatch.StartNew(); | ||
| var response = await _client.UpdateByQueryAsync<PersistentEvent>(request => request | ||
| .Indices($"{_config.Events.VersionedName}-*") | ||
| .Query(query => query.Bool(filter => filter.MustNot(mustNot => mustNot.Exists(exists => exists.Field($"idx.{indexKey}"))))) | ||
| .Script(value => value.Source(script).Lang(ScriptLanguage.Painless) | ||
| .Params(new Dictionary<string, object> { ["whitespace"] = whitespace })) | ||
| .WaitForCompletion(false), context.CancellationToken); | ||
| _logger.LogRequest(response, LogLevel.Information); | ||
|
|
||
| if (!response.IsValidResponse || response.Task is null) | ||
| throw new ApplicationException($"Unable to start parent-reference backfill: {response.DebugInformation}"); | ||
|
|
||
| int attempts = 0; | ||
| while (!context.CancellationToken.IsCancellationRequested) | ||
| { | ||
| var taskStatus = await _client.Tasks.GetAsync(response.Task.FullyQualifiedId, context.CancellationToken); | ||
| if (!taskStatus.IsValidResponse) | ||
| throw new ApplicationException($"Unable to monitor parent-reference backfill: {taskStatus.DebugInformation}"); | ||
|
|
||
| if (taskStatus.Completed) | ||
| { | ||
| EnsureTaskSucceeded(taskStatus); | ||
| _logger.LogInformation("Finished parent-reference backfill: Duration={Duration}", stopwatch.Elapsed); | ||
| return; | ||
| } | ||
|
|
||
| attempts++; | ||
| await context.Lock.RenewAsync(); | ||
| await Task.Delay(TimeSpan.FromSeconds(attempts <= 5 ? 1 : 5), _timeProvider, context.CancellationToken); | ||
| } | ||
|
|
||
| context.CancellationToken.ThrowIfCancellationRequested(); | ||
| } | ||
|
|
||
| internal static void EnsureTaskSucceeded(GetTasksResponse taskStatus) | ||
| { | ||
| if (taskStatus.Error is not null) | ||
| throw new ApplicationException($"Parent-reference backfill failed: {JsonSerializer.Serialize(taskStatus.Error)}"); | ||
|
|
||
| if (taskStatus.Response is null) | ||
| return; | ||
|
|
||
| JsonElement response = JsonSerializer.SerializeToElement(taskStatus.Response); | ||
| if (response.ValueKind == JsonValueKind.Object | ||
| && response.TryGetProperty("version_conflicts", out var versionConflicts) | ||
| && versionConflicts.TryGetInt64(out long conflictCount) | ||
| && conflictCount > 0) | ||
| { | ||
| throw new ApplicationException($"Parent-reference backfill failed with {conflictCount} version conflicts."); | ||
| } | ||
|
|
||
| if (response.ValueKind == JsonValueKind.Object | ||
| && response.TryGetProperty("failures", out var failures) | ||
| && failures.ValueKind == JsonValueKind.Array | ||
| && failures.GetArrayLength() > 0) | ||
| { | ||
| throw new ApplicationException($"Parent-reference backfill failed: {failures}"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.