-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix broken links in docs, add broken link checker. #7658
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import json | ||
| import os | ||
| import re | ||
| import sys | ||
|
|
||
| # | ||
| # Checks for broken redirects (in _redirects.json) and links from markdown files to | ||
| # nonexistent pages. Does _not_ check for links to anchors that don't exist. | ||
| # | ||
|
|
||
| # Targets to these 'well known' pages are OK. | ||
| WELL_KNOWN_PAGES = ["/libraries.html", "/downloads.html", "/community/", "/thanks.html"] | ||
|
|
||
| def normalize_link(source, target): | ||
| dirname = os.path.dirname(source) | ||
| normalized = os.path.normpath(os.path.join(dirname, target)) | ||
| return normalized | ||
|
|
||
| def verify_redirects(docs_directory, redirect_json): | ||
| ok = True | ||
|
|
||
| with open(redirect_json, 'r') as f: | ||
| redirects = json.loads(f.read()) | ||
|
|
||
| for redirect in redirects: | ||
| if redirect["target"] in WELL_KNOWN_PAGES: | ||
| continue | ||
|
|
||
| # Replace .html and named anchors with .md, and check the file on the filesystem. | ||
| target = re.sub(r'\.html(#.*)?$', '.md', normalize_link(redirect["source"], redirect["target"])) | ||
| if not os.path.exists(os.path.join(docs_directory, target)): | ||
| sys.stderr.write('Redirect [' + redirect["source"] + '] target does not exist: ' + redirect["target"] + "\n") | ||
| ok = False | ||
|
|
||
| return ok | ||
|
|
||
| def verify_markdown(docs_directory): | ||
| ok = True | ||
|
|
||
| # Get list of markdown files. | ||
| markdowns = [] | ||
| for root, dirs, files in os.walk(docs_directory): | ||
| for name in files: | ||
| if name.endswith('.md'): | ||
| markdowns.append(os.path.join(root, name)) | ||
|
|
||
| for markdown_file in markdowns: | ||
| with open(markdown_file, 'r') as f: | ||
| content = f.read() | ||
|
|
||
| for m in re.finditer(r'\[([^\[]*?)\]\((.*?)(?: \"[^\"]+\")?\)', content): | ||
| target = m.group(2) | ||
|
|
||
| if target in WELL_KNOWN_PAGES: | ||
| continue | ||
|
|
||
| if markdown_file.endswith("/druid-kerberos.md") and target in ['regexp', 'druid@EXAMPLE.COM']: | ||
| # Hack to support the fact that rule examples in druid-kerberos docs look sort of like markdown links. | ||
| continue | ||
|
|
||
| target = re.sub(r'^/docs/VERSION/', '', target) | ||
| target = re.sub(r'#.*$', '', target) | ||
| target = re.sub(r'\.html$', '.md', target) | ||
| target = re.sub(r'/$', '/index.md', target) | ||
| if target and not (target.startswith('http://') or target.startswith('https://')): | ||
| target_normalized = normalize_link(markdown_file, target) | ||
|
|
||
| if not os.path.exists(target_normalized): | ||
| sys.stderr.write('Page [' + markdown_file + '] target does not exist: ' + m.group(2) + "\n") | ||
| ok = False | ||
|
|
||
| return ok | ||
|
|
||
| def main(): | ||
| if len(sys.argv) != 3: | ||
| sys.stderr.write('usage: program <docs dir> <redirect.json>\n') | ||
| sys.exit(1) | ||
|
|
||
| ok = verify_redirects(sys.argv[1], sys.argv[2]) | ||
| ok = verify_markdown(sys.argv[1]) and ok | ||
| if not ok: | ||
| sys.exit(1) | ||
|
|
||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,7 +41,7 @@ Below is a description of the high-level features and functionality of the Druid | |||||
|
|
||||||
| ## Home | ||||||
|
|
||||||
| The home view provide a high level overview of the cluster. Each card is clickable and links to the appropriate view. The legacy menu allows you to go to the [legacy coordinator and overlord consoles](./management-uis#legacy-consoles) should you need them. | ||||||
| The home view provide a high level overview of the cluster. Each card is clickable and links to the appropriate view. The legacy menu allows you to go to the [legacy coordinator and overlord consoles](./management-uis.html#legacy-consoles) should you need them. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this isn't your fault, but 'The home view provides ...'
Suggested change
|
||||||
|
|
||||||
|  | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| --- | ||
| layout: doc_page | ||
| title: "insert-segment-to-db Tool" | ||
| --- | ||
|
|
||
| <!-- | ||
| ~ Licensed to the Apache Software Foundation (ASF) under one | ||
| ~ or more contributor license agreements. See the NOTICE file | ||
| ~ distributed with this work for additional information | ||
| ~ regarding copyright ownership. The ASF licenses this file | ||
| ~ to you under the Apache License, Version 2.0 (the | ||
| ~ "License"); you may not use this file except in compliance | ||
| ~ with the License. You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, | ||
| ~ software distributed under the License is distributed on an | ||
| ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| ~ KIND, either express or implied. See the License for the | ||
| ~ specific language governing permissions and limitations | ||
| ~ under the License. | ||
| --> | ||
|
|
||
| # insert-segment-to-db Tool | ||
|
|
||
| In older versions of Apache Druid (incubating), `insert-segment-to-db` was a tool that could scan deep storage and | ||
| insert data from there into Druid metadata storage. It was intended to be used to update the segment table in the | ||
| metadata storage after manually migrating segments from one place to another, or even to recover lost metadata storage | ||
| by telling it where the segments are stored. | ||
|
|
||
| In Druid 0.14.x and earlier, Druid wrote segment metadata to two places: the metadata store's `druid_segments` table, and | ||
| `descriptor.json` files in deep storage. This practice was stopped in Druid 0.15.0 as part of | ||
| [consolidated metadata management](https://github.com/apache/druid/issues/6849), for the following reasons: | ||
|
|
||
| 1. If any segments are manually dropped or re-enabled by cluster operators, this information is not reflected in | ||
| deep storage. Restoring metadata from deep storage would undo any such drops or re-enables. | ||
| 2. Ingestion methods that allocate segments optimistically (such as native Kafka or Kinesis stream ingestion, or native | ||
| batch ingestion in 'append' mode) can write segments to deep storage that are not meant to actually be used by the | ||
| Druid cluster. There is no way, while purely looking at deep storage, to differentiate the segments that made it into | ||
| the metadata store originally (and therefore _should_ be used) from the segments that did not (and therefore | ||
| _should not_ be used). | ||
| 3. Nothing in Druid other than the `insert-segment-to-db` tool read the `descriptor.json` files. | ||
|
|
||
| After this change, Druid stopped writing `descriptor.json` files to deep storage, and now only writes segment metadata | ||
| to the metadata store. This meant the `insert-segment-to-db` tool is no longer useful, so it was removed in Druid 0.15.0. | ||
|
|
||
| It is highly recommended that you take regular backups of your metadata store, since it is difficult to recover Druid | ||
| clusters properly without it. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I could tell, this script doesn't modify anything and just prints out the broken links/redirects, what is the purpose of calling it here? Should we be catching the exit code and have it cause a failure of some sort if it has non-zero exit code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bash script is running with mode
-eso if any subcommand exits nonzero, it will automatically stop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! I see that now, my bad 👍