Skip to content
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
35 changes: 33 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,39 @@ exclude =
__pycache__,
docs,
.idea,
venv
venv,
out,
scripts,
max-line-length = 120
per-file-ignores =
# ignore unused imports in __init__ files
*/__init__.py: F401
*/__init__.py: F401
# supress some docstring requirements in tests
test/__init__.py: D104
test/test_deep/__init__.py: D104
test/test_deep/*/__init__.py: D104,D107
test/test_deep/*/test_*.py: D101,D102,D107,D100,D105
test/test_deep/test_*.py: D101,D102,D107,D100,D105
test/test_deep/test_target.py: D102,D107,D103
# these files are from OTEL so should use OTEL license.
*/deep/api/types.py: NCF102
*/deep/api/resource/__init__.py: NCF102
*/deep/api/attributes/__init__.py: NCF102

detailed-output = True
copyright-regex =
'# Copyright \(C\) [0-9]{4} Intergral GmbH'
'#'
'# This program is free software: you can redistribute it and/or modify'
'# it under the terms of the GNU Affero General Public License as published by'
'# the Free Software Foundation, either version 3 of the License, or'
'# \(at your option\) any later version.'
'#'
'# This program is distributed in the hope that it will be useful,'
'# but WITHOUT ANY WARRANTY; without even the implied warranty of'
'# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the'
'# GNU Affero General Public License for more details.'
'#'
'# You should have received a copy of the GNU Affero General Public License'
'# along with this program. If not, see <https://www.gnu.org/licenses/>.'
''
7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# main (unreleased)

- **[CHANGE]**: change(build): add doc string check to flake8 [#14](https://github.com/intergral/deep/pull/14) [@Umaaz](https://github.com/Umaaz)
- **[FEATURE]**: feat(logging): initial implementation of log points [#3](https://github.com/intergral/deep/pull/3) [@Umaaz](https://github.com/Umaaz)
- **[BUGFIX]**: feat(api): add api function to register tracepoint directly [#8](https://github.com/intergral/deep/pull/8) [@Umaaz](https://github.com/Umaaz)

# 1.0.1 (22/06/2023)

- **[BUGFIX]**: fix(config): correct env name on look up [#1](https://github.com/intergral/deep/pull/1) [@Umaaz](https://github.com/Umaaz)

<!-- Template START
# 0.1.1 (16/06/2023)

- **[CHANGE]**: description [#PRid](https://github.com/intergral/deep/pull/8) [@user](https://github.com/)
- **[FEATURE]**: description [#PRid](https://github.com/intergral/deep/pull/) [@user](https://github.com/)
- **[ENHANCEMENT]**: description [#PRid](https://github.com/intergral/deep/pull/) [@user](https://github.com/)
- **[BUGFIX]**: description [#PRid](https://github.com/intergral/deep/pull/) [@user](https://github.com/)
Template END -->
5 changes: 4 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ pdoc3
mkdocstrings-python
build
twine
certifi>=2023.7.22 # not directly required, pinned by Snyk to avoid a vulnerability
flake8-docstrings
certifi>=2023.7.22 # not directly required, pinned by Snyk to avoid a vulnerability
flake8-header-validator>=0.0.3
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
11 changes: 11 additions & 0 deletions dev/test-server/src/test-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""This is a basic example of setting up a GRPC server to consume Deep protobuf messages."""

from concurrent import futures

Expand All @@ -23,6 +28,7 @@


def serve():
"""Set up and start a GRPC service on port 43315 to server Deep clients."""
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

deepproto.proto.poll.v1.poll_pb2_grpc.add_PollConfigServicer_to_server(
Expand All @@ -34,14 +40,19 @@ def serve():


class SnapshotServicer(SnapshotServiceServicer):
"""Create class to handle snapshot send events."""

def send(self, request, context):
"""Receive and process a snapshot request."""
print("hit", request.ID, request.attributes)
return SnapshotResponse()


class PollServicer(PollConfigServicer):
"""Create a class to handle poll requests."""

def poll(self, request, context):
"""Receive and process poll requests."""
print(request, context, context.invocation_metadata())
response = PollResponse(ts_nanos=request.ts_nanos, current_hash="123", response=[
TracePointConfig(ID="17", path="/simple-app/simple_test.py", line_number=31,
Expand Down
43 changes: 43 additions & 0 deletions examples/simple-app-custom-logging/src/simple-app/base_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (C) 2023 Intergral GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""A simple test object for examples."""

import random
import uuid


class BaseTest:
"""A basic test that is used in examples."""

def new_id(self):
"""Create new id."""
return str(uuid.uuid4())

def next_max(self):
"""Create new random max."""
return random.randint(1, 101)

def make_char_count_map(self, in_str):
"""Create char count map."""
res = {}

for i in range(0, len(in_str)):
c = in_str[i]
if c not in res:
res[c] = 0
else:
res[c] = res[c] + 1
return res
39 changes: 39 additions & 0 deletions examples/simple-app-custom-logging/src/simple-app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,53 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""Simple Example of using Deep, with custom log config."""
import os
import signal
import time

import deep
from simple_test import SimpleTest


class GracefulKiller:
"""Ensure clean shutdown."""

kill_now = False

def __init__(self):
"""Crate new killer."""
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)

def exit_gracefully(self, *args):
"""Exit example."""
self.kill_now = True


def main():
"""Run the example."""
killer = GracefulKiller()
ts = SimpleTest("This is a test")
while not killer.kill_now:
try:
ts.message(ts.new_id())
except BaseException as e:
print(e)
ts.reset()

time.sleep(0.1)


if __name__ == '__main__':
deep.start({
'SERVICE_URL': 'localhost:43315',
'LOGGING_CONF': "%s/logging.conf" % os.path.dirname(os.path.realpath(__file__))
})

print("app running")
main()
73 changes: 73 additions & 0 deletions examples/simple-app-custom-logging/src/simple-app/simple_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (C) 2023 Intergral GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""A simple test object for examples."""

import time

from base_test import BaseTest


class SimpleTest(BaseTest):
"""A basic test that is used in examples."""

def __init__(self, test_name):
"""Create new test object."""
super().__init__()
self._started_at = round(time.time() * 1000)
self.__cnt = 0
self.char_counter = {}
self.test_name = test_name
self.max_executions = self.next_max()

def message(self, uuid):
"""Print message to console."""
print("%s:%s" % (self.__cnt, uuid))
self.__cnt += 1
self.check_end(self.__cnt, self.max_executions)

info = self.make_char_count_map(uuid)
self.merge(self.char_counter, info)
if self.__cnt % 30 == 0:
self.dump()

def merge(self, char_counter, new_info):
"""Merge captured data."""
for key in new_info:
new_val = new_info[key]

if key not in char_counter:
char_counter[key] = new_val
else:
char_counter[key] = new_val + char_counter[key]

def dump(self):
"""Dump message to console."""
print(self.char_counter)
self.char_counter = {}

def check_end(self, value, max_executions):
"""Check if we are at end."""
if value > max_executions:
raise Exception("Hit max executions %s %s " % (value, max_executions))

def __str__(self) -> str:
"""Represent this as a string."""
return self.__class__.__name__ + ":" + self.test_name + ":" + str(self._started_at)

def reset(self):
"""Reset the count."""
self.__cnt = 0
self.max_executions = self.next_max()
9 changes: 9 additions & 0 deletions examples/simple-app-docker/src/simple-app/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""A simple test object for examples."""

import random
import uuid


class BaseTest:
"""A basic test that is used in examples."""

def new_id(self):
"""Create new id."""
return str(uuid.uuid4())

def next_max(self):
"""Create new random max."""
return random.randint(1, 101)

def make_char_count_map(self, in_str):
"""Create char count map."""
res = {}

for i in range(0, len(in_str)):
Expand Down
13 changes: 12 additions & 1 deletion examples/simple-app-docker/src/simple-app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2023 Intergral GmbH
# Copyright (C) 2024 Intergral GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand All @@ -9,6 +9,12 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""Simple Example of using Deep."""

import signal
import time

Expand All @@ -17,17 +23,22 @@


class GracefulKiller:
"""Ensure clean shutdown."""

kill_now = False

def __init__(self):
"""Crate new killer."""
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)

def exit_gracefully(self, *args):
"""Exit example."""
self.kill_now = True


def main():
"""Run the example."""
killer = GracefulKiller()
ts = SimpleTest("This is a test")
while not killer.kill_now:
Expand Down
Loading