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

added configurable device id parsing #228

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- switch webhook configuration from sns to argus [#202](https://github.com/xmidt-org/caduceus/pull/202)
- removed `/hooks` endpoint [#202](https://github.com/xmidt-org/caduceus/pull/202)
- Updated references to the main branch [#227](https://github.com/xmidt-org/caduceus/pull/227)
- Added configurable device id parsing [#228](https://github.com/xmidt-org/caduceus/pull/228)

## [v0.4.0]
- Moved and renamed configuration variable for outgoing hostname validation [#223](https://github.com/xmidt-org/caduceus/pull/223)
Expand Down
40 changes: 40 additions & 0 deletions caduceus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,46 @@
retryCodes:
- 429

# deviceIDParsers provide instructions to Caduceus on how to find the
# device id for different events. If an event matched the regex on the
# field given, the device ID is found based on the location instructions
# for that label.
deviceIDParsers:
# state is the name we are giving this set of device location instructions
# so that debugging will be easier. It can be named anything.
# (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$"

# deviceLocation is where to find the device id for an event of this label.
# If a valid regex and regexLabel aren't provided, the whole value in the
# field given is used.
deviceLocation:
# field can either be Destination or Source.
# (Optional) default is Source
field: "Destination"

# regex must include the label provided. This is where the device id will
# be found.
regex: "device-status/(?P<device>.*)/(on|off)line$"
regexLabel: "device"

# default provides the default way to find the device ID. Default doesn't
# match against any regular expressions, because it is the bucket for
# anything not matched to a label above.
# (Optional)
default:
# (Optional) default is Source with no regex used
deviceLocation:
field: "Source"

# (Deprecated)
# profilerFrequency: 15
# profilerDuration: 15
Expand Down
20 changes: 17 additions & 3 deletions caduceus_type.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2017 Comcast Cable Communications Management, LLC
* Copyright 2020 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,14 +17,15 @@
package main

import (
"github.com/xmidt-org/argus/chrysom"
"time"

"github.com/xmidt-org/argus/chrysom"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/go-kit/kit/metrics"
"github.com/xmidt-org/webpa-common/logging"
"github.com/xmidt-org/wrp-go/v2"
"github.com/xmidt-org/wrp-go/v3"
)

// Below is the struct we're using to contain the data from a provided config file
Expand All @@ -51,6 +52,19 @@ type SenderConfig struct {
DeliveryRetries int
DeliveryInterval time.Duration
RetryCodes []int
DeviceIDParsers map[string]ParserConfig
}

type ParserConfig struct {
Field string
Regex string
DeviceLocation FinderConfig
}

type FinderConfig struct {
Field string
Regex string
RegexLabel string
}

type CaduceusMetricsRegistry interface {
Expand Down
2 changes: 1 addition & 1 deletion caduceus_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/stretchr/testify/mock"
"github.com/xmidt-org/webpa-common/logging"
"github.com/xmidt-org/wrp-go/v2"
"github.com/xmidt-org/wrp-go/v3"
)

func TestCaduceusHandler(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/go-kit/kit v0.9.0
github.com/gorilla/mux v1.7.3
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/justinas/alice v1.2.0
github.com/samuel/go-zookeeper v0.0.0-20190810000440-0ceca61e4d75 // indirect
github.com/satori/go.uuid v1.2.0
Expand All @@ -17,7 +18,7 @@ require (
github.com/stretchr/testify v1.5.1
github.com/xmidt-org/argus v0.3.3
github.com/xmidt-org/webpa-common v1.10.2
github.com/xmidt-org/wrp-go/v2 v2.0.0
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 // indirect
github.com/xmidt-org/wrp-go/v3 v3.0.1
github.com/xmidt-org/wrp-listener v0.2.1
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
)
Loading