-
Notifications
You must be signed in to change notification settings - Fork 55
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
Events for c8y are consumed from te/+/+/+/+/e/+ #2221
Events for c8y are consumed from te/+/+/+/+/e/+ #2221
Conversation
@@ -21,13 +21,13 @@ Child devices support sending custom measurements | |||
|
|||
|
|||
Child devices support sending custom events | |||
Execute Command tedge mqtt pub tedge/events/myCustomType1/${CHILD_SN} '{ "text": "Some test event", "someOtherCustomFragment": {"nested":{"value": "extra info"}} }' | |||
Execute Command tedge mqtt pub te/device/${CHILD_SN}///e/myCustomType1 '{ "text": "Some test event", "someOtherCustomFragment": {"nested":{"value": "extra info"}} }' | |||
${events}= Device Should Have Event/s expected_text=Some test event with_attachment=False minimum=1 maximum=1 type=myCustomType1 fragment=someOtherCustomFragment | |||
Log ${events} | |||
|
|||
|
|||
Child devices support sending custom events overriding the type |
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.
This test gives false-positive to the current main branch. It cannot detect if two "type" fields are added as the test check only if the payload "contains" a type=otherType.
In my opinion, this test can be covered by Rust code as below.
thin-edge.io/crates/extensions/c8y_mapper_ext/src/converter.rs
Lines 1480 to 1496 in 993a7c2
async fn convert_event_use_event_type_from_payload() { | |
let tmp_dir = TempTedgeDir::new(); | |
let (mut converter, _http_proxy) = create_c8y_converter(&tmp_dir).await; | |
let event_topic = "te/device/main///e/topic_event"; | |
let event_payload = r#"{ ".type": "payload_event", "text": "Someone clicked", "time": "2020-02-02T01:02:03+05:30" }"#; | |
let event_message = Message::new(&Topic::new_unchecked(event_topic), event_payload); | |
let converted_events = converter.convert(&event_message).await; | |
assert_eq!(converted_events.len(), 1); | |
let converted_event = converted_events.get(0).unwrap(); | |
assert_eq!(converted_event.topic.name, "c8y/s/us"); | |
assert_eq!( | |
converted_event.payload_str().unwrap(), | |
r#"400,"payload_event","Someone clicked",2020-02-02T01:02:03+05:30"# | |
); | |
} |
@@ -27,13 +27,13 @@ Thin-edge devices support sending custom measurements | |||
|
|||
|
|||
Thin-edge devices support sending custom events | |||
Execute Command tedge mqtt pub tedge/events/myCustomType1 '{ "text": "Some test event", "someOtherCustomFragment": {"nested":{"value": "extra info"}} }' | |||
Execute Command tedge mqtt pub te/device/main///e/myCustomType1 '{ "text": "Some test event", "someOtherCustomFragment": {"nested":{"value": "extra info"}} }' | |||
${events}= Device Should Have Event/s expected_text=Some test event with_attachment=False minimum=1 maximum=1 type=myCustomType1 fragment=someOtherCustomFragment | |||
Log ${events} | |||
|
|||
|
|||
Thin-edge devices support sending custom events overriding the type |
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.
This test is also giving false-positive.
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.
What is the false positive / how is it a false positive? Is the someOtherCustomFragment
property not included in the event?
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.
Actually the current main branch has a bug. If user publishes an event with type
field in the payload, the mapper creates "type" field twice.
- "type":"myCustomType"
- "type":"otherType"
But the test passed because the test checks if contains type=otherType
.
Here is the trace.
[tedge/events/myCustomType] {"type": "otherType", "text": "Some test event", "someOtherCustomFragment": {"nested":{"value": "extra info"}} }
[c8y/event/events/create] {"type":"myCustomType","time":"2023-09-06T09:29:59.89872988Z","text":"Some test event","type":"otherType","someOtherCustomFragment":{"nested":{"value":"extra info"}}}
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.
Oh, duplicating keys definitely should be avoided, whilst it is not forbidden it is not recommended and it causes massive issues with different libraries (some support duplicate object keys, some don't)..as the JSON spec says The names within an object SHOULD be unique.
@rina23q So is the fix to avoid duplicated keys also included in the PR?
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.
@rina23q So is the fix to avoid duplicated keys also included in the PR?
Yes ofc :) Rust test case convert_event_use_event_type_from_payload_to_c8y_json()
is covering this.
Codecov Report
Additional details and impacted files
|
Robot Results
|
#[tedge_config(example = "tedge/alarms/#,te/+/+/+/+/m/+")] | ||
#[tedge_config(default(value = "te/+/+/+/+/m/+,tedge/alarms/+/+,tedge/alarms/+/+/+,tedge/events/+,tedge/events/+/+,tedge/health/+,tedge/health/+/+"))] | ||
#[tedge_config(example = "tedge/alarms/#,te/+/+/+/+/m/+,te/+/+/+/+/e/+")] | ||
#[tedge_config(default(value = "te/+/+/+/+/m/+,te/+/+/+/+/e/+,tedge/alarms/+/+,tedge/alarms/+/+/+,tedge/health/+,tedge/health/+/+"))] |
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.
Wondering why we're replacing the tedge/events
topics with the te/.../e
topics. Shouldn't they both coexist until we fully stop supporting the tedge/...
topics? Else who will subscribe to the tedge/events
topics and map those messages to their te/.../e
equivalent?
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.
This is the configuration per cloud, so I believe it's safe to replace tedge/events
with te/.../e
topic for only c8y mapper. Still the default config of the aws and az mappers are subscribing to tedge/events
(and tedge/measurements
).
Also, don't miss that tedge-agent converts from tedge/...
topics to te/...
topics. This means c8y-mapper users can still use tedge/events
topics to create events.
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 agent does the translation from tedge/#
to te/#
.
This has been implemented by #2125
"tedge/events/+", | ||
"tedge/events/+/+", |
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.
Seeing these tedge/
topics replaced by the te/
topics, while the former is only deprecated for the next release but not removed, I feel I'm missing something here. Especially since the same was done for tedge/measurements
as well.
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 agent does the translation from tedge/#
to te/#
.
This has been implemented by #2125
} else { | ||
false | ||
let event_type = match event_type.is_empty() { | ||
true => DEFAULT_EVENT_TYPE, |
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.
That's new. Earlier this was an error case, reported as a parsing error on tedge/errors
topic. It was different for tedge/measurements
as the type wasn't mandatory for it. But for events and alarms, the type
was mandatory. So I hope this was intentional. @reubenmiller could you confirm?
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.
Yes having a default type used for events will useful as it makes it easier to publish an event, and it aligns with the measurement type handling so it makes for a nice and consistent API.
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.
And I'm pretty sure no one is actually subscribing to the tedge/errors
topics, so usually they just wonder why the event is not being published.
* If input event type is empty, the converter uses "ThinEdgeEvent" as the event type. * Event converter uses entity store and no longer need to care if a child device is already created. Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
993a7c2
to
6332046
Compare
// If the message doesn't contain any fields other than `text` and `time`, convert to SmartREST | ||
let message = if c8y_event.extras.is_empty() { | ||
let smartrest_event = Self::serialize_to_smartrest(&c8y_event)?; | ||
let smartrest_topic = Topic::new_unchecked(SMARTREST_PUBLISH_TOPIC); | ||
Message::new(&smartrest_topic, smartrest_event) | ||
} else { | ||
// If the message contains extra fields other than `text` and `time`, convert to Cumulocity JSON | ||
let cumulocity_event_json = serde_json::to_string(&c8y_event)?; | ||
let json_mqtt_topic = Topic::new_unchecked(C8Y_JSON_MQTT_EVENTS_TOPIC); | ||
Message::new(&json_mqtt_topic, cumulocity_event_json) | ||
}; |
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.
We agreed offline to simplify this by systematically publishing the events over the c8y json topic. This will be done in a follow-up PR, though.
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.
Approved. Thank you
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.
Looks good, though do we have a robot test case to cover publishing without the type in the topic?
Robot case no. But I added the case to Rust Updated: Now two robot tests are added to cover it.
|
e9feb77
to
55d2306
Compare
Replace `tedge/events/#` topics used in Robot Framework tests for c8y-mapper by `te/+/+/+/+/e/+`. Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
55d2306
to
8f6d256
Compare
Proposed changes
Events for c8y should be consumed from the mqtt topic
te/+/+/+/+/e/+
instead oftedge/events/#
.Types of changes
Paste Link to the issue
#2214
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments