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

Build summary gprc #541

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
937c563
Added serval release version to translation build
mudiagaobrikisil Oct 18, 2024
7b1172a
Merge branch 'main' into add_serval_release_version
mudiagaobrikisil Oct 18, 2024
edf45ea
Made requested changes
mudiagaobrikisil Oct 21, 2024
346e116
Merge remote-tracking branch 'origin/add_serval_release_version' into…
mudiagaobrikisil Oct 21, 2024
00a6d3f
Fixed constructor issue
mudiagaobrikisil Oct 21, 2024
2cc125b
Used deployment version
mudiagaobrikisil Oct 23, 2024
f8485d3
Checking if test will pass
mudiagaobrikisil Oct 23, 2024
3ca47ac
Modification to use deployment version properly
mudiagaobrikisil Oct 23, 2024
678f03a
Made edits to the PR
mudiagaobrikisil Oct 24, 2024
56bd93f
Removed commented code
mudiagaobrikisil Oct 24, 2024
80682ba
refactored code to reflect suggestions
mudiagaobrikisil Oct 25, 2024
de7f91e
Working on GRPC
mudiagaobrikisil Nov 1, 2024
a6fff2f
Added summary
mudiagaobrikisil Nov 17, 2024
2b91842
Merge branch 'main' into build_summary_gprc
mudiagaobrikisil Nov 18, 2024
0812665
Initialized statistics to an empty array and made resulting changes
mudiagaobrikisil Nov 26, 2024
40084eb
Merge branch 'main' into build_summary_gprc
mudiagaobrikisil Nov 26, 2024
3cb8e1f
Updated PR and changed Statistics to ExecutionData
mudiagaobrikisil Nov 28, 2024
2d79791
Merge branch 'main' into build_summary_gprc
mudiagaobrikisil Nov 28, 2024
3dcedf4
removed camel case in proto file
mudiagaobrikisil Dec 2, 2024
9e18ec5
Merge remote-tracking branch 'origin/build_summary_gprc' into build_s…
mudiagaobrikisil Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ Task InsertPretranslationsAsync(
Stream pretranslationsStream,
CancellationToken cancellationToken = default
);

Task UpdateBuildExecutionDataAsync(
string engineId,
string buildId,
IReadOnlyDictionary<string, string> executionData,
CancellationToken cancellationToken = default
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ CancellationToken cancellationToken
);
}

var executionData = new Dictionary<string, string>()
{
{ "trainCount", trainCount.ToString(CultureInfo.InvariantCulture) },
{ "pretranslateCount", pretranslateCount.ToString(CultureInfo.InvariantCulture) }
};
await PlatformService.UpdateBuildExecutionDataAsync(engineId, buildId, executionData, cancellationToken);

cancellationToken.ThrowIfCancellationRequested();

bool canceling = !await BuildJobService.StartBuildJobAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public static class ServalPlatformOutboxConstants
public const string BuildRestarting = "BuildRestarting";
public const string InsertPretranslations = "InsertPretranslations";
public const string IncrementTranslationEngineCorpusSize = "IncrementTranslationEngineCorpusSize";
public const string UpdateBuildExecutionData = "UpdateBuildExecutionData";
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ await _client.IncrementTranslationEngineCorpusSizeAsync(
cancellationToken: cancellationToken
);
break;
case ServalPlatformOutboxConstants.UpdateBuildExecutionData:
await _client.UpdateBuildExecutionDataAsync(
JsonSerializer.Deserialize<UpdateBuildExecutionDataRequest>(content!),
cancellationToken: cancellationToken
);
break;
default:
throw new InvalidOperationException($"Encountered a message with the unrecognized method '{method}'.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,22 @@ await _outboxService.EnqueueMessageAsync(
cancellationToken: cancellationToken
);
}

public async Task UpdateBuildExecutionDataAsync(
string engineId,
string buildId,
IReadOnlyDictionary<string, string> executionData,
CancellationToken cancellationToken = default
)
{
var request = new UpdateBuildExecutionDataRequest { EngineId = engineId, BuildId = buildId };
request.ExecutionData.Add((IDictionary<string, string>)executionData);
await _outboxService.EnqueueMessageAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.UpdateBuildExecutionData,
engineId,
JsonSerializer.Serialize(request),
cancellationToken: cancellationToken
);
}
}
3 changes: 3 additions & 0 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9849,6 +9849,9 @@ public partial class TranslationBuild
[Newtonsoft.Json.JsonProperty("deploymentVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? DeploymentVersion { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("executionData", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IDictionary<string, string>? ExecutionData { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ service TranslationPlatformApi {

rpc IncrementTranslationEngineCorpusSize(IncrementTranslationEngineCorpusSizeRequest) returns (google.protobuf.Empty);
rpc InsertPretranslations(stream InsertPretranslationsRequest) returns (google.protobuf.Empty);
rpc UpdateBuildExecutionData(UpdateBuildExecutionDataRequest) returns (google.protobuf.Empty);
}

message UpdateBuildStatusRequest {
Expand Down Expand Up @@ -59,3 +60,9 @@ message InsertPretranslationsRequest {
repeated string refs = 4;
string translation = 5;
}

message UpdateBuildExecutionDataRequest {
string engine_id = 1;
string build_id = 2;
map<string, string> execution_data = 3;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Translation.Contracts;
namespace Serval.Translation.Contracts;

public record TranslationBuildDto
{
Expand Down Expand Up @@ -28,4 +28,5 @@ public record TranslationBuildDto
/// </example>
public object? Options { get; init; }
public string? DeploymentVersion { get; init; }
public IReadOnlyDictionary<string, string>? ExecutionData { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Translation.Controllers;
namespace Serval.Translation.Controllers;

#pragma warning disable CS0612 // Type or member is obsolete

Expand Down Expand Up @@ -1547,7 +1547,8 @@ private TranslationBuildDto Map(Build source)
State = source.State,
DateFinished = source.DateFinished,
Options = source.Options,
DeploymentVersion = source.DeploymentVersion
DeploymentVersion = source.DeploymentVersion,
ExecutionData = source.ExecutionData
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/Serval/src/Serval.Translation/Models/Build.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Translation.Models;
namespace Serval.Translation.Models;

public record Build : IEntity
{
Expand All @@ -13,7 +13,9 @@ public record Build : IEntity
public string? Message { get; init; }
public int? QueueDepth { get; init; }
public JobState State { get; init; } = JobState.Pending;
public DateTime DateCreated { get; init; } = DateTime.UtcNow;
public DateTime? DateFinished { get; init; }
public IReadOnlyDictionary<string, object>? Options { get; init; }
public string? DeploymentVersion { get; init; }
public IReadOnlyDictionary<string, string> ExecutionData { get; init; } = new Dictionary<string, string>();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Google.Protobuf.WellKnownTypes;
using System.Collections.ObjectModel;
using Google.Protobuf.WellKnownTypes;
using Serval.Translation.V1;

namespace Serval.Translation.Services;
Expand Down Expand Up @@ -98,7 +99,7 @@ await _publishEndpoint.Publish(
Owner = engine.Owner,
BuildState = build.State,
Message = build.Message!,
DateFinished = build.DateFinished!.Value
DateFinished = build.DateFinished!.Value,
},
ct
);
Expand Down Expand Up @@ -265,6 +266,33 @@ await _builds.UpdateAsync(
return Empty;
}

public override async Task<Empty> UpdateBuildExecutionData(
UpdateBuildExecutionDataRequest request,
ServerCallContext context
)
{
var build = await _builds.GetAsync(request.BuildId, cancellationToken: context.CancellationToken);
if (build == null)
{
throw new RpcException(new Status(StatusCode.NotFound, "Build not found."));
}

var updatedExecutionData = new Dictionary<string, string>(build.ExecutionData);

foreach (var entry in request.ExecutionData)
{
updatedExecutionData[entry.Key] = entry.Value;
}

await _builds.UpdateAsync(
b => b.Id == request.BuildId,
u => u.Set(b => b.ExecutionData, new ReadOnlyDictionary<string, string>(updatedExecutionData)),
cancellationToken: context.CancellationToken
);

return new Empty();
}

public override async Task<Empty> IncrementTranslationEngineCorpusSize(
IncrementTranslationEngineCorpusSizeRequest request,
ServerCallContext context
Expand Down
6 changes: 6 additions & 0 deletions src/Serval/test/Serval.E2ETests/ServalApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public async Task NmtBatch()
engineId,
cId2
);

TranslationBuild build = await _helperClient.TranslationEnginesClient.GetCurrentBuildAsync(engineId);
Assert.That(build.ExecutionData, Is.Not.Null);
Assert.That(build.ExecutionData, Contains.Key("trainCount"));
Assert.That(build.ExecutionData, Contains.Key("pretranslateCount"));

Assert.That(lTrans2, Has.Count.EqualTo(13)); // just 2 John
}

Expand Down
Loading