-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bump up version to 3.0.0. can run continuous background mapreduce que…
…ries, useful for log file monitorig for example. breaking protocol change which allows to mapreduce aggreate messages containing the default field separator |. add of more unit tests. add logformat mapreduce query keyword. add set mapreduce clause support and support to evaluate built-in functions such as md5sum() and maskdigits().
- Loading branch information
Showing
32 changed files
with
642 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
module github.com/mimecast/dtail | ||
|
||
go 1.13 | ||
go 1.15 | ||
|
||
require ( | ||
github.com/DataDog/zstd v1.4.4 | ||
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 | ||
github.com/DataDog/zstd v1.4.5 | ||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de | ||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect | ||
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package mapr | ||
|
||
import "fmt" | ||
|
||
type fieldType int | ||
|
||
// The possible field types. | ||
const ( | ||
UndefFieldType fieldType = iota | ||
Field fieldType = iota | ||
String fieldType = iota | ||
Float fieldType = iota | ||
FunctionStack fieldType = iota | ||
) | ||
|
||
func (w fieldType) String() string { | ||
switch w { | ||
case Field: | ||
return fmt.Sprintf("Field") | ||
case String: | ||
return fmt.Sprintf("String") | ||
case Float: | ||
return fmt.Sprintf("Float") | ||
case FunctionStack: | ||
return fmt.Sprintf("FunctionStack") | ||
default: | ||
return fmt.Sprintf("UndefFieldType") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package funcs | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// CallbackFunc is a function which can be executed by the mapreduce engine | ||
type CallbackFunc func(text string) string | ||
|
||
// Function embeddes the function name to the callback function | ||
type Function struct { | ||
// Name of the callback function | ||
Name string | ||
call CallbackFunc | ||
} | ||
|
||
// FunctionStack is a list of functions stacked each other | ||
type FunctionStack []Function | ||
|
||
// NewFunctionStack parses the input string, e.g. foo(bar("arg")) and returns a corresponding function stack. | ||
func NewFunctionStack(in string) (FunctionStack, string, error) { | ||
var fs FunctionStack | ||
|
||
getCallback := func(name string) (CallbackFunc, error) { | ||
var cb CallbackFunc | ||
|
||
switch name { | ||
case "md5sum": | ||
return Md5Sum, nil | ||
case "maskdigits": | ||
return MaskDigits, nil | ||
default: | ||
return cb, fmt.Errorf("unknown function '%s'", name) | ||
} | ||
} | ||
|
||
aux := in | ||
for strings.HasSuffix(aux, ")") { | ||
index := strings.Index(aux, "(") | ||
if index <= 0 { | ||
return fs, "", fmt.Errorf("unable to parse function '%s' at '%s'", in, aux) | ||
} | ||
name := aux[0:index] | ||
|
||
call, err := getCallback(name) | ||
if err != nil { | ||
return fs, "", err | ||
} | ||
fs = append(fs, Function{name, call}) | ||
aux = aux[index+1 : len(aux)-1] | ||
} | ||
|
||
return fs, aux, nil | ||
} | ||
|
||
// Call the function stack. | ||
func (fs FunctionStack) Call(str string) string { | ||
for i := len(fs) - 1; i >= 0; i-- { | ||
//logger.Debug("Call", fs[i].Name, str) | ||
str = fs[i].call(str) | ||
//logger.Debug("Call.result", fs[i].Name, str) | ||
} | ||
|
||
return str | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package funcs | ||
|
||
import "testing" | ||
|
||
func TestFunction(t *testing.T) { | ||
input := "md5sum($line)" | ||
fs, arg, err := NewFunctionStack(input) | ||
if err != nil { | ||
t.Errorf("error parsing function input '%s': %s (%v)\n", input, err.Error(), fs) | ||
} | ||
if arg != "$line" { | ||
t.Errorf("error parsing function input '%s': expected argument '$line' but got '%s' (%v)\n", input, arg, fs) | ||
} | ||
t.Log(input, fs, arg) | ||
|
||
result := fs.Call(input) | ||
if result != "b38699013d79e50d9d122433753959c1" { | ||
t.Errorf("error executing function stack '%s': expected result 'b38699013d79e50d9d122433753959c1' but got '%s' (%v)\n", input, result, fs) | ||
} | ||
|
||
input = "maskdigits(md5sum(maskdigits($line)))" | ||
fs, arg, err = NewFunctionStack(input) | ||
if err != nil { | ||
t.Errorf("error parsing function input '%s': %s (%v)\n", input, err.Error(), fs) | ||
} | ||
if arg != "$line" { | ||
t.Errorf("error parsing function input '%s': expected argument '$line' but got '%s' (%v)\n", input, arg, fs) | ||
} | ||
t.Log(input, fs, arg) | ||
|
||
result = fs.Call(input) | ||
if result != ".fac.bbe..bb.........d...a.c..b." { | ||
t.Errorf("error executing function stack '%s': expected result '.fac.bbe..bb.........d...a.c..b.' but got '%s' (%v)\n", input, result, fs) | ||
} | ||
|
||
input = "md5sum$line)" | ||
if fs, _, err := NewFunctionStack(input); err == nil { | ||
t.Errorf("Expected error parsing function input '%s' (%v) but got no error\n", input, fs) | ||
} | ||
|
||
input = "md5sum(makedigits$line))" | ||
if fs, _, err := NewFunctionStack(input); err == nil { | ||
t.Errorf("Expected error parsing function input '%s' (%v) but got no error\n", input, fs) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package funcs | ||
|
||
// MaskDigits masks all digits (replaces them with .) | ||
func MaskDigits(input string) string { | ||
s := []byte(input) | ||
|
||
for i, b := range s { | ||
if '0' <= b && b <= '9' { | ||
s[i] = '.' | ||
} | ||
} | ||
|
||
return string(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package funcs | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/hex" | ||
) | ||
|
||
// Md5Sum returns the hex encoded MD5 checksum of a given input string. | ||
func Md5Sum(text string) string { | ||
hash := md5.Sum([]byte(text)) | ||
return hex.EncodeToString(hash[:]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.