Skip to content

Add all versions in version dropdown and filter out non-existing URLs #1367

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

Merged
merged 14 commits into from
Jun 16, 2025

Conversation

reakaleek
Copy link
Member

@reakaleek reakaleek commented Jun 13, 2025

This pull request introduces significant updates to the Elastic documentation ecosystem, including the addition of a Bloom filter-based legacy page checker, new tooling commands, and project restructuring. The changes aim to improve the efficiency of legacy page validation, enhance project modularity, and refine the user experience in documentation navigation.

Documentation Enhancements

  • Bloom Filter Implementation: Added a BloomFilter class in src/Elastic.Documentation.LegacyDocs/BloomFilter.cs to enable efficient legacy page existence checks. The filter supports persistence and optimal parameter calculation for false positive probability.
  • Legacy Page Checker: Introduced LegacyPageChecker in src/Elastic.Documentation.LegacyDocs/LegacyPageChecker.cs for checking legacy page existence using the Bloom filter. Includes methods for loading and generating the Bloom filter binary file.
  • Pages Provider: Added IPagesProvider and LocalPagesProvider in src/Elastic.Documentation.LegacyDocs/PagesProvider.cs to fetch pages from a local repository.
  • README Update: Documented usage of the legacy page checker and instructions for creating/updating the Bloom filter file in src/Elastic.Documentation.LegacyDocs/README.md.

Project Restructuring

  • New Projects: Added Elastic.Documentation.LegacyDocs and Elastic.Documentation.LegacyDocs.Tests projects to the solution, along with their configurations in docs-builder.sln. [1] [2]
  • Embedded Resource: Included legacy-pages.bloom.bin as an embedded resource in Elastic.Documentation.LegacyDocs.csproj.
  • Cross-Project References: Added project references to integrate Elastic.Documentation.LegacyDocs with other components, such as Elastic.Markdown.

Tooling Updates

  • Legacy Docs Commands: Added commands in src/tooling/docs-assembler/Cli/LegacyDocsCommands.cs for generating and validating Bloom filter binaries via CLI.
  • Repository Commands: Updated BuildAll in src/tooling/docs-assembler/Cli/RepositoryCommands.cs to use the new LegacyPageChecker for page validation.

UI Improvements

  • Table of Contents: Updated _TableOfContents.cshtml to display legacy page links conditionally based on their existence. Improved styling for better visual hierarchy. [1] [2]
  • Version Dropdown: Modified HtmlWriter.cs to dynamically populate version dropdown items based on legacy page mappings.

Miscellaneous Fixes

  • Package Updates: Corrected the casing of a package reference in Elastic.Documentation.Tooling.csproj.
  • Mapping Key Adjustment: Removed trailing slash from mapping keys in docs-assembler/AssembleSources.cs.

@reakaleek reakaleek requested a review from a team as a code owner June 13, 2025 16:27
@reakaleek reakaleek marked this pull request as draft June 13, 2025 17:20
@reakaleek reakaleek requested a review from Copilot June 13, 2025 22:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive legacy version support by wiring in a bloom-filter–backed page existence checker and updating the UI to list all historical versions while disabling links for pages that no longer exist.

  • Introduces a new Elastic.Documentation.LegacyDocs project with LegacyPageChecker and CLI commands to generate/check against a bloom filter.
  • Enhances PageLegacyUrlMapper to mark legacy mappings as existing or not, and updates the Razor UI (_TableOfContents.cshtml) and HTML writer to render/disable links accordingly.
  • Updates version dropdown logic to include all versions (Skip(1).ToArray()), adjusts YAML mappings to use trailing slashes, and fixes project references.

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tooling/docs-assembler/Legacy/PageLegacyUrlMapper.cs Added existence check via LegacyPageChecker, updated mapping API
src/tooling/docs-assembler/Cli/LegacyDocsCommands.cs New CLI for bloom-filter creation and page-existence queries
src/tooling/docs-assembler/Cli/RepositoryCommands.cs Wired up PageLegacyUrlMapper with LegacyPageChecker
src/tooling/docs-assembler/AssembleSources.cs Adjusted YAML key handling (removed forced trailing slash)
src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml Conditional rendering/disabling of legacy version links
src/Elastic.Markdown/Slices/HtmlWriter.cs Changed LegacyPages to include all prior versions
src/tooling/docs-assembler/legacy-url-mappings.yml Added trailing slashes to keys for mapping consistency
Comments suppressed due to low confidence (3)

src/tooling/docs-assembler/Legacy/PageLegacyUrlMapper.cs:21

  • There are no existing unit tests covering the new filtering logic in MapLegacyUrl. Adding tests for scenarios where pages exist and do not exist will help prevent regressions.
public IReadOnlyCollection<LegacyPageMapping> MapLegacyUrl(IReadOnlyCollection<string>? mappedPages)

src/tooling/docs-assembler/Cli/LegacyDocsCommands.cs:17

  • [nitpick] The logger is typed as Program, but this class is LegacyDocsCommands. For clarity and consistency, consider using ILogger<LegacyDocsCommands>.
private readonly ILogger<Program> _log = logger.CreateLogger<Program>();

src/tooling/docs-assembler/AssembleSources.cs:141

  • Interpolating mappingValues (a list) directly will call its ToString() instead of listing items. Consider using string.Join(", ", mappingValues) for a clearer warning message.
reader.EmitWarning($"'{mappingKey}' is already mapped to '{mappingValues}'");

@reakaleek reakaleek marked this pull request as ready for review June 13, 2025 22:25
Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few nitpicks.

@@ -19,7 +19,9 @@
<PackageVersion Include="FakeItEasy" Version="8.3.0" />
<PackageVersion Include="Elastic.Ingest.Elasticsearch" Version="0.11.3" />
<PackageVersion Include="Microsoft.OpenApi" Version="2.0.0-preview9" />
<PackageVersion Include="Octokit" Version="14.0.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks unreferenced, can remove this dep?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<PackageVersion Include="System.Text.Json" Version="9.0.5" />
<PackageVersion Include="TestableIO.System.IO.Abstractions.Wrappers" Version="22.0.14" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not used (we use System.IO.Abstractions which is the same thing).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var itemList = new List<string>(items);
var filter = new BloomFilter(itemList.Count, falsePositiveProbability);
foreach (var item in itemList)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent braces style

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (var i = 0; i < size; i++)
{
if ((bitArrayBytes[i / 8] & (1 << (i % 8))) != 0)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent braces style

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// <returns>False if the item is definitely not in the set, True if it might be.</returns>
public bool Check(string item)
{
var itemBytes = Encoding.UTF8.GetBytes(item.Replace("/guide/en/", ""));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do the item.Replace("/guide/en/", "") at the call site of Check so the bloom filter implementation stays agnostic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

782b42c

I did it a little different.

I'm now building the bloom filter binary with /guide/en instead.

Hence, the BloomFilter class itself only knows it's storing a list of strings.

Copy link
Member Author

@reakaleek reakaleek Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my first attempt, I thought the string size might influence the size of the bloom.bin file, which is why I removed the /guide/en prefix in the first place.

But obviously, it doesn't, since it's only storing the hashes.

@reakaleek reakaleek requested a review from Mpdreamz June 16, 2025 09:46
@reakaleek reakaleek merged commit 9ecb990 into main Jun 16, 2025
15 checks passed
@reakaleek reakaleek deleted the feature/add-only-existing-pages-to-version-dropdown branch June 16, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants