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

Added serval release version to translation build #517

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ services:
'/bin/sh',
'-c',
'mongod --quiet --replSet myRS --bind_ip 0.0.0.0 & sleep 2s; mongosh --host localhost:27017 --eval '' config = { "_id" : "myRS", "members" : [{"_id" : 0,"host" : "mongo:27017"}] }; rs.initiate(config, { force: true }); '' ; sleep infinity'
]
]
6 changes: 6 additions & 0 deletions src/Serval/src/Serval.ApiServer/ServalSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Serval.ApiServer;

public class ServalSettings
{
public string ReleaseVersion { get; set; } = "1.0.0"; // Default value
}
1 change: 1 addition & 0 deletions src/Serval/src/Serval.ApiServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public void ConfigureServices(IServiceCollection services)
.AddOpenTelemetry()
.WithMetrics(opts => opts.AddAspNetCoreInstrumentation().AddPrometheusExporter());
}
services.Configure<Serval.Shared.Configuration.ServalSettings>(Configuration.GetSection("ServalSettings"));
services.Configure<Bugsnag.Configuration>(Configuration.GetSection("Bugsnag"));
services.AddBugsnag();
}
Expand Down
3 changes: 3 additions & 0 deletions src/Serval/src/Serval.ApiServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"LogLevel": {
"System.Net.Http.HttpClient": "Warning"
}
},
"ServalSettings": {
"ReleaseVersion": "1.0.0"
}
}
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 @@ -9816,6 +9816,9 @@ public partial class TranslationBuild
[Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public object? Options { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("servalReleaseVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? ServalReleaseVersion { 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
6 changes: 6 additions & 0 deletions src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Serval.Shared.Configuration;

public class ServalSettings
{
public string ReleaseVersion { get; set; } = "1.0.0"; // Default value
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public record TranslationBuildDto
/// }
/// </example>
public object? Options { get; init; }
public string? ServalReleaseVersion { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class TranslationEnginesController(
IPretranslationService pretranslationService,
IOptionsMonitor<ApiOptions> apiOptions,
IUrlService urlService,
ILogger<TranslationEnginesController> logger
ILogger<TranslationEnginesController> logger,
IOptions<ServalSettings> servalSettingsOptions
) : ServalControllerBase(authService)
{
private static readonly JsonSerializerOptions ObjectJsonSerializerOptions =
Expand All @@ -22,6 +23,7 @@ ILogger<TranslationEnginesController> logger
private readonly IOptionsMonitor<ApiOptions> _apiOptions = apiOptions;
private readonly IUrlService _urlService = urlService;
private readonly ILogger<TranslationEnginesController> _logger = logger;
private readonly ServalSettings _servalSettings = servalSettingsOptions.Value;

/// <summary>
/// Get all translation engines
Expand Down Expand Up @@ -1505,7 +1507,8 @@ private TranslationBuildDto Map(Build source)
QueueDepth = source.QueueDepth,
State = source.State,
DateFinished = source.DateFinished,
Options = source.Options
Options = source.Options,
ServalReleaseVersion = _servalSettings.ReleaseVersion
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Translation/Models/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public record Build : IEntity
public JobState State { get; init; } = JobState.Pending;
public DateTime? DateFinished { get; init; }
public IReadOnlyDictionary<string, object>? Options { get; init; }
public string? ServalReleaseVersion { get; set; }
}
29 changes: 29 additions & 0 deletions src/Serval/test/Serval.E2ETests/ServalApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@ public async Task GetEchoPretranslate()
Assert.That(pretranslations, Has.Count.GreaterThan(1));
}

[Test]
public async Task GetServalReleaseVersion()
{
string engineId = await _helperClient.CreateNewEngineAsync("Echo", "es", "es", "Echo2");
string[] books = ["1JN.txt", "2JN.txt"];
await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", false);
books = ["3JN.txt"];
string corpusId = await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", true);
await _helperClient.BuildEngineAsync(engineId);
IList<Pretranslation> pretranslations = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync(
engineId,
corpusId
);
Assert.That(pretranslations, Has.Count.GreaterThan(1));
TranslationBuild build = await _helperClient.TranslationEnginesClient.GetCurrentBuildAsync(engineId);
Assert.That(
build.ServalReleaseVersion,
Is.Not.Null.And.Not.Empty,
"Serval release version should not be null or empty."
);

var hasServalReleaseVersionProperty = typeof(TranslationBuild).GetProperty("ServalReleaseVersion") != null;
Assert.That(
hasServalReleaseVersionProperty,
Is.True,
"ServalReleaseVersion property should exist in the build."
);
}

[Test]
public async Task GetSmtTranslation()
{
Expand Down
Loading