-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add http usage publisher using rpc, update readme
- Loading branch information
Showing
9 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import urllib3 | ||
from . import tenant_usage_pb2 | ||
|
||
|
||
usage_endpoint = os.getenv('HTTP_PUBLISHER_ENDPOINT', None) | ||
|
||
timeout = urllib3.Timeout(connect=2.0, read=7.0) | ||
HTTP = urllib3.PoolManager(timeout=timeout) | ||
|
||
|
||
def publish_to_http(usage_event: dict): | ||
event = tenant_usage_pb2.TenantUsage() | ||
event.datetime = usage_event['datetime'] | ||
event.dev_eui = usage_event['dev_eui'] | ||
event.tenant_id = usage_event['tenant_id'] | ||
event.application_id = usage_event['application_id'] | ||
event.dc_used = usage_event['dc_used'] | ||
payload = event.SerializeToString() | ||
|
||
r = HTTP.request( | ||
'POST', | ||
usage_endpoint, | ||
body=payload, | ||
headers={'Content-Type': 'application/octet-stream'} | ||
) | ||
return r |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from google.protobuf import descriptor as _descriptor | ||
from google.protobuf import message as _message | ||
from typing import ClassVar as _ClassVar, Optional as _Optional | ||
|
||
DESCRIPTOR: _descriptor.FileDescriptor | ||
|
||
class TenantUsage(_message.Message): | ||
__slots__ = ["datetime", "dev_eui", "tenant_id", "application_id", "dc_used"] | ||
DATETIME_FIELD_NUMBER: _ClassVar[int] | ||
DEV_EUI_FIELD_NUMBER: _ClassVar[int] | ||
TENANT_ID_FIELD_NUMBER: _ClassVar[int] | ||
APPLICATION_ID_FIELD_NUMBER: _ClassVar[int] | ||
DC_USED_FIELD_NUMBER: _ClassVar[int] | ||
datetime: str | ||
dev_eui: str | ||
tenant_id: str | ||
application_id: str | ||
dc_used: int | ||
def __init__(self, datetime: _Optional[str] = ..., dev_eui: _Optional[str] = ..., tenant_id: _Optional[str] = ..., application_id: _Optional[str] = ..., dc_used: _Optional[int] = ...) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! | ||
"""Client and server classes corresponding to protobuf-defined services.""" | ||
import grpc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters