From 356658310a039e2813be64783b813999a34283f6 Mon Sep 17 00:00:00 2001 From: Zane Williamson Date: Fri, 24 Jun 2022 17:37:38 -0700 Subject: [PATCH] fixes for black, flake8, isort, logging wording fix (#106) --- CHANGELOG.md | 5 ++++ charts/dinghy-ping/Chart.yaml | 2 +- dinghy_ping/services/api.py | 43 ++++++++++++++++++++--------------- dinghy_ping/services/forms.py | 42 +++++++++++++++++++++++++--------- 4 files changed, 62 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 461cd83..763f9f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ This file is used to list changes made in each version of the Dinghy-ping ## unreleased +## v1.2.1 (2022-06-24) +- [Zane] + - black, isort, flake8 fixes + - fixing event log stream logging wording, remove asyncio reference + ## v1.2.0 (2022-06-24) - [Zane] - Use wtform validations diff --git a/charts/dinghy-ping/Chart.yaml b/charts/dinghy-ping/Chart.yaml index 6807d4c..ce4c192 100644 --- a/charts/dinghy-ping/Chart.yaml +++ b/charts/dinghy-ping/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v1 -appVersion: "v1.2.0" +appVersion: "v1.2.1" description: A Helm chart for dinghy-ping name: dinghy-ping version: 0.4.13 diff --git a/dinghy_ping/services/api.py b/dinghy_ping/services/api.py index 1847556..31d7730 100644 --- a/dinghy_ping/services/api.py +++ b/dinghy_ping/services/api.py @@ -2,23 +2,23 @@ import json import logging import os +import socket import sys import time -import socket import traceback from urllib.parse import urlparse import datadog import dns.rdatatype from ddtrace import patch, tracer -from flask import Flask, url_for, redirect, jsonify, make_response, render_template, request +from flask import Flask, jsonify, make_response, render_template, request from flask_sock import Sock from kubernetes import client, config, watch from kubernetes.client.rest import ApiException from dinghy_ping.models import dinghy_dns from dinghy_ping.models.data import DinghyData -from dinghy_ping.services.forms import HTTPCheckForm, DNSCheckForm, TCPCheckForm +from dinghy_ping.services.forms import DNSCheckForm, HTTPCheckForm, TCPCheckForm patch(requests=True) import requests # noqa @@ -89,7 +89,7 @@ def to_pretty_json(value): ) api.jinja_env.filters["tojson_pretty"] = to_pretty_json sock = Sock(api) -api.config['SECRET_KEY'] = SECRET_KEY +api.config["SECRET_KEY"] = SECRET_KEY config.load_incluster_config() initialize_datadog() @@ -147,16 +147,22 @@ def dinghy_html(): if http_form.validate_on_submit(): url = http_form.url.data headers = http_form.headers.data - response_code, response_text, response_time_ms, response_headers, request_url = _http_check(url, headers) + ( + response_code, + response_text, + response_time_ms, + response_headers, + request_url, + ) = _http_check(url, headers) return render_template( "ping_response.html", - request=request_url, - domain_response_code=response_code, - domain_response_text=response_text, - domain_response_headers=response_headers, - domain_response_time_ms=response_time_ms, + request=request_url, + domain_response_code=response_code, + domain_response_text=response_text, + domain_response_headers=response_headers, + domain_response_time_ms=response_time_ms, ) - + if dns_form.validate_on_submit(): domain = dns_form.domain.data nameserver = dns_form.nameserver.data @@ -181,13 +187,14 @@ def dinghy_html(): port=tcp_port, connection_results=conn_info, ) - + return render_template( "index.html", http_form=http_form, dns_form=dns_form, tcp_form=tcp_form, - get_all_pinged_urls=get_all_pinged_urls) + get_all_pinged_urls=get_all_pinged_urls, + ) @api.route("/ping/domains") @@ -309,7 +316,7 @@ def _http_check(url, headers): response_text, response_time_ms, response_headers, - request_url + request_url, ) @@ -323,7 +330,7 @@ def _tcp_check(tcp_endpoint, tcp_port): s.settimeout(deadline - time.time()) s.connect((tcp_endpoint, tcp_port)) conn_info = f"Connection created to {tcp_endpoint} on port {tcp_port}" - + d = DinghyData( redis_host, domain_response_code="tcp handshake success", @@ -352,7 +359,7 @@ def _dns_check(domain, nameserver): dns_info_A = _gather_dns_A_info(domain, nameserver) dns_info_NS = _gather_dns_NS_info(domain, nameserver) dns_info_MX = _gather_dns_MX_info(domain, nameserver) - + d = DinghyData( redis_host, domain_response_code=f"dns lookup for {domain} on {nameserver}", @@ -609,10 +616,10 @@ def log_stream_websocket(ws): while True: try: line = resp.readline() - except asyncio.TimeoutError as e: + except Exception as e: logging.error( f""" - Async timeout server side, will recover from client side {e} + issue reading pod logs: {e} """ ) break diff --git a/dinghy_ping/services/forms.py b/dinghy_ping/services/forms.py index 937d91e..a6f17b2 100644 --- a/dinghy_ping/services/forms.py +++ b/dinghy_ping/services/forms.py @@ -1,29 +1,49 @@ from flask_wtf import FlaskForm -from wtforms import StringField, URLField, SubmitField, TextAreaField, IntegerField -from wtforms.validators import DataRequired, Optional +from wtforms import IntegerField, StringField, SubmitField, TextAreaField, URLField +from wtforms.validators import DataRequired, Optional + class HTTPCheckForm(FlaskForm): """ Form for URL input and headers input """ - url = URLField('URL Check', validators=[DataRequired()]) - headers = TextAreaField('Optional Headers', render_kw={"placeholder": '{"Content-Type": "application/json"}'}, validators=[Optional()]) - submit = SubmitField('Ping') + + url = URLField("URL Check", validators=[DataRequired()]) + headers = TextAreaField( + "Optional Headers", + render_kw={"placeholder": '{"Content-Type": "application/json"}'}, + validators=[Optional()], + ) + submit = SubmitField("Ping") class TCPCheckForm(FlaskForm): """ Form for IP input and port input """ - tcp_endpoint = StringField('TCP Endpoint Check', validators=[DataRequired()], render_kw={"placeholder": "domain"}) - tcp_port = IntegerField('TCP Port', validators=[DataRequired()], render_kw={"placeholder": "3306"}) - submit = SubmitField('Ping') + + tcp_endpoint = StringField( + "TCP Endpoint Check", + validators=[DataRequired()], + render_kw={"placeholder": "domain"}, + ) + tcp_port = IntegerField( + "TCP Port", validators=[DataRequired()], render_kw={"placeholder": "3306"} + ) + submit = SubmitField("Ping") class DNSCheckForm(FlaskForm): """ Form for domain input """ - domain = StringField('Hostname', validators=[DataRequired()], render_kw={"placeholder": "domain"}) - nameserver = StringField('Optional Nameserver Override', validators=[Optional()], render_kw={"placeholder": "10.96.0.10"}) - submit = SubmitField('Ping') \ No newline at end of file + + domain = StringField( + "Hostname", validators=[DataRequired()], render_kw={"placeholder": "domain"} + ) + nameserver = StringField( + "Optional Nameserver Override", + validators=[Optional()], + render_kw={"placeholder": "10.96.0.10"}, + ) + submit = SubmitField("Ping")