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(generators): Add Chrome svc generator of Kafka messages #125

Merged
merged 6 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions opl/generators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ messages (HBI output messages).
Used to generate HBI input messages, but with correct template it
can generate various things. Please check existing templates:

* `opl/generators/inventory_ingress_InvGitUtilsPayload_template.json.j2` -
template based on HBI git example file for usual HBI input message
* `opl/generators/inventory_ingress_RHSM_template.json.j2` - template
for RHSM Conduit messages
* `opl/generators/inventory_ingress_yupana_template.json.j2` - template
used in `QPCTarballGenerator` for yupana host records
* `opl/generators/inventory_ingress_InvGitUtilsPayload_template.json.j2` -
template based on HBI git example file for usual HBI input message
* `opl/generators/inventory_ingress_RHSM_template.json.j2` - template
for RHSM Conduit messages
* `opl/generators/inventory_ingress_yupana_template.json.j2` - template
used in `QPCTarballGenerator` for yupana host records

When you iterate through the generator, it return's `count` of touples
with random `subscription_manager_id` and dict with full message.
Expand Down Expand Up @@ -101,3 +101,8 @@ Example usage:

tarball.upload()

`chrome_notifications.py`: `ChromeNotificationsGenerator`
---------------------------------------
Generate Chrome notifications Kafka messages.

Just supply the count of messages to be generated.
27 changes: 27 additions & 0 deletions opl/generators/chrome_notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generator of payloads for notifications.drawer messages to the platform.chrome topic.
# sample message:
# echo '{"specversion":"1.0.2","type":"notifications.drawer","source":"https://whatever.service.com","id":"test-message","time":"2023-05-23T11:54:03.879689005+02:00","datacontenttype":"application/json","data":{"broadcast":true,"payload":{"id":"foo.bar.1","description":"string","title":"string","created":"2023-05-23T11:54:03.879689005+02:00","read":false,"source":"string"}}}'

import opl.gen
import opl.generators.packages
import opl.generators.generic


class ChromeNotificationsGenerator(opl.generators.generic.GenericGenerator):
def __init__(
self,
count=100,
template="chrome_notifications_template.json.j2",
):
super().__init__(count=count, template=template, dump_message=False)

def _mid(self, data):
return data["id"]

def _data(self):
return {
"id": self._get_uuid(),
"payload_id": self._get_uuid(),
"time": self._get_now_iso(),
"title": "totallyrandomtitle",
}
19 changes: 19 additions & 0 deletions opl/generators/chrome_notifications_template.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"specversion": "1.0.2",
"type": "notifications.drawer",
"source": "https://whatever.service.com",
"id": "{{ id }}",
"time": "{{ time }}",
"datacontenttype": "application/json",
"data": {
"broadcast": true,
"payload": {
"id": "{{ payload_id }}",
"description": "string",
"title": "{{ title }}",
"created": "{{ time }}",
"read": false,
"source": "string"
}
}
}
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
description="Our performance library",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/TODO/TODO",
url="https://github.com/redhat-performance/opl",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
Expand Down Expand Up @@ -62,6 +62,7 @@
"installed_services.txt",
"running_processes.txt",
"yum_repos.txt",
"chrome_notifications_template.json.j2",
],
"opl.investigator": [
"sample_config.yaml",
Expand Down
Loading