Skip to content
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

feat: Auto-generate documentation for jaeger-v2 configuration structs via AST #6776

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AnmolxSingh
Copy link
Contributor

Which problem is this PR solving?

Description of the changes

  • Rough outline of the milestones: (Copied from Issue)

    • basic framework that navigates to the listed structs via AST (and prints something simple)
    • recursively evaluate nested structs (and print a hierarchy)
    • print complete info about config structs (e.g. as YAML or JSON output) including field names, types, descriptions (from
      comments)
    • enhance Jaeger docs to use the output from last step to render docs in HTML

How was this change tested?

Checklist

Signed-off-by: AnmolxSingh <[email protected]>
@AnmolxSingh AnmolxSingh requested a review from a team as a code owner February 26, 2025 17:21
@AnmolxSingh AnmolxSingh requested a review from jkowall February 26, 2025 17:21
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.02%. Comparing base (ce07285) to head (cbdb269).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6776      +/-   ##
==========================================
- Coverage   96.03%   96.02%   -0.02%     
==========================================
  Files         363      364       +1     
  Lines       20677    20690      +13     
==========================================
+ Hits        19857    19867      +10     
- Misses        626      628       +2     
- Partials      194      195       +1     
Flag Coverage Δ
badger_v1 9.81% <ø> (+0.05%) ⬆️
badger_v2 1.89% <ø> (+0.06%) ⬆️
cassandra-4.x-v1-manual 14.86% <ø> (+0.05%) ⬆️
cassandra-4.x-v2-auto 1.88% <ø> (+0.06%) ⬆️
cassandra-4.x-v2-manual 1.88% <ø> (+0.06%) ⬆️
cassandra-5.x-v1-manual 14.86% <ø> (+0.05%) ⬆️
cassandra-5.x-v2-auto 1.88% <ø> (+0.06%) ⬆️
cassandra-5.x-v2-manual 1.88% <ø> (+0.06%) ⬆️
elasticsearch-6.x-v1 19.19% <ø> (+0.04%) ⬆️
elasticsearch-7.x-v1 19.27% <ø> (+0.04%) ⬆️
elasticsearch-8.x-v1 19.44% <ø> (+0.04%) ⬆️
elasticsearch-8.x-v2 1.89% <ø> (+0.06%) ⬆️
grpc_v1 10.86% <ø> (+0.05%) ⬆️
grpc_v2 7.86% <ø> (+0.06%) ⬆️
kafka-3.x-v1 10.11% <ø> (-0.02%) ⬇️
kafka-3.x-v2 1.89% <ø> (+0.06%) ⬆️
memory_v2 1.89% <ø> (+0.06%) ⬆️
opensearch-1.x-v1 19.32% <ø> (+0.04%) ⬆️
opensearch-2.x-v1 19.32% <ø> (+0.04%) ⬆️
opensearch-2.x-v2 1.89% <ø> (+0.06%) ⬆️
tailsampling-processor 0.48% <ø> (-0.01%) ⬇️
unittests 94.91% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AnmolxSingh AnmolxSingh force-pushed the ast branch 2 times, most recently from 107268e to e5c469a Compare February 26, 2025 18:08
Signed-off-by: AnmolxSingh <[email protected]>
@yurishkuro yurishkuro requested a review from Copilot February 26, 2025 19:17
Copy link

@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.

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

}

// Iterate over the struct fields
for _, field := range structType.Fields.List {
Copy link
Preview

Copilot AI Feb 26, 2025

Choose a reason for hiding this comment

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

The current loop iterates over field.Names without handling fields that are embedded (anonymous fields). Adding logic to process embedded fields could improve the robustness of the documentation generation.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Member

Choose a reason for hiding this comment

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

This is correct observation

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Anmol <[email protected]>
continue
}

structDoc := StructDoc{
Copy link
Member

Choose a reason for hiding this comment

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

not every struct you encounter is a config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are config structs only in config.go file?

Copy link
Member

Choose a reason for hiding this comment

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

not guaranteed. Top level configs usually are, but the nested subconfigs they contain could be anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we use any specific convention to identify config structs?

Copy link
Member

Choose a reason for hiding this comment

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

sadly, there is no required interface that configs implement. The factories typically have this function

func createDefaultConfig() component.Config {
	return &Config{}
}

so you could use it as an indication that Config struct is really an interesting config.

Copy link
Contributor Author

@AnmolxSingh AnmolxSingh Feb 28, 2025

Choose a reason for hiding this comment

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

For this i am planning to use ast.Inspect two times one for filtering the config structs returned by above function and second for printing them

Co-authored-by: Yuri Shkuro <[email protected]>
Signed-off-by: Anmol <[email protected]>
Signed-off-by: AnmolxSingh <[email protected]>
// Iterate over each target directory
for _, dir := range targetDirs {
fmt.Printf("Parsing directory: %s\n", dir)
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
Copy link
Member

Choose a reason for hiding this comment

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

you are using file system access. Doesn't Go AST have other means of traversal? We have some components imported directly from OTEL, with their own configs, and they will not be easily accessible via local file system (they would be somewhere in Go cache).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that would require more dependencies to be added to go.mod

Copy link
Member

Choose a reason for hiding this comment

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

Like what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

golang.org/x/tools/go/packages would be added to traverse AST based on package

Copy link
Member

Choose a reason for hiding this comment

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

+1

Signed-off-by: AnmolxSingh <[email protected]>
@AnmolxSingh AnmolxSingh changed the title Auto-generate documentation for jaeger-v2 configuration structs via AST feat: Auto-generate documentation for jaeger-v2 configuration structs via AST Mar 2, 2025
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.

[experiment] Auto-generate documentation for jaeger-v2 configuration structs via AST
2 participants