Skip to content

Commit

Permalink
fixes for black, flake8, isort, logging wording fix (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
sepulworld authored Jun 25, 2022
1 parent be920eb commit 3566583
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/dinghy-ping/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
43 changes: 25 additions & 18 deletions dinghy_ping/services/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -309,7 +316,7 @@ def _http_check(url, headers):
response_text,
response_time_ms,
response_headers,
request_url
request_url,
)


Expand All @@ -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",
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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
Expand Down
42 changes: 31 additions & 11 deletions dinghy_ping/services/forms.py
Original file line number Diff line number Diff line change
@@ -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')

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")

0 comments on commit 3566583

Please sign in to comment.