Skip to content

Commit 411c590

Browse files
committed
stage
1 parent b133c9d commit 411c590

File tree

12 files changed

+151
-5
lines changed

12 files changed

+151
-5
lines changed

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageVersion Include="AWSSDK.Core" Version="4.0.0.2" />
1717
<PackageVersion Include="AWSSDK.SQS" Version="4.0.0.1" />
1818
<PackageVersion Include="AWSSDK.S3" Version="4.0.0.1" />
19+
<PackageVersion Include="Elastic.Ingest.Elasticsearch" Version="0.8.0" />
1920
</ItemGroup>
2021
<!-- Build -->
2122
<ItemGroup>
@@ -63,4 +64,4 @@
6364
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
6465
<PackageVersion Include="xunit.v3" Version="1.1.0" />
6566
</ItemGroup>
66-
</Project>
67+
</Project>

docs-builder.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assembler-filter", "assembl
9494
actions\assembler-filter\action.yml = actions\assembler-filter\action.yml
9595
EndProjectSection
9696
EndProject
97+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Documentation.Search", "src\Elastic.Documentation.Search\Elastic.Documentation.Search.csproj", "{052F70DE-CA5A-45F9-800B-E13CFEAE262C}"
98+
EndProject
9799
Global
98100
GlobalSection(SolutionConfigurationPlatforms) = preSolution
99101
Debug|Any CPU = Debug|Any CPU
@@ -155,6 +157,10 @@ Global
155157
{CD94F9E4-7FCD-4152-81F1-4288C6B75367}.Debug|Any CPU.Build.0 = Debug|Any CPU
156158
{CD94F9E4-7FCD-4152-81F1-4288C6B75367}.Release|Any CPU.ActiveCfg = Release|Any CPU
157159
{CD94F9E4-7FCD-4152-81F1-4288C6B75367}.Release|Any CPU.Build.0 = Release|Any CPU
160+
{052F70DE-CA5A-45F9-800B-E13CFEAE262C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
161+
{052F70DE-CA5A-45F9-800B-E13CFEAE262C}.Debug|Any CPU.Build.0 = Debug|Any CPU
162+
{052F70DE-CA5A-45F9-800B-E13CFEAE262C}.Release|Any CPU.ActiveCfg = Release|Any CPU
163+
{052F70DE-CA5A-45F9-800B-E13CFEAE262C}.Release|Any CPU.Build.0 = Release|Any CPU
158164
EndGlobalSection
159165
GlobalSection(NestedProjects) = preSolution
160166
{4D198E25-C211-41DC-9E84-B15E89BD7048} = {BE6011CC-1200-4957-B01F-FCCA10C5CF5A}
@@ -178,5 +184,6 @@ Global
178184
{059E787F-85C1-43BE-9DD6-CE319E106383} = {BE6011CC-1200-4957-B01F-FCCA10C5CF5A}
179185
{7D36DDDA-9E0B-4D2C-8033-5D62FF8B6166} = {059E787F-85C1-43BE-9DD6-CE319E106383}
180186
{FB1C1954-D8E2-4745-BA62-04DD82FB4792} = {245023D2-D3CA-47B9-831D-DAB91A2FFDC7}
187+
{052F70DE-CA5A-45F9-800B-E13CFEAE262C} = {BE6011CC-1200-4957-B01F-FCCA10C5CF5A}
181188
EndGlobalSection
182189
EndGlobal
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Elastic.Ingest.Elasticsearch" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\Elastic.Documentation\Elastic.Documentation.csproj"/>
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Buffers;
6+
using System.Text.Json;
7+
using Elastic.Ingest.Elasticsearch;
8+
using Elastic.Ingest.Elasticsearch.Indices;
9+
using Elastic.Transport;
10+
using Microsoft.Extensions.Hosting;
11+
using Microsoft.Extensions.Logging;
12+
13+
namespace Elastic.Documentation.Search;
14+
15+
public record DocumentationDocument
16+
{
17+
public string? Title { get; set; }
18+
}
19+
20+
public class IngestCollector : IDisposable
21+
{
22+
private readonly IndexChannel<DocumentationDocument> _channel;
23+
private readonly ILogger<IngestCollector> _logger;
24+
25+
public IngestCollector(ILoggerFactory logFactory, string url, string apiKey)
26+
{
27+
_logger = logFactory.CreateLogger<IngestCollector>();
28+
var uri = new Uri(url);
29+
var moniker = $"{uri.Host}${Guid.NewGuid():N}";
30+
var base64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(moniker));
31+
var cloudId = $"name:{base64}";
32+
33+
var pool = new CloudNodePool(cloudId, new ApiKey(apiKey));
34+
var configuration = new TransportConfiguration(pool);
35+
var transport = new DistributedTransport(configuration);
36+
var options = new IndexChannelOptions<DocumentationDocument>(transport)
37+
{
38+
IndexFormat = "documentation",
39+
ExportExceptionCallback = e => _logger.LogError(e, "Failed to export document"),
40+
ServerRejectionCallback = items => _logger.LogInformation("Server rejection: {Rejection}", items.First().Item2)
41+
};
42+
_channel = new IndexChannel<DocumentationDocument>(options);
43+
}
44+
45+
public async ValueTask<bool> TryWrite(DocumentationDocument document, CancellationToken ctx = default)
46+
{
47+
if (_channel.TryWrite(document))
48+
return true;
49+
50+
if (await _channel.WaitToWriteAsync(ctx))
51+
return _channel.TryWrite(document);
52+
return false;
53+
}
54+
55+
public void Dispose()
56+
{
57+
_channel.Complete();
58+
_channel.Dispose();
59+
GC.SuppressFinalize(this);
60+
}
61+
}

src/Elastic.Markdown/DocumentationGenerator.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class DocumentationGenerator
4040
private readonly ILogger _logger;
4141
private readonly IFileSystem _writeFileSystem;
4242
private readonly IDocumentationFileExporter _documentationFileExporter;
43+
private readonly IMarkdownExporter[] _markdownExporters;
4344
private HtmlWriter HtmlWriter { get; }
4445

4546
public DocumentationSet DocumentationSet { get; }
@@ -51,12 +52,14 @@ public DocumentationGenerator(
5152
ILoggerFactory logger,
5253
INavigationHtmlWriter? navigationHtmlWriter = null,
5354
IDocumentationFileOutputProvider? documentationFileOutputProvider = null,
55+
IMarkdownExporter[]? markdownExporters = null,
5456
IDocumentationFileExporter? documentationExporter = null,
5557
IConversionCollector? conversionCollector = null,
5658
ILegacyUrlMapper? legacyUrlMapper = null,
5759
IPositionalNavigation? positionalNavigation = null
5860
)
5961
{
62+
_markdownExporters = markdownExporters ?? [];
6063
_documentationFileOutputProvider = documentationFileOutputProvider;
6164
_conversionCollector = conversionCollector;
6265
_writeFileSystem = docSet.Context.WriteFileSystem;
@@ -219,6 +222,12 @@ private async Task ProcessFile(HashSet<string> offendingFiles, DocumentationFile
219222
return;
220223
}
221224

225+
if (file is MarkdownFile markdown)
226+
{
227+
foreach (var exporter in _markdownExporters)
228+
_ = await exporter.Export(markdown);
229+
}
230+
222231
_logger.LogTrace("--> {FileFullPath}", file.SourceFile.FullName);
223232
//TODO send file to OutputFile() so we can validate its scope is defined in navigation.yml
224233
var outputFile = OutputFile(file.RelativePath);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Elastic.Markdown.IO;
6+
7+
namespace Elastic.Markdown.Exporters;
8+
9+
public interface IMarkdownExporter
10+
{
11+
ValueTask<bool> Export(MarkdownFile file);
12+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
// See the LICENSE file in the project root for more information
44

55
using System.Collections.Frozen;
6+
using Documentation.Assembler.Indexing;
67
using Documentation.Assembler.Navigation;
78
using Elastic.Documentation.Legacy;
89
using Elastic.Documentation.Links;
910
using Elastic.Markdown;
11+
using Elastic.Markdown.Exporters;
1012
using Elastic.Markdown.Links.CrossLinks;
1113
using Microsoft.Extensions.Logging;
1214

@@ -92,12 +94,18 @@ string Resolve(string relativeMarkdownPath)
9294

9395
private async Task<GenerationResult> BuildAsync(AssemblerDocumentationSet set, Cancel ctx)
9496
{
97+
IMarkdownExporter[]? markdownExporters =
98+
Environment.GetEnvironmentVariable("ELASTIC_API_KEY") is { } apiKey &&
99+
Environment.GetEnvironmentVariable("ELASTIC_URL") is { } url
100+
? [new ElasticsearchMarkdownExporter(logger, url, apiKey)]
101+
: null;
95102
var generator = new DocumentationGenerator(
96103
set.DocumentationSet,
97104
logger, HtmlWriter,
98105
pathProvider,
99106
legacyUrlMapper: LegacyUrlMapper,
100-
positionalNavigation: navigation
107+
positionalNavigation: navigation,
108+
markdownExporters: markdownExporters
101109
);
102110
return await generator.GenerateAll(ctx);
103111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ await Parallel.ForEachAsync(repositories,
163163
outputPath
164164
);
165165
var set = new DocumentationSet(context, logger);
166-
var generator = new DocumentationGenerator(set, logger, null, null, new NoopDocumentationFileExporter());
166+
var generator = new DocumentationGenerator(set, logger, null, null, null, new NoopDocumentationFileExporter());
167167
_ = await generator.GenerateAll(c);
168168

169169
IAmazonS3 s3Client = new AmazonS3Client();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Elastic.Documentation.Search;
6+
using Elastic.Markdown.Exporters;
7+
using Elastic.Markdown.IO;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace Documentation.Assembler.Indexing;
11+
12+
public class ElasticsearchMarkdownExporter(ILoggerFactory logFactory, string url, string apiKey) : IMarkdownExporter, IDisposable
13+
{
14+
private readonly IngestCollector _ingestCollector = new(logFactory, url, apiKey);
15+
16+
public void Dispose()
17+
{
18+
_ingestCollector.Dispose();
19+
GC.SuppressFinalize(this);
20+
}
21+
22+
public async ValueTask<bool> Export(MarkdownFile file)
23+
{
24+
var doc = new DocumentationDocument
25+
{
26+
Title = file.Title,
27+
};
28+
return await _ingestCollector.TryWrite(doc);
29+
}
30+
}

src/tooling/docs-assembler/docs-assembler.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</ItemGroup>
2727

2828
<ItemGroup>
29+
<ProjectReference Include="..\..\Elastic.Documentation.Search\Elastic.Documentation.Search.csproj" />
2930
<ProjectReference Include="..\..\Elastic.Documentation\Elastic.Documentation.csproj" />
3031
<ProjectReference Include="..\..\Elastic.Markdown\Elastic.Markdown.csproj" />
3132
<ProjectReference Include="..\Elastic.Documentation.Tooling\Elastic.Documentation.Tooling.csproj" />

0 commit comments

Comments
 (0)