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

Implement code-generation hints to drop/rename attributes in case of a collision #1462

Open
lmolkova opened this issue Oct 9, 2024 · 3 comments
Assignees
Labels
tooling Regarding build, workflows, build-tools, ...

Comments

@lmolkova
Copy link
Contributor

lmolkova commented Oct 9, 2024

This is a tracking issue for #1118 (comment) Phase 2

Currently we don't allow collisions between attribute/event/etc names in the code-friendly representation of them (. replaced with _).

But we have some attributes that would benefit from renaming (e.g. db.cosmosdb.client_id should stay consistent with messaging.client.id).

We can resolve it by providing code-generation hints in the yaml that would help code-generator to resolve collisions.

@lmolkova lmolkova added the tooling Regarding build, workflows, build-tools, ... label Oct 9, 2024
@lmolkova lmolkova self-assigned this Oct 9, 2024
@lmolkova
Copy link
Contributor Author

lmolkova commented Oct 9, 2024

Scenarios to consider

  1. attribute is deprecated, the replacement has the same constant name (messaging.client_id -> messaging.client.id):
  2. attribute is deprecated, the replacement has the same constant name, but different type
    1. code generator hint could tell to drop it (same as scenario 1)
    2. OR code-generator may need to generate both attributes, so needs a hint to use a different name for the replacement attribute
  3. Attribute name contains non-ASCII characters and needs a code-generator-friendly name
    ...

Proposal

Combining with #1419 to keep it consistent with deprecation if possible.

Scenarios 1 & 2i

- id: registry.foo
  ...
  attributes:
    - id: foo.bar_id
      deprecated:            # not in the scope of this item
        action: rename
        renamed_to: foo.bar.id
      code_generation_hint:  # <-- this is the proposal for scenarios 1 and 2i above
        action: exclude      # <-- this is the proposal for scenarios 1 and 2i above

Scenarios 2ii & 3

- id: registry.foo
  ...
  attributes:
    - id: foo.bar_code
      type: int
      deprecated:
        action: remove
      note: Renamed to `foo.bar.code` and type changed to string
    - id: foo.bar.code
      type: string
      code_generation_hint:                # <-- this is the proposal for scenario 2ii
        code_friendly_name: foo_bar_code2  # <-- this is the proposal for scenario 2ii
    - id: pprof::foo.bar
      code_generation_hint:                # <-- this is the proposal for scenario 3 
        code_friendly_name: pprof_foo_bar  # <-- this is the proposal for scenario 3 

Alternative proposal

- id: registry.foo
  ...
  attributes:
    - id: foo.bar_id
      deprecated:                         # not in the scope of this item
        action: rename
        renamed_to: foo.bar.id
      code_generation_hint: exclude       # <-- this is the proposal for scenarios 1 and 2i above
    - id: pprof::foo.bar
      code_friendly_name:  pprof_foo_bar  # <-- this is the proposal for scenario 2ii & 3 

@lmolkova
Copy link
Contributor Author

lmolkova commented Oct 9, 2024

The following policies will be necessary:

  • code_generator: action: remove or alternatives MUST NOT appear on stable things.
  • if code_friendly_name is not set, it's considered to be {id}.replace('.', '_') and MUST NOT change for experimental or stable things in the future version (i.e. code_friendly_name can be specified once at the attribute creation time (or within the same version attribute was defined)
  • Same with code_generation_hint: action: exclude or alternatives - it SHOULD NOT be changed for existing attributes. Except current exceptions -
    excluded_const_collisions := {"messaging.client_id"}

@lmolkova
Copy link
Contributor Author

Based on the discussions on slack there is a preference for option 1:

      code_generation_hint: 
        action: exclude
        code_friendly_name: <>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tooling Regarding build, workflows, build-tools, ...
Projects
Development

No branches or pull requests

2 participants