Skip to content

Commit 942d3ed

Browse files
committed
fixup! WIP charm daisy
1 parent 44b83bf commit 942d3ed

File tree

10 files changed

+106
-179
lines changed

10 files changed

+106
-179
lines changed

charms/daisy/charmcraft.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: |
99
gather the crash data.
1010
links:
1111
source:
12-
- https://github.com/canonical/error-tracker/tree/main/charms/daisy
12+
- https://github.com/ubuntu/error-tracker/tree/main/charms/daisy
1313

1414
platforms:
1515
@@ -26,7 +26,7 @@ config:
2626
repo-url:
2727
description: |
2828
Address of the git repository to clone
29-
default: "https://github.com/canonical/error-tracker"
29+
default: "https://github.com/ubuntu/error-tracker"
3030
type: string
3131
repo-branch:
3232
description: |

src/daisy/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def validate_and_set_configuration():
9191
aws_secret_key = getattr(config, "aws_secret_key", "")
9292
if not (host and aws_access_key and aws_secret_key):
9393
msg = (
94-
"EC2 provider set but host, bucket, aws_access_key, or"
95-
" aws_secret_key not set."
94+
"EC2 provider set but host, bucket, aws_access_key, or aws_secret_key not set."
9695
)
9796
raise ImportError(msg)
9897
config.storage_write_weights = {"s3": 1.0}
@@ -118,7 +117,7 @@ def validate_and_set_configuration():
118117
if not getattr(config, "storage_write_weights", ""):
119118
d = config.core_storage.get("default", "")
120119
if not d:
121-
msg = "No storage_write_weights set, but no default set in core" " storage"
120+
msg = "No storage_write_weights set, but no default set in core storage"
122121
raise ImportError(msg)
123122
config.storage_write_weights = {d: 1.0}
124123

src/daisy/app.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from flask import Flask, request
2+
3+
from daisy.submit import submit
4+
5+
app = Flask(__name__)
6+
7+
8+
@app.route("/<system_token>", methods=["POST"])
9+
def handle_submit(system_token):
10+
return submit(request, system_token)
11+
12+
13+
def __main__():
14+
app.run(host="0.0.0.0", debug=True)
15+
16+
17+
if __name__ == "__main__":
18+
__main__()

src/daisy/configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@
194194
# Hooks for relations in charms to contribute their configuration settings.
195195
try:
196196
from db_settings import * # noqa: F403
197+
198+
print("Loaded local db settings")
197199
except ImportError:
198200
pass
199201

src/daisy/metrics.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
from cassandra import ConsistencyLevel
2-
from cassandra.auth import PlainTextAuthProvider
3-
from cassandra.cluster import Cluster
4-
5-
from daisy import config
6-
71
METRICS = None
82

93

@@ -34,16 +28,6 @@ def get_metrics(namespace="daisy"):
3428
return METRICS
3529

3630

37-
def cassandra_session():
38-
auth_provider = PlainTextAuthProvider(
39-
username=config.cassandra_username, password=config.cassandra_password
40-
)
41-
cluster = Cluster(config.cassandra_hosts, auth_provider=auth_provider)
42-
cassandra_session = cluster.connect(config.cassandra_keyspace)
43-
cassandra_session.default_consistency_level = ConsistencyLevel.LOCAL_ONE
44-
return cassandra_session
45-
46-
4731
def record_revno(namespace="daisy"):
4832
import socket
4933

src/daisy/submit.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from daisy import config, utils
3434
from daisy.metrics import get_metrics
35+
from errortracker.cassandra import cassandra_session
3536
from oopsrepository import config as oopsconfig
3637
from oopsrepository import oopses
3738

@@ -118,7 +119,10 @@ def try_to_repair_sas(data):
118119
metrics.meter("repair.failed_sas")
119120

120121

121-
def submit(_session, environ, system_token):
122+
def submit(request, system_token):
123+
logger.info("Submit handler")
124+
logger.info(f"request: {request}")
125+
_session = cassandra_session()
122126
# N.B. prepared statements do the hexlify() conversion on their own
123127
global counters_update
124128
if not counters_update:
@@ -131,7 +135,7 @@ def submit(_session, environ, system_token):
131135
'UPDATE "CountersForProposed" SET value = value +1 WHERE key = ? and column1 = ?'
132136
)
133137
try:
134-
data = environ["wsgi.input"].read()
138+
data = request["wsgi.input"].read()
135139
except IOError as e:
136140
if e.message == "request data read error":
137141
# The client disconnected while sending the report.
@@ -156,14 +160,14 @@ def submit(_session, environ, system_token):
156160

157161
# Keep a reference to the decoded report data. If we crash, we'll
158162
# potentially attach it to the OOPS report.
159-
environ["wsgi.input.decoded"] = data
163+
request["wsgi.input.decoded"] = data
160164

161165
oops_id = str(uuid.uuid1())
162166

163167
# In theory one should be able to use map_environ with make_app in
164168
# oops_wsgi to write arbitary data to the OOPS report but I couldn't get
165169
# that to work so cheat and uses HTTP_ which always gets written.
166-
environ["HTTP_Z_CRASH_ID"] = oops_id
170+
request["HTTP_Z_CRASH_ID"] = oops_id
167171

168172
day_key = time.strftime("%Y%m%d", time.gmtime())
169173

@@ -184,10 +188,8 @@ def submit(_session, environ, system_token):
184188
# we want to try and find out which releases are sending reports with
185189
# a missing SystemIdentifier
186190
try:
187-
whoopsie_version = environ["HTTP_X_WHOOPSIE_VERSION"]
188-
metrics.meter(
189-
"missing.missing_system_token_%s" % whoopsie_version.replace(".", "_")
190-
)
191+
whoopsie_version = request["HTTP_X_WHOOPSIE_VERSION"]
192+
metrics.meter("missing.missing_system_token_%s" % whoopsie_version.replace(".", "_"))
191193
except KeyError:
192194
pass
193195
metrics.meter("missing.missing_system_token")
@@ -224,10 +226,9 @@ def submit(_session, environ, system_token):
224226
if crash_id in reported_crash_ids:
225227
return (False, "Crash already reported.")
226228
try:
227-
whoopsie_version = environ["HTTP_X_WHOOPSIE_VERSION"]
229+
whoopsie_version = request["HTTP_X_WHOOPSIE_VERSION"]
228230
metrics.meter(
229-
"invalid.duplicate_report.whoopise_%s"
230-
% whoopsie_version.replace(".", "_")
231+
"invalid.duplicate_report.whoopise_%s" % whoopsie_version.replace(".", "_")
231232
)
232233
except KeyError:
233234
pass
@@ -248,9 +249,9 @@ def submit(_session, environ, system_token):
248249
# wonky with apport
249250
src_package = data.get("SourcePackage", "")
250251
src_package = src_package.encode("ascii", errors="replace")
251-
environ["HTTP_Z_SRC_PKG"] = src_package
252+
request["HTTP_Z_SRC_PKG"] = src_package
252253
problem_type = data.get("ProblemType", "")
253-
environ["HTTP_Z_PROBLEMTYPE"] = problem_type
254+
request["HTTP_Z_PROBLEMTYPE"] = problem_type
254255
apport_version = data.get("ApportVersion", "")
255256
third_party = False
256257
if not utils.retraceable_package(package):
@@ -286,7 +287,7 @@ def submit(_session, environ, system_token):
286287
return (True, "Crash report successfully submitted.")
287288

288289
package, version = utils.split_package_and_version(package)
289-
environ["HTTP_Z_PKG"] = package
290+
request["HTTP_Z_PKG"] = package
290291
# src_version is None and is never used, nor should it be.
291292
src_package, src_version = utils.split_package_and_version(src_package)
292293
fields = utils.get_fields_for_bucket_counters(
@@ -297,9 +298,7 @@ def submit(_session, environ, system_token):
297298
# phased-updater and only includes official Ubuntu packages and not those
298299
# crahses from systems under auto testing.
299300
if not third_party and not automated_testing and problem_type == "Crash":
300-
update_counters(
301-
_session, release=release, src_package=src_package, date=day_key
302-
)
301+
update_counters(_session, release=release, src_package=src_package, date=day_key)
303302
if version == "":
304303
metrics.meter("missing.missing_package_version")
305304
else:
@@ -359,9 +358,7 @@ def submit(_session, environ, system_token):
359358
if utils.blocklisted_device(system_token):
360359
# If the device stops appearing in the log file then the offending
361360
# crash file may have been removed and it could be unblocklisted.
362-
logger.info(
363-
"Blocklisted device %s disallowed from sending a crash." % system_token
364-
)
361+
logger.info("Blocklisted device %s disallowed from sending a crash." % system_token)
365362
return (False, "Device blocked from sending crash reports.")
366363

367364
try:
@@ -382,9 +379,7 @@ def submit(_session, environ, system_token):
382379
msg = "%s: WriteTimeout with %s keys." % (system_token, len(list(data.keys())))
383380
logger.info(msg)
384381
logger.info("%s: The keys are %s" % (system_token, list(data.keys())))
385-
logger.info(
386-
"%s: The crash has a ProblemType of: %s" % (system_token, problem_type)
387-
)
382+
logger.info("%s: The crash has a ProblemType of: %s" % (system_token, problem_type))
388383
if "Traceback" in data:
389384
logger.info("%s: The crash has a python traceback." % system_token)
390385
raise
@@ -477,9 +472,7 @@ def bucket(_session, oops_config, oops_id, data, day_key):
477472
stacktrace = False
478473
if cql_addr_sig:
479474
try:
480-
stacktraces = _session.execute(
481-
stacktrace_select, [cql_addr_sig, "Stacktrace"]
482-
)
475+
stacktraces = _session.execute(stacktrace_select, [cql_addr_sig, "Stacktrace"])
483476
stacktrace = [stacktrace[0] for stacktrace in stacktraces][0]
484477
threadstacktraces = _session.execute(
485478
stacktrace_select, [cql_addr_sig, "ThreadStacktrace"]
@@ -506,9 +499,7 @@ def bucket(_session, oops_config, oops_id, data, day_key):
506499
# The crash is a duplicate so we don't need this data.
507500
# Stacktrace, and ThreadStacktrace were already not accepted
508501
if "ProcMaps" in data:
509-
oops_delete = _session.prepare(
510-
'DELETE FROM "OOPS" WHERE key = ? AND column1 = ?'
511-
)
502+
oops_delete = _session.prepare('DELETE FROM "OOPS" WHERE key = ? AND column1 = ?')
512503
unneeded_columns = (
513504
"Disassembly",
514505
"ProcMaps",

src/daisy/wsgi.py

Lines changed: 0 additions & 129 deletions
This file was deleted.

src/errortracker/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
# Pre-load config to parse it before runtime
2+
from .config import *
3+
14
__version__ = "0.0.1"

0 commit comments

Comments
 (0)