-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ron cohen
committed
Mar 19, 2018
1 parent
f33412d
commit 6e9418d
Showing
8 changed files
with
309 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package beater | ||
|
||
import ( | ||
"errors" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/mitchellh/mapstructure" | ||
"github.com/santhosh-tekuri/jsonschema" | ||
|
||
"github.com/elastic/apm-server/decoder" | ||
"github.com/elastic/apm-server/model" | ||
"github.com/elastic/apm-server/processor" | ||
"github.com/elastic/apm-server/processor/transaction" | ||
"github.com/elastic/apm-server/utility" | ||
) | ||
|
||
// func SillyDecoder(fn func(r *http.Request) (decoder.DecodeReader, error)) decoder.Decoder { | ||
// return func(r *http.Request) (map[string]interface{}, error) { | ||
// return fn(r) | ||
// } | ||
// } | ||
|
||
// func backendV2Handler(pf ProcessorFactory, config *Config, report reporter) http.Handler { | ||
|
||
// decoder := decoder.GetJSONDecoder(config.MaxUnzippedSize) | ||
|
||
// process := processRequestHandler(pf, nil, report, | ||
// decoder.DecodeSystemData( | ||
// SillyDecoder(), config.AugmentEnabled | ||
|
||
// return logHandler( | ||
// authHandler(config.SecretToken, process)) | ||
// } | ||
|
||
func validateTransaction() { | ||
|
||
} | ||
|
||
func readSchema(file string) *jsonschema.Schema { | ||
schemaData, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return processor.CreateSchema(string(schemaData), "Bleh") | ||
} | ||
|
||
func decodeHeader(rawHeader map[string]interface{}) (*model.Header, error) { | ||
header := model.Header{} | ||
decoder, _ := mapstructure.NewDecoder( | ||
&mapstructure.DecoderConfig{ | ||
DecodeHook: utility.RFC3339DecoderHook, | ||
Result: &header, | ||
}, | ||
) | ||
err := decoder.Decode(rawHeader) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &header, nil | ||
} | ||
|
||
func processStreamingRequestHandler(pf ProcessorFactory, prConfig *processor.Config, report reporter, decode decoder.DecodeReader) http.Handler { | ||
transactionSchema := readSchema("docs/specs/transactions/tranasction.json") | ||
errorSchema := readSchema("docs/specs/transactions/tranasction.json") | ||
spanSchema := readSchema("docs/specs/transactions/span.json") | ||
|
||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
|
||
code, err := func() (int, error) { | ||
// read header | ||
rawHeader, err := decode.Read() | ||
if err != nil { | ||
return http.StatusBadRequest, err | ||
} | ||
|
||
header, err := decodeHeader(rawHeader) | ||
if err != nil { | ||
return http.StatusBadRequest, err | ||
} | ||
context := model.NewContext(header.Service, header.Process, header.System) | ||
|
||
decoder.DecodeUserData(func(*http.Request) { | ||
|
||
}) | ||
|
||
var schema *jsonschema.Schema | ||
for { | ||
item, err := decode.Read() | ||
if err != nil { | ||
return http.StatusBadRequest, err | ||
} | ||
|
||
if item == nil { | ||
return http.StatusAccepted, nil | ||
} | ||
|
||
itemType, ok := item["type"] | ||
if !ok { | ||
return http.StatusBadRequest, errors.New("missing 'type' field") | ||
} | ||
|
||
switch itemType { | ||
case "transaction": | ||
schema = transactionSchema | ||
case "span": | ||
schema = spanSchema | ||
case "error": | ||
schema = errorSchema | ||
} | ||
|
||
err = schema.ValidateInterface(item) | ||
if err != nil { | ||
return http.StatusBadRequest, err | ||
} | ||
switch itemType { | ||
case "transaction": | ||
transaction.New | ||
} | ||
} | ||
}() | ||
|
||
// code, err := processRequest(r, pf, prConfig, report, decode) | ||
sendStatus(w, r, code, err) | ||
}) | ||
} |
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,7 @@ | ||
package model | ||
|
||
type Header struct { | ||
Service Service | ||
Process *Process | ||
System *System | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.