Skip to content

Commit df3621c

Browse files
authored
feature/aspire elasticsearch (#1696)
* stage * Further attempts at manual service discovery resolving * bootstrap endpoints * Start on updating actual indexer code * centralize exporters and configuration contexts * Ensure everything is driven by the exporters options
1 parent ad363e3 commit df3621c

File tree

86 files changed

+1072
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1072
-674
lines changed

src/Elastic.ApiExplorer/OpenApiGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ IFileInfo OutputFile(INavigationItem currentNavigation)
312312
{
313313
const string indexHtml = "index.html";
314314
var fileName = Regex.Replace(currentNavigation.Url + "/" + indexHtml, $"^{context.UrlPathPrefix}", string.Empty);
315-
var fileInfo = _writeFileSystem.FileInfo.New(Path.Combine(context.DocumentationOutputDirectory.FullName, fileName.Trim('/')));
315+
var fileInfo = _writeFileSystem.FileInfo.New(Path.Combine(context.OutputDirectory.FullName, fileName.Trim('/')));
316316
return fileInfo;
317317
}
318318
}

src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public static AssemblyConfiguration Deserialize(string yaml, bool skipPrivateRep
2727
var config = deserializer.Deserialize<AssemblyConfiguration>(input);
2828
foreach (var (name, r) in config.ReferenceRepositories)
2929
{
30-
if (name == "cloud")
31-
{
32-
}
3330
var repository = RepositoryDefaults(r, name);
3431
config.ReferenceRepositories[name] = repository;
3532
}

src/Elastic.Documentation.Configuration/BuildContext.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@
1111

1212
namespace Elastic.Documentation.Configuration;
1313

14-
public record BuildContext : IDocumentationContext
14+
public record BuildContext : IDocumentationSetContext, IDocumentationConfigurationContext
1515
{
1616
public static string Version { get; } = Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyInformationalVersionAttribute>()
1717
.FirstOrDefault()?.InformationalVersion ?? "0.0.0";
1818

1919
public IFileSystem ReadFileSystem { get; }
2020
public IFileSystem WriteFileSystem { get; }
21+
public IReadOnlySet<Exporter> AvailableExporters { get; }
2122

2223
public IDirectoryInfo? DocumentationCheckoutDirectory { get; }
2324
public IDirectoryInfo DocumentationSourceDirectory { get; }
24-
public IDirectoryInfo DocumentationOutputDirectory { get; }
25+
public IDirectoryInfo OutputDirectory { get; }
2526

2627
public ConfigurationFile Configuration { get; }
2728

28-
public VersionsConfiguration VersionsConfig { get; init; }
29+
public VersionsConfiguration VersionsConfiguration { get; }
30+
public ConfigurationFileProvider ConfigurationFileProvider { get; }
31+
public DocumentationEndpoints Endpoints { get; }
2932

3033
public IFileInfo ConfigurationPath { get; }
3134

@@ -35,17 +38,7 @@ public record BuildContext : IDocumentationContext
3538

3639
public bool Force { get; init; }
3740

38-
public bool SkipDocumentationState { get; private set; }
39-
40-
public bool AssemblerBuild
41-
{
42-
get => _assemblerBuild;
43-
init
44-
{
45-
_assemblerBuild = value;
46-
SkipDocumentationState = value;
47-
}
48-
}
41+
public bool AssemblerBuild { get; init; }
4942

5043
// This property is used to determine if the site should be indexed by search engines
5144
public bool AllowIndexing { get; init; }
@@ -56,24 +49,28 @@ public bool AssemblerBuild
5649
public Uri? CanonicalBaseUrl { get; init; }
5750

5851
private readonly string? _urlPathPrefix;
59-
private readonly bool _assemblerBuild;
6052

6153
public string? UrlPathPrefix
6254
{
6355
get => string.IsNullOrWhiteSpace(_urlPathPrefix) ? "" : $"/{_urlPathPrefix.Trim('/')}";
6456
init => _urlPathPrefix = value;
6557
}
6658

67-
public BuildContext(IDiagnosticsCollector collector, IFileSystem fileSystem, VersionsConfiguration versionsConfig)
68-
: this(collector, fileSystem, fileSystem, versionsConfig, null, null)
59+
public BuildContext(
60+
IDiagnosticsCollector collector,
61+
IFileSystem fileSystem,
62+
IConfigurationContext configurationContext
63+
)
64+
: this(collector, fileSystem, fileSystem, configurationContext, ExportOptions.Default, null, null)
6965
{
7066
}
7167

7268
public BuildContext(
7369
IDiagnosticsCollector collector,
7470
IFileSystem readFileSystem,
7571
IFileSystem writeFileSystem,
76-
VersionsConfiguration versionsConfig,
72+
IConfigurationContext configurationContext,
73+
IReadOnlySet<Exporter> availableExporters,
7774
string? source = null,
7875
string? output = null,
7976
GitCheckoutInformation? gitCheckoutInformation = null
@@ -82,7 +79,10 @@ public BuildContext(
8279
Collector = collector;
8380
ReadFileSystem = readFileSystem;
8481
WriteFileSystem = writeFileSystem;
85-
VersionsConfig = versionsConfig;
82+
AvailableExporters = availableExporters;
83+
VersionsConfiguration = configurationContext.VersionsConfiguration;
84+
ConfigurationFileProvider = configurationContext.ConfigurationFileProvider;
85+
Endpoints = configurationContext.Endpoints;
8686

8787
var rootFolder = !string.IsNullOrWhiteSpace(source)
8888
? ReadFileSystem.DirectoryInfo.New(source)
@@ -92,15 +92,15 @@ public BuildContext(
9292

9393
DocumentationCheckoutDirectory = Paths.DetermineSourceDirectoryRoot(DocumentationSourceDirectory);
9494

95-
DocumentationOutputDirectory = !string.IsNullOrWhiteSpace(output)
95+
OutputDirectory = !string.IsNullOrWhiteSpace(output)
9696
? WriteFileSystem.DirectoryInfo.New(output)
9797
: WriteFileSystem.DirectoryInfo.New(Path.Combine(rootFolder.FullName, Path.Combine(".artifacts", "docs", "html")));
9898

9999
if (ConfigurationPath.FullName != DocumentationSourceDirectory.FullName)
100100
DocumentationSourceDirectory = ConfigurationPath.Directory!;
101101

102102
Git = gitCheckoutInformation ?? GitCheckoutInformation.Create(DocumentationCheckoutDirectory, ReadFileSystem);
103-
Configuration = new ConfigurationFile(this, VersionsConfig);
103+
Configuration = new ConfigurationFile(this, VersionsConfiguration);
104104
GoogleTagManager = new GoogleTagManagerConfiguration
105105
{
106106
Enabled = false

src/Elastic.Documentation.Configuration/Builder/ConfigurationFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Elastic.Documentation.Configuration.Builder;
1515

1616
public record ConfigurationFile : ITableOfContentsScope
1717
{
18-
private readonly IDocumentationContext _context;
18+
private readonly IDocumentationSetContext _context;
1919

2020
public IFileInfo SourceFile => _context.ConfigurationPath;
2121

@@ -62,7 +62,7 @@ public record ConfigurationFile : ITableOfContentsScope
6262
Project is not null
6363
&& Project.Equals("Elastic documentation", StringComparison.OrdinalIgnoreCase);
6464

65-
public ConfigurationFile(IDocumentationContext context, VersionsConfiguration versionsConfig)
65+
public ConfigurationFile(IDocumentationSetContext context, VersionsConfiguration versionsConfig)
6666
{
6767
_context = context;
6868
ScopeDirectory = context.ConfigurationPath.Directory!;

src/Elastic.Documentation.Configuration/Builder/RedirectFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public record RedirectFile
1212
{
1313
public Dictionary<string, LinkRedirect>? Redirects { get; set; }
1414
private IFileInfo Source { get; init; }
15-
private IDocumentationContext Context { get; init; }
15+
private IDocumentationSetContext Context { get; init; }
1616

17-
public RedirectFile(IFileInfo source, IDocumentationContext context)
17+
public RedirectFile(IFileInfo source, IDocumentationSetContext context)
1818
{
1919
Source = source;
2020
Context = context;

src/Elastic.Documentation.Configuration/Builder/TableOfContentsConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Elastic.Documentation.Configuration.Builder;
1313

1414
public record TableOfContentsConfiguration : ITableOfContentsScope
1515
{
16-
private readonly IDocumentationContext _context;
16+
private readonly IDocumentationSetContext _context;
1717
private readonly int _maxTocDepth;
1818
private readonly int _depth;
1919
private readonly string _parentPath;
@@ -33,7 +33,7 @@ public TableOfContentsConfiguration(
3333
ConfigurationFile configuration,
3434
IFileInfo definitionFile,
3535
IDirectoryInfo scope,
36-
IDocumentationContext context,
36+
IDocumentationSetContext context,
3737
int depth,
3838
string parentPath)
3939
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
namespace Elastic.Documentation.Configuration;
6+
7+
public record DocumentationEndpoints
8+
{
9+
public required ElasticsearchEndpoint Elasticsearch { get; init; }
10+
}
11+
12+
public record ElasticsearchEndpoint
13+
{
14+
public static ElasticsearchEndpoint Default { get; } = new ElasticsearchEndpoint { Uri = new Uri("https://localhost:9200") };
15+
16+
public required Uri Uri { get; init; }
17+
public string? Username { get; init; }
18+
public string? Password { get; init; }
19+
public string? ApiKey { get; init; }
20+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.Configuration.Versions;
6+
7+
namespace Elastic.Documentation.Configuration;
8+
9+
public interface IConfigurationContext
10+
{
11+
VersionsConfiguration VersionsConfiguration { get; }
12+
ConfigurationFileProvider ConfigurationFileProvider { get; }
13+
DocumentationEndpoints Endpoints { get; }
14+
}
15+
16+
/// Used only to seed <see cref="IConfigurationContext"/> in DI, you primarily want to depend on <see cref="IDocumentationConfigurationContext"/>
17+
public class ConfigurationContext : IConfigurationContext
18+
{
19+
/// <inheritdoc />
20+
public required VersionsConfiguration VersionsConfiguration { get; init; }
21+
22+
/// <inheritdoc />
23+
public required ConfigurationFileProvider ConfigurationFileProvider { get; init; }
24+
25+
/// <inheritdoc />
26+
public required DocumentationEndpoints Endpoints { get; init; }
27+
}
28+
29+
public interface IDocumentationConfigurationContext : IDocumentationContext, IConfigurationContext;

src/Elastic.Documentation.Configuration/Plugins/DetectionRules/TableOfContents/DetectionRulesReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public RuleOverviewReference(
2020
string overviewFilePath,
2121
string parentPath,
2222
ConfigurationFile configuration,
23-
IDocumentationContext context,
23+
IDocumentationSetContext context,
2424
IReadOnlyCollection<string> detectionRuleFolders
2525
)
2626
: base(tableOfContentsScope, overviewFilePath, false, [])
@@ -30,7 +30,7 @@ IReadOnlyCollection<string> detectionRuleFolders
3030
Children = CreateTableOfContentItems(configuration, context);
3131
}
3232

33-
private IReadOnlyCollection<ITocItem> CreateTableOfContentItems(ConfigurationFile configuration, IDocumentationContext context)
33+
private IReadOnlyCollection<ITocItem> CreateTableOfContentItems(ConfigurationFile configuration, IDocumentationSetContext context)
3434
{
3535
var tocItems = new List<ITocItem>();
3636
foreach (var detectionRuleFolder in DetectionRuleFolders)
@@ -44,7 +44,7 @@ private IReadOnlyCollection<ITocItem> CreateTableOfContentItems(ConfigurationFil
4444
.ToArray();
4545
}
4646

47-
private IReadOnlyCollection<ITocItem> ReadDetectionRuleFolder(ConfigurationFile configuration, IDocumentationContext context, string detectionRuleFolder)
47+
private IReadOnlyCollection<ITocItem> ReadDetectionRuleFolder(ConfigurationFile configuration, IDocumentationSetContext context, string detectionRuleFolder)
4848
{
4949
var detectionRulesFolder = Path.Combine(ParentPath, detectionRuleFolder).TrimStart(Path.DirectorySeparatorChar);
5050
var fs = context.ReadFileSystem;

src/Elastic.Documentation.Search/Elastic.Documentation.Search.csproj

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)