Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mattdeboard/eventcapture_comparison
base: 381c528c4c
...
head fork: mattdeboard/eventcapture_comparison
compare: 9f76e44cac
  • 7 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
2  benchmark/sample_post_data.txt
@@ -1 +1 @@
-event_type=test&ext_ref=abc&user_ref=dude3&data={"a": 1}
+event_type=test&ext_ref=abc&user_ref=dude3&data={"a": 1}
View
3  clj/eventcapture/project.clj
@@ -6,7 +6,8 @@
[org.clojure/data.json "0.2.4"]
[org.clojure/java.jdbc "0.3.3"]
[org.postgresql/postgresql "9.3-1100-jdbc4"]
- [com.jolbox/bonecp "0.8.0.RELEASE"]]
+ [com.jolbox/bonecp "0.8.0.RELEASE"]
+ [lib-noir "0.7.6"]]
:plugins [[lein-ring "0.8.10"]]
:ring {:handler eventcapture.handler/app}
:profiles
View
28 clj/eventcapture/src/eventcapture/handler.clj
@@ -51,15 +51,23 @@
:result-set-fn first))
"")
+(defn server-error [error]
+ (-> (response error)
+ (status 500)))
+
(defn handle-event-post [event-type ext-ref user-ref data]
- {:pre [(string? event-type)
- (not (strings/blank? event-type))
- (string? data)
- (json/read-str data)]}
- (insert-event {:event_type event-type
- :ext_ref ext-ref
- :user_ref user-ref
- :data data}))
+ (rule (string? event-type)
+ [:event_type "Event type must be a non-empty string"])
+ (rule (not (strings/blank? event-type))
+ [:event_type "Event type must be non-empty string"])
+ (rule (string? data) [:data "Data must be a string."])
+ (rule (json/read-str data) [:data "Data must be a string."])
+ (if (errors? :event_type :data)
+ (server-error (get-errors))
+ (insert-event {:event_type event-type
+ :ext_ref ext-ref
+ :user_ref user-ref
+ :data data})))
(defroutes app-routes
(GET "/" [] "It works!")
@@ -69,4 +77,6 @@
(route/not-found "Not Found"))
(def app
- (handler/site app-routes))
+ (-> (routes app-routes)
+ handler/site
+ wrap-noir-validation))
View
7 compare.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+RUNS=${1-10000}
+PORT=${2-3000}
+
+sudo -u postgres psql event -c "truncate eventlog"
+sudo -u postgres psql event -c "vacuum analyze eventlog"
+ab -n $RUNS -c 50 -T application/x-www-form-urlencoded -p benchmark/sample_post_data.txt -k http://localhost:$PORT/capture
View
2  golang/eventcaptureserver/eventcaptureserver.go
@@ -36,7 +36,7 @@ func handleCapture(req *http.Request, params martini.Params) (string, int) {
req.PostFormValue("user_ref"), data}
if err := event.Save(); err != nil {
fmt.Println(err)
- return "Event capture failed", 500
+ return "Event capture failed\n", 500
}
return "", 204
}
View
31 sql/create_eventlog_table.sql
@@ -1,16 +1,21 @@
--- create the eventlog table
-CREATE TABLE eventlog (
- id serial PRIMARY KEY,
- timeutc timestamp with time zone NOT NULL default (now() at time zone 'utc'),
- event_type varchar(200) NOT NULL CHECK (event_type <> ''),
- ext_ref varchar(200),
- user_ref varchar(200),
- data json
-);
-CREATE INDEX eventlog_timeutc_type_user_idx
- ON eventlog (timeutc ASC,
- event_type NULLS LAST,
- user_ref NULLS LAST);
+DO $$ BEGIN
+ IF NOT EXISTS (SELECT * FROM pg_tables WHERE tablename = 'eventlog') THEN
+ -- create the eventlog table
+ CREATE TABLE eventlog (
+ id serial PRIMARY KEY,
+ timeutc timestamp with time zone NOT NULL default (now() at time zone 'utc'),
+ event_type varchar(200) NOT NULL CHECK (event_type <> ''),
+ ext_ref varchar(200),
+ user_ref varchar(200),
+ data json
+ );
+
+ CREATE INDEX eventlog_timeutc_type_user_idx
+ ON eventlog (timeutc ASC,
+ event_type NULLS LAST,
+ user_ref NULLS LAST);
+ END IF;
+END; $$;
-- a function to help in doing inserts
CREATE OR REPLACE FUNCTION insert_eventlog
View
12 sql/init.sql
@@ -1,7 +1,11 @@
---create user for the eventcapture apps
-CREATE ROLE eventcaptureuser LOGIN
- ENCRYPTED PASSWORD 'md59781e8b2674aa82664bae96006fc0c32'
- NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
+DO $$ BEGIN
+ --create user for the eventcapture apps
+ IF NOT EXISTS (SELECT * FROM pg_catalog.pg_user WHERE usename = 'eventcaptureuser') THEN
+ CREATE ROLE eventcaptureuser LOGIN
+ ENCRYPTED PASSWORD 'md59781e8b2674aa82664bae96006fc0c32'
+ NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
+ END IF;
+END; $$;
--create event database
CREATE DATABASE event

No commit comments for this range

Something went wrong with that request. Please try again.