diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..a12e979 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +omit = duetector/cli/* diff --git a/duetector/analyzer/db.py b/duetector/analyzer/db.py index 9450960..df9fdee 100644 --- a/duetector/analyzer/db.py +++ b/duetector/analyzer/db.py @@ -6,6 +6,7 @@ from duetector.analyzer.base import Analyzer from duetector.analyzer.models import AnalyzerBrief, Brief, Tracking from duetector.db import SessionManager +from duetector.log import logger class DBAnalyzer(Analyzer): @@ -140,6 +141,7 @@ def query( if order_by_desc: statm = statm.order_by(*[getattr(m, k).desc() for k in order_by_desc]) + logger.debug(f"Querying {tracer}@{collector_id} with statm: {statm}") with self.sm.begin() as session: r.extend( [ @@ -192,6 +194,7 @@ def _table_brief( m = self.sm.get_tracking_model(tracer, collector_id) if not inspect: + logger.debug(f"Briefing {tracer}@{collector_id} without inspect") return Brief( tracer=tracer, collector_id=collector_id, @@ -209,6 +212,7 @@ def _table_brief( start_statm = statm.order_by(m.dt.asc()) end_statm = statm.order_by(m.dt.desc()) count_statm = select(func.count()).select_from(statm.subquery()) + logger.debug(f"Briefing {tracer}@{collector_id} with statm: {start_statm}") with self.sm.begin() as session: start_tracking = self._convert_row_to_tracking( columns, session.execute(start_statm).first(), tracer @@ -271,6 +275,7 @@ def brief( Returns: AnalyzerBrief: A brief of this analyzer. """ + tables = self.sm.inspect_all_tables() if tracers: tables = [t for t in tables if self.sm.table_name_to_tracer(t) in tracers] diff --git a/duetector/service/query/routes.py b/duetector/service/query/routes.py index e39f544..7700760 100644 --- a/duetector/service/query/routes.py +++ b/duetector/service/query/routes.py @@ -28,7 +28,7 @@ async def root( @r.post("/{analyzer_name}", response_model=QueryResult) async def query( analyzer_name: str, - query_param: QueryBody = Body(), + query_param: QueryBody = Body(default=QueryBody()), controller: AnalyzerController = Depends(get_controller(AnalyzerController)), ): """ diff --git a/tests/config.toml b/tests/config.toml index 5c04b52..72129ac 100644 --- a/tests/config.toml +++ b/tests/config.toml @@ -7,7 +7,7 @@ [filter] disabled = false - +include_extension = true [filter.patternfilter] disabled = false @@ -31,6 +31,16 @@ re_exclude_gcustom = ["ignore_custom*"] [tracer] disabled = false +include_extension = true + +[tracer.clonetracer] +disabled = false +attach_event = "__x64_sys_clone" +poll_timeout = 10 + +[tracer.tcpconnecttracer] +disabled = false +poll_timeout = 10 [tracer.unametracer] disabled = false @@ -38,14 +48,20 @@ enable_cache = true [tracer.opentracer] disabled = false +attach_event = "do_sys_openat2" +poll_timeout = 10 [collector] disabled = false +include_extension = true [collector.dbcollector] disabled = false id = "unittest" +[collector.dbcollector.backend_args] +max_workers = 10 + [collector.dbcollector.db] table_prefix = "duetector_tracking" @@ -57,15 +73,31 @@ disabled = true id = "unittest" maxlen = 1024 +[collector.dequecollector.backend_args] +max_workers = 10 + [monitor.bcc] disabled = false auto_init = true +continue_on_exception = true + +[monitor.bcc.backend_args] +max_workers = 10 + +[monitor.bcc.poller] +interval_ms = 500 [monitor.sh] disabled = false auto_init = true timeout = 5 +[monitor.sh.backend_args] +max_workers = 10 + +[monitor.sh.poller] +interval_ms = 500 + [db_analyzer.db] table_prefix = "duetector_tracking" diff --git a/tests/service/test_query.py b/tests/service/test_query.py new file mode 100644 index 0000000..48378a0 --- /dev/null +++ b/tests/service/test_query.py @@ -0,0 +1,40 @@ +import pytest +from fastapi.testclient import TestClient + +from duetector.analyzer.db import DBAnalyzer +from duetector.service.app import app +from duetector.service.config import get_config + + +@pytest.fixture +def configed_app(full_config): + app.dependency_overrides = {get_config: lambda: full_config} + return app + + +@pytest.fixture +def client(configed_app): + with TestClient(configed_app) as client: + yield client + + +def test_query(client: TestClient): + response = client.get(f"/query/") + assert response.status_code == 200 + assert response.json() == {"analyzers": [DBAnalyzer.config_scope]} + + +def test_query_brief(client: TestClient): + response = client.get(f"/query/{DBAnalyzer.config_scope}/brief") + assert response.status_code == 200 + assert response.json() + + +def test_query_analyzer(client: TestClient): + response = client.post(f"/query/{DBAnalyzer.config_scope}") + assert response.status_code == 200 + assert response.json() + + +if __name__ == "__main__": + pytest.main(["-vv", "-s", __file__]) diff --git a/tests/service/test_token.py b/tests/service/test_token.py index 3bef7b9..bb43ec2 100644 --- a/tests/service/test_token.py +++ b/tests/service/test_token.py @@ -22,3 +22,7 @@ def client(): def test_root(client: TestClient): response = client.get("/", params={"token": "test_token"}) assert response.status_code == 200 + + +if __name__ == "__main__": + pytest.main(["-vv", "-s", __file__]) diff --git a/tests/test_service.py b/tests/test_service.py deleted file mode 100644 index 15c51b9..0000000 --- a/tests/test_service.py +++ /dev/null @@ -1,5 +0,0 @@ -# TODO - - -def test_service(): - pass