Skip to content

Commit 0617da7

Browse files
authored
Use environment aware elasticsearch index names (#1823)
* Use environment aware elasticsearch index names * Make PublishEnvironment optional
1 parent 0a693f9 commit 0617da7

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/tooling/Elastic.Documentation.Tooling/Arguments/ExportOption.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using ConsoleAppFramework;
66
using Elastic.Documentation.Configuration;
7+
using Elastic.Documentation.Configuration.Assembler;
78
using Elastic.Documentation.Tooling.Exporters;
89
using Elastic.Markdown.Exporters;
910
using Microsoft.Extensions.Logging;
@@ -60,7 +61,8 @@ public static class ExporterExtensions
6061
public static IReadOnlyCollection<IMarkdownExporter> CreateMarkdownExporters(
6162
this IReadOnlySet<Exporter> exportOptions,
6263
ILoggerFactory logFactory,
63-
IDocumentationConfigurationContext context
64+
IDocumentationConfigurationContext context,
65+
PublishEnvironment? environment = null
6466
)
6567
{
6668
var markdownExporters = new List<IMarkdownExporter>(3);
@@ -71,7 +73,11 @@ IDocumentationConfigurationContext context
7173
if (exportOptions.Contains(Elasticsearch))
7274
markdownExporters.Add(new ElasticsearchMarkdownExporter(logFactory, context.Collector, context.Endpoints));
7375
if (exportOptions.Contains(SemanticElasticsearch))
74-
markdownExporters.Add(new ElasticsearchMarkdownSemanticExporter(logFactory, context.Collector, context.Endpoints));
76+
{
77+
if (environment is null)
78+
throw new ArgumentNullException(nameof(environment), "A publish environment is required when using the semantic elasticsearch exporter");
79+
markdownExporters.Add(new ElasticsearchMarkdownSemanticExporter(environment, logFactory, context.Collector, context.Endpoints));
80+
}
7581
return markdownExporters;
7682
}
7783
}

src/tooling/Elastic.Documentation.Tooling/Exporters/ElasticsearchMarkdownExporter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO.Abstractions;
66
using Elastic.Channels;
77
using Elastic.Documentation.Configuration;
8+
using Elastic.Documentation.Configuration.Assembler;
89
using Elastic.Documentation.Diagnostics;
910
using Elastic.Documentation.Search;
1011
using Elastic.Documentation.Serialization;
@@ -36,7 +37,7 @@ public class ElasticsearchMarkdownExporter(ILoggerFactory logFactory, IDiagnosti
3637
protected override CatalogIndexChannel<DocumentationDocument> NewChannel(CatalogIndexChannelOptions<DocumentationDocument> options) => new(options);
3738
}
3839

39-
public class ElasticsearchMarkdownSemanticExporter(ILoggerFactory logFactory, IDiagnosticsCollector collector, DocumentationEndpoints endpoints)
40+
public class ElasticsearchMarkdownSemanticExporter(PublishEnvironment environment, ILoggerFactory logFactory, IDiagnosticsCollector collector, DocumentationEndpoints endpoints)
4041
: ElasticsearchMarkdownExporterBase<SemanticIndexChannelOptions<DocumentationDocument>, SemanticIndexChannel<DocumentationDocument>>
4142
(logFactory, collector, endpoints)
4243
{
@@ -45,8 +46,8 @@ public class ElasticsearchMarkdownSemanticExporter(ILoggerFactory logFactory, ID
4546
{
4647
GetMapping = (inferenceId, _) => CreateMapping(inferenceId),
4748
GetMappingSettings = (_, _) => CreateMappingSetting(),
48-
IndexFormat = "semantic-documentation-{0:yyyy.MM.dd.HHmmss}",
49-
ActiveSearchAlias = "semantic-documentation",
49+
IndexFormat = $"semantic-docs-{environment.Name}-{{0:yyyy.MM.dd.HHmmss}}",
50+
ActiveSearchAlias = $"semantic-docs-{environment.Name}",
5051
IndexNumThreads = IndexNumThreads,
5152
InferenceCreateTimeout = TimeSpan.FromMinutes(4)
5253
};

src/tooling/docs-assembler/Building/AssemblerBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text.Json;
77
using Documentation.Assembler.Navigation;
88
using Elastic.Documentation;
9+
using Elastic.Documentation.Configuration.Assembler;
910
using Elastic.Documentation.Legacy;
1011
using Elastic.Documentation.Links;
1112
using Elastic.Documentation.Serialization;
@@ -32,15 +33,15 @@ public class AssemblerBuilder(
3233

3334
private ILegacyUrlMapper? LegacyUrlMapper { get; } = legacyUrlMapper;
3435

35-
public async Task BuildAllAsync(FrozenDictionary<string, AssemblerDocumentationSet> assembleSets, IReadOnlySet<Exporter> exportOptions, Cancel ctx)
36+
public async Task BuildAllAsync(PublishEnvironment environment, FrozenDictionary<string, AssemblerDocumentationSet> assembleSets, IReadOnlySet<Exporter> exportOptions, Cancel ctx)
3637
{
3738
if (context.OutputDirectory.Exists)
3839
context.OutputDirectory.Delete(true);
3940
context.OutputDirectory.Create();
4041

4142
var redirects = new Dictionary<string, string>();
4243

43-
var markdownExporters = exportOptions.CreateMarkdownExporters(logFactory, context);
44+
var markdownExporters = exportOptions.CreateMarkdownExporters(logFactory, context, environment);
4445

4546
var tasks = markdownExporters.Select(async e => await e.StartAsync(ctx));
4647
await Task.WhenAll(tasks);

src/tooling/docs-assembler/Cli/RepositoryCommands.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ public async Task<int> BuildAll(
183183
var historyMapper = new PageLegacyUrlMapper(legacyPageChecker, assembleSources.HistoryMappings);
184184

185185
var builder = new AssemblerBuilder(logFactory, assembleContext, navigation, htmlWriter, pathProvider, historyMapper);
186-
await builder.BuildAllAsync(assembleSources.AssembleSets, exporters, ctx);
186+
187+
await builder.BuildAllAsync(assembleContext.Environment, assembleSources.AssembleSets, exporters, ctx);
187188

188189
if (exporters.Contains(Exporter.LinkMetadata))
189190
await cloner.WriteLinkRegistrySnapshot(checkoutResult.LinkRegistrySnapshot, ctx);

0 commit comments

Comments
 (0)