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

Refactor has_logs utility #8123

Merged
merged 1 commit into from
Dec 11, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
from ...utils import (
complete_valid_checks,
get_check_file,
get_config_file,
get_data_directory,
get_readme_file,
get_testable_checks,
get_valid_integrations,
has_dashboard,
has_e2e,
has_logs,
is_tile_only,
)
from ..console import CONTEXT_SETTINGS, abort, echo_info
Expand Down Expand Up @@ -72,18 +71,11 @@ def catalog(checks, out_file, markdown):
integration_catalog = []

for check in sorted(checks):
has_logs = False
is_prometheus = False
is_http = False
has_metadata = False
tile_only = is_tile_only(check)

if not is_tile_only:
config_file = get_config_file(check)
with open(config_file) as f:
if '# logs:' in f.read():
has_logs = True

check_file = get_check_file(check)
if os.path.exists(check_file):
with open(check_file) as f:
Expand All @@ -95,16 +87,10 @@ def catalog(checks, out_file, markdown):
if 'self.set_metadata' in contents:
has_metadata = True

readme_file = get_readme_file(check)
if not has_logs and os.path.exists(readme_file):
with open(readme_file) as f:
if '# Log collection' in f.read():
has_logs = True

entry = {
'name': check,
'has_dashboard': has_dashboard(check),
'has_logs': has_logs,
'has_logs': has_logs(check),
'is_jmx': os.path.exists(os.path.join(get_data_directory(check), 'metrics.yaml')),
'is_prometheus': is_prometheus,
'is_http': is_http,
Expand Down
14 changes: 14 additions & 0 deletions datadog_checks_dev/datadog_checks/dev/tooling/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,20 @@ def has_dashboard(check):
return os.path.isdir(dashboards_path) and len(os.listdir(dashboards_path)) > 0


def has_logs(check):
config_file = get_config_file(check)
if os.path.exists(config_file):
with open(config_file, 'r', encoding='utf-8') as f:
if '# logs:' in f.read():
return True

readme_file = get_readme_file(check)
if os.path.exists(readme_file):
with open(readme_file, 'r', encoding='utf-8') as f:
if '# Log collection' in f.read():
return True


def find_legacy_signature(check):
"""
Validate that the given check does not use the legacy agent signature (contains agentConfig)
Expand Down
24 changes: 7 additions & 17 deletions docs/developer/.scripts/33_render_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
get_readme_file,
get_valid_checks,
get_valid_integrations,
has_logs,
has_agent_8_check_signature,
has_dashboard,
has_e2e,
Expand Down Expand Up @@ -168,28 +169,17 @@ def render_logs_progress():

for check in valid_checks:
status = None
has_logs = False
tile_only = is_tile_only(check)
check_has_logs = has_logs(check)

if not tile_only:
status = ' '
config_file = get_config_file(check)
if check_has_logs:
status = 'X'
checks_with_logs += 1

with open(config_file, 'r', encoding='utf-8') as f:
if '# logs:' in f.read():
status = 'X'
checks_with_logs += 1
has_logs = True

if not has_logs:
readme_file = get_readme_file(check)
if os.path.exists(readme_file):
with open(readme_file, 'r', encoding='utf-8') as f:
if '# Log collection' in f.read():
status = 'X'
checks_with_logs += 1
if status != 'X' and tile_only:
total_checks -= 1 # we cannot really add log collection to tile only integrations
if status != 'X' and tile_only:
total_checks -= 1 # we cannot really add log collection to tile only integrations

if status is not None:
lines.append(f' - [{status}] {check}')
Expand Down