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

add support for multiple sensor queries #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions feeders.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
feeder:
- name: AMQPInput2
type: amqp
url: amqp://guest:guest@localhost:5672
exchange: [ tdh.pdns ]
input_format: fever_aggregate
- name: HTTP Input
type: http
listen_host: 127.0.0.1
Expand Down
47 changes: 36 additions & 11 deletions query/query_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"runtime"
"strings"
"time"

"github.com/DCSO/balboa/db"
Expand Down Expand Up @@ -175,7 +176,7 @@ const (
# Providing rdata, rrname, rrtype and/or sensor_id will restrict the
# results to the set of observations that match all of the given
# constraints.
entries(rdata: String, rrname: String, rrtype: RRType, sensor_id: String, limit: Int = 1000): [Entry]
entries(rdata: String, rrname: String, rrtype: RRType, sensor_id: [String], limit: Int = 1000): [Entry]

# Returns some runtime values describing the current state of the database.
stats(): Stats
Expand Down Expand Up @@ -207,7 +208,7 @@ func (r *Resolver) Entries(args struct {
Rdata *string
Rrname *string
Rrtype *string
SensorID *string
SensorID *[]*string
Limit int32
}) (*[]*EntryResolver, error) {
startTime := time.Now()
Expand All @@ -229,7 +230,11 @@ func (r *Resolver) Entries(args struct {
rrtype = ("nil")
}
if args.SensorID != nil {
sensorID = *args.SensorID
sensorIDs := make([]string, 0)
for _, sid := range *args.SensorID {
sensorIDs = append(sensorIDs, *sid)
}
sensorID = strings.Join(sensorIDs, ",")
} else {
sensorID = ("nil")
}
Expand All @@ -242,15 +247,35 @@ func (r *Resolver) Entries(args struct {
Message: "at least one of the 'rdata' or 'rrname' parameters is required",
}
}
results, err := db.ObservationDB.Search(args.Rdata, args.Rrname, args.Rrtype, args.SensorID, int(args.Limit))
if err != nil {
return nil, err
}
for _, r := range results {
er := EntryResolver{
entry: r,
if args.SensorID == nil {
results, err := db.ObservationDB.Search(args.Rdata, args.Rrname, args.Rrtype, nil, int(args.Limit))
if err != nil {
return nil, err
}
for _, r := range results {
er := EntryResolver{
entry: r,
}
l = append(l, &er)
}
} else {
lim := int(args.Limit)
for _, sid := range *args.SensorID {
if lim < 1 {
break
}
results, err := db.ObservationDB.Search(args.Rdata, args.Rrname, args.Rrtype, sid, lim)
if err != nil {
return nil, err
}
for _, r := range results {
er := EntryResolver{
entry: r,
}
lim--
l = append(l, &er)
}
}
l = append(l, &er)
}
return &l, nil
}
Expand Down