Skip to content

Commit

Permalink
added field choice and fixed long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinapathak committed Jul 27, 2020
1 parent c7836c4 commit a247e8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 11 additions & 5 deletions requestParser/requestParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Config struct {
}

type LabelConfig struct {
Field string
Regex string
StorePayload bool
TTL time.Duration
Expand Down Expand Up @@ -123,7 +124,8 @@ func NewRequestParser(config Config, logger log.Logger, metricsRegistry provider
for k, v := range config.Labels {
eventType := db.ParseEventType(k)
if eventType != db.Default {
c, err := wrpparser.NewRegexpClassifierFromStr(eventType.String(), v.Regex, wrpparser.Destination)
c, err := wrpparser.NewRegexpClassifierFromStr(eventType.String(),
v.Regex, wrpparser.GetField(v.Field))
if err != nil {
// log error
} else {
Expand Down Expand Up @@ -264,7 +266,8 @@ func (r *RequestParser) createRecord(req wrp.Message, result *eventparser.Result
case wrp.SimpleEventMessageType:

default:
return emptyRecord, parseFailReason, emperror.WrapWith(errUnexpectedWRPType, "message type check failed", "type", msg.Type, "full message", req)
return emptyRecord, parseFailReason, emperror.WrapWith(errUnexpectedWRPType, "message type check failed",
"type", msg.Type, "full message", req)
}

now := r.currTime()
Expand All @@ -277,12 +280,14 @@ func (r *RequestParser) createRecord(req wrp.Message, result *eventparser.Result
record.BirthDate = birthDate.UnixNano()

if birthDate.After(now.Add(time.Hour)) {
return emptyRecord, invalidBirthdateReason, emperror.WrapWith(errFutureBirthdate, "invalid birthdate", "birthdate", birthDate.String())
return emptyRecord, invalidBirthdateReason, emperror.WrapWith(errFutureBirthdate, "invalid birthdate",
"birthdate", birthDate.String())
}

deathDate := birthDate.Add(result.TTL)
if now.After(deathDate) {
return emptyRecord, expiredReason, emperror.WrapWith(errExpired, "event is already expired", "deathdate", deathDate.String())
return emptyRecord, expiredReason, emperror.WrapWith(errExpired, "event is already expired",
"deathdate", deathDate.String())
}
record.DeathDate = deathDate.UnixNano()

Expand All @@ -294,7 +299,8 @@ func (r *RequestParser) createRecord(req wrp.Message, result *eventparser.Result
// if metadata is too large, store a message explaining that instead of the metadata
marshaledMetadata, err := json.Marshal(msg.Metadata)
if err != nil {
return emptyRecord, parseFailReason, emperror.WrapWith(err, "failed to marshal metadata to determine size", "metadata", msg.Metadata, "full message", req)
return emptyRecord, parseFailReason, emperror.WrapWith(err, "failed to marshal metadata to determine size",
"metadata", msg.Metadata, "full message", req)
}
if len(marshaledMetadata) > r.config.MetadataMaxSize {
msg.Metadata = make(map[string]string)
Expand Down
5 changes: 5 additions & 0 deletions svalinn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ requestParser:
# to find the device ID.
# (Optional)
state:
# field provides the field to use to determine if an event should be
# labelled a State event.
# (Optional) default is Source
field: "Destination"

# regex provides the regular expression to be used to determine if an event
# should be labelled a State event.
regex: "device-status/.*/(on|off)line$"
Expand Down

0 comments on commit a247e8c

Please sign in to comment.