-
Notifications
You must be signed in to change notification settings - Fork 54
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
Support reading additional files with references #156
Conversation
@Oberon00 @arminru can you please take a look? Apparently, codegen is broken for 1.19.0 release (open-telemetry/opentelemetry-specification#3299). |
semantic-conventions/src/opentelemetry/semconv/templating/code.py
Outdated
Show resolved
Hide resolved
713e66b
to
018e874
Compare
parser.add_argument( | ||
"--reference-only", | ||
"-r", | ||
help="Additional files to resolve references only (and extends) using GLOB syntax", |
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.
I think this feature warrants a bit more description. This suggestion is also a check if I understood this PR correctly 😃
help="Additional files to resolve references only (and extends) using GLOB syntax", | |
help="""Additional files that will be loaded and available for referencing, but will not be part of the output. | |
As semantic conventions can, in various ways, e.g. using `ref` or `include`, reference other conventions you | |
sometimes need to add files/groups to your input but you don't want the groups in there be processed by | |
the code generator template or markdown generator. In this case, add only the subset of files you want to | |
process with your template / markdown generator to `--yaml-root`, and add any additional required | |
(transitively depended-upon) files with `--reference-only`. | |
""", |
@@ -223,6 +244,12 @@ def setup_parser(): | |||
parser.add_argument( | |||
"--exclude", "-e", help="Exclude the matching files using GLOB syntax", type=str | |||
) | |||
parser.add_argument( | |||
"--reference-only", | |||
"-r", |
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.
I wonder if we actually want a short-name for this flag.
errors: bool = False | ||
|
||
def parse(self, file): | ||
def parse(self, file, ref_only=False): |
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.
Maybe instead add parse_into(self, file, models)
?
If you prefer keeping the boolean argument, please add *
before to enforce using named arguments for it:
def parse(self, file, ref_only=False): | |
def parse(self, file, *, ref_only=False): |
semconv = SemanticConventionSet(debug=False) | ||
semconv.parse(self.load_file("yaml/http.yaml")) | ||
self.assertEqual(len(semconv.models), 3) | ||
semconv.parse(self.load_file("yaml/general.yaml"), True) |
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.
semconv.parse(self.load_file("yaml/general.yaml"), True) | |
semconv.parse(self.load_file("yaml/general.yaml"), ref_only=True) |
etc
(or see comment before for maybe using an API that does not rely on a boolean)
I hit this with Go and Python so was also looking at making this patch. My 2 cents, I expected it to work without an additional argument. As in, if I give a path to where the yaml schema files are to If the user doesn't want to include all the schema files in the path they give to -- And |
I think this is already the case. IIUC, this PR is actually about adding a way to exclude files from output generation but not from internal model construction (see #156 (comment)).
I wonder if this PR is maybe going into the wrong direction, as it adds more reliance on the directory structure. Maybe globbing on the group ID would be better. Or maybe |
Actually I now looked at how If going for the ID-based filtering, this could mean that some group IDs in the semantic conventions might have to be renamed in order to improve "filterability". This would not change the actual attribute keys, as the "prefix" is independent of the group ID. If going for adding the filepath to the model, the existing |
Another option would be: instead of adding additional paths, you would add the actual root as --yaml-root, and you would add another option I think all these options work, including the one currently in the PR, it's more of an UX decision. |
Thanks for looking into this. I don't have specific comments about the implementation itself, and which options to pass to generate code. From an end-user point of view, and based on my (very limited) understanding of semconv code generation, expectations are as follows:
A docker command like:
seems to meet these expectations, assuming it can be supported. If there is a need to:
every time the spec releases a different set of *.yaml files, due to changes in internal dependencies, this becomes more difficult to deal with, and is more subject to errors. Changing the docker run command once this is resolved is not an issue, but having to change it all the time (3) is a concern here. If somehow these expectations are not realistic, please clarify what we (users in languages) are supposed to do then (see (1)). Regards. |
Thanks for your comment. I was of the opinion that the docker command you mention (with some syntax changes such as Based on #122 (comment), it might be enough to add support for multiple types to |
to address @marcalff concern, I think
It's also the first time for me looking into codegen and here I'd really like to reasonably unblock ourselves for 1.19.0 release and take steps to prevent it. I wonder if these steps are good enough. Regarding reusing current functionality without a new flag and allowing multiple
The opt2 is somewhat controversial and I'm not ready to drive it forward. |
I think that has very little to do with the issue here. I think this should be either enforced by the tool (option 2) or by spec reviewers. Option 1 would be "enforcement by difficult UX". In general, I believe adding reliance on the directory structure instead of explicit group kinds/types is going into the wrong direction. |
makes sense. Options 2 can happen any time in the future as well and not blocking.
ok, so I can do the following in this PR instead of
sounds good @Oberon00 ? |
great point that |
Right, I think that is what I was trying to suggest. I'm trying to catch up. I don't think having multiple values to
And Python:
|
we'll have to update generate scripts anyway and the common pattern can be: -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions:/source \
--only span,attribute_group,event this will preserve current attribute locations in files. an alternative could be to run script per semconv type and move attributes into individual files -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions:/source \
--only span -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions:/source \
--only attribute_group -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions:/source \
--only event |
Did multiple |
Should attribute_group even be required to be mentioned? I think for referencing, you don't need to include it in |
good point. thought about it and I think it's totally valid to generate md or template for an attribute group. |
closing in favor of #157 |
Fixes #155
Adds
--references-only
flag tosemconvgen
which allows to specify additional sources for referenced (extended, included) semconv.E.g. browser resource semconv references general
user_agent.original
attribute. When code for resources is generated,user_agent.original
needs to be resolved, even thoughuser_agent
semconv is not generated.Usage (tested on Java):
All semconv except resources
New flag excludes semconvs from the output, but allows references to them.
Resources:
I.e. from all semconv output resource conventions, and use yaml files from root folder
semantic_conventions
to resolve references.