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: Add device attributes to ApplicationUp messages #7451

Draft
wants to merge 16 commits into
base: v3.33
Choose a base branch
from

Conversation

vlasebian
Copy link
Contributor

@vlasebian vlasebian commented Dec 19, 2024

Summary

References #5879

Changes

  • Add attributes field to ApplicationUplink
  • Add attributes field to ApplicationUplinkNormalized
  • Add locations, version_ids, network_ids and attributes fields to ApplicationJoinAccept
  • Add locations, version_ids, network_ids and attributes fields to ApplicationDownlink
  • Add locations, version_ids, network_ids and attributes fields to ApplicationDownlinkFailed
  • Add locations, version_ids, network_ids and attributes fields to ApplicationInvalidatedDownlinks
  • Add locations, version_ids, network_ids and attributes fields to ApplicationServiceData
  • Add attributes registry cache implementation
  • Implement attributes metadata registry
  • Add attributes registry config
  • Enrich uplinks with end device attributes

Testing

Steps
  • Launch a local TTS instance
  • Connect a gateway to the local instance
  • Create an application
  • Register an end device in the application
  • Go to the settings of the end device and add some attributes
  • Go to the integrations of the application and create a web hook (e.g. with webhook.site)
  • Check the messages in the live data panel of the console
  • Check the webhooks sent to the third party
Results

Join-accept:

Screenshot 2025-01-07 at 17 12 02
Screenshot 2025-01-07 at 17 13 35

Uplink:

Screenshot 2025-01-07 at 17 14 01
Screenshot 2025-01-07 at 17 12 20

Regressions

...

Notes for Reviewers

...

Checklist

  • Scope: The referenced issue is addressed, there are no unrelated changes.
  • Compatibility: The changes are backwards compatible with existing API, storage, configuration and CLI, according to the compatibility commitments in README.md for the chosen target branch.
  • Documentation: Relevant documentation is added or updated.
  • Testing: The steps/process to test this feature are clearly explained including testing for regressions.
  • Infrastructure: If infrastructural changes (e.g., new RPC, configuration) are needed, a separate issue is created in the infrastructural repositories.
  • Changelog: Significant features, behavior changes, deprecations and fixes are added to CHANGELOG.md.
  • Commits: Commit messages follow guidelines in CONTRIBUTING.md, there are no fixup commits left.

@vlasebian vlasebian changed the title api: Add device attributes to ApplicationUp messages feat: Add device attributes to ApplicationUp messages Dec 19, 2024
@vlasebian
Copy link
Contributor Author

vlasebian commented Dec 20, 2024

@johanstokking @KrishnaIyer there is a note in the implementation plan that I don't get completely:

[...] a new binary compatible variant of ApplicationDownlink [2]. [..]

[2] ApplicationDownlink is also used during submission, and it does not make much sense to allow users to submit these fields while pushing a downlink.

I understand that this change has to be made as it does not make sense to set these fields when the application sends a downlink to the end device (the fields should be set on end device creation and not modified through uplinks or downlinks).

Does this mean that a whole new message must be defined where these fields are included? Something like:

message EnrichedApplicationDownlink {
  ApplicationDownlink downlinks = 1;
  // End device location metadata, set by the Application Server while handling the message.
  map<string, Location> locations = 3;

  // End device version identifiers, set by the Application Server while handling the message.
  EndDeviceVersionIdentifiers version_ids = 4;

  // Network identifiers, set by the Network Server that handles the message.
  NetworkIdentifiers network_ids = 5;

  // Attributes for devices, set by the Application Server while handling the message.
  map<string, string> attributes = 6 [(validate.rules).map = {
    max_pairs: 10,
    keys: {
      string: {
        pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$",
        max_len: 36
      }
    },
    values: {
      string: {max_len: 200}
    }
  }];

  // next: 7
}

And by binary compatible variant, does that mean serialisable?

@vlasebian vlasebian self-assigned this Dec 23, 2024
@johanstokking
Copy link
Member

Does this mean that a whole new message must be defined where these fields are included?

No, these can be part of the existing message. We use comments to indicate which component sets them.

Also, we can use pkg/ttnpb.ProhibitFields() to validate incoming requests, e.g. pass the fields that may not be set when pushing/replacing downlink and return the error back to the client if they're part of the field mask.

@vlasebian vlasebian force-pushed the feature/5879-device-attributes branch from 04e15dd to 54c9a07 Compare January 3, 2025 10:55
@github-actions github-actions bot added c/application server This is related to the Application Server compat/db This could affect Database compatibility compat/config This could affect Configuration compatibility labels Jan 7, 2025
@vlasebian vlasebian force-pushed the feature/5879-device-attributes branch from 6890128 to 5eeda26 Compare January 7, 2025 14:47
@vlasebian vlasebian marked this pull request as ready for review January 8, 2025 12:39
@vlasebian vlasebian requested review from a team as code owners January 8, 2025 12:39
@vlasebian vlasebian requested a review from a team as a code owner January 8, 2025 14:20
@github-actions github-actions bot added the ui/web This is related to a web interface label Jan 8, 2025
@vlasebian vlasebian force-pushed the feature/5879-device-attributes branch from 4de08b9 to 557efe3 Compare January 8, 2025 14:43
@vlasebian
Copy link
Contributor Author

I see that the downlink replace and the downlink push both use the same request which does not contain a field mask:

message DownlinkQueueRequest {
  EndDeviceIdentifiers end_device_ids = 1 [(validate.rules).message.required = true];
  repeated ApplicationDownlink downlinks = 2 [(validate.rules).repeated.max_items = 100000];
}

However, looking through the code, most of the .Set methods have hardcoded paths, so it should be fine not adding a FieldMask and the corresponding ProhibitField call right?

Also, I noticed that the attributes are saved in the entity registry (that belongs to the IS) which is different than the device registry (that belongs to the AS), is that right? I saw that the locations are also saved in the entity registry. I followed the location registry implementation to fetch the attributes, but only implemented the get call as no set should happened for the attributes in the message handlers.

Let me know if this is okay.

@vlasebian vlasebian marked this pull request as draft January 8, 2025 15:45
@johanstokking
Copy link
Member

However, looking through the code, most of the .Set methods have hardcoded paths, so it should be fine not adding a FieldMask and the corresponding ProhibitField call right?

Yes

Also, I noticed that the attributes are saved in the entity registry (that belongs to the IS) which is different than the device registry (that belongs to the AS), is that right? I saw that the locations are also saved in the entity registry. I followed the location registry implementation to fetch the attributes, but only implemented the get call as no set should happened for the attributes in the message handlers.

Indeed this information is stored in IS, and that has been the main reason we didn't put these fields in the upstream messages: it would require an IS roundtrip. In our global deployments, these are cross-continental roundtrips, delaying uplink messages, increasing memory usage, etc.

So indeed, like location, AS should fetch this from IS in a similar way. These should be combined in one call otherwise there are two sequential roundtrips and that's even worse.

@vlasebian
Copy link
Contributor Author

Okay, got it. I'll refactor the location and attributes calls into one 👍

@github-actions github-actions bot added the c/network server This is related to the Network Server label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/application server This is related to the Application Server c/network server This is related to the Network Server compat/config This could affect Configuration compatibility compat/db This could affect Database compatibility ui/web This is related to a web interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants