Documentation ¶
Overview ¶
Example (CheckErrorHandling) ¶
Check to ensure that if there is an error thrown in the client we don't trip up and kill the server as the ES logs aren't mandatory
testServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer testServer.Close() t := "2006-01-02T15:04:05-07:00" twrong := "2007-01-02T15:04:05-07:00" //tstr := fmt.Sprintf(t.Format("2006-01-02T15:04:05.0000000-07:00")) ti, err := time.Parse("2006-01-02T15:04:05-07:00", t) var ExpIndexObject = []string{ `{"Instance":"Test","Time":"` + twrong + `","Component":"Test Component","Message":"Test Message","Response":"","Version":"","Params":{"some param":"some param value"},"Environment":"Test","User":"5838239847"}`, } var ExpRespObject = []string{} d := DummyElasticClient{} foo, err := d.DummyElasticSearchClient(testServer.URL, ExpRespObject, ExpIndexObject, ExpRespObject, nil) defer d.FinishTest() apiConfig := config.APIConfig{EnvironmentName: "Test"} if err != nil { fmt.Printf("%v\n", err) } connection, err := Connect(foo, apiConfig) if err != nil { fmt.Printf("%v\n", err) } params := make(map[string]interface{}) params["some param"] = "some param value" ilogger := logger.NullLogger{} o := LoggingObject{ Instance: "Test", Time: ti, Component: "Test Component", Message: "Test Message", Params: params, Environment: "Test", User: "5838239847", } resp, err := InsertLogRecord(connection, o, ilogger) if err != nil { fmt.Printf("%v", err) } fmt.Printf("%v", resp.Index)
Output: incorrect input object expected: {"Instance":"Test","Time":"2007-01-02T15:04:05-07:00","Component":"Test Component","Message":"Test Message","Response":"","Version":"","Params":{"some param":"some param value"},"Environment":"Test","User":"5838239847"}, got: {"Instance":"Test","Time":"2006-01-02T15:04:05-07:00","Component":"Test Component","Message":"Test Message","Response":"","Version":"","Params":{"some param":"some param value"},"Environment":"Test","User":"5838239847"}
Example (TestInsert) ¶
testServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer testServer.Close() t := "2006-01-02T15:04:05-07:00" //tstr := fmt.Sprintf(t.Format("2006-01-02T15:04:05.0000000-07:00")) ti, err := time.Parse("2006-01-02T15:04:05-07:00", t) t2 := "2007-01-02T15:04:05-07:00" ti2, err := time.Parse("2006-01-02T15:04:05-07:00", t2) var ExpIndexObject = []string{ `{"Instance":"Test","Time":"2006-01-02T15:04:05-07:00","Component":"Test Component","Message":"Test Message","Response":"","Version":"","Params":{"some param":"some param value"},"Environment":"Test","User":"5838239847"}`, `{"Instance":"Test","Time":"2007-01-02T15:04:05-07:00","Component":"Second Component","Message":"Test Message","Response":"","Version":"","Params":{"some param":"some param value"},"Environment":"Test","User":"5838239847"}`, } var ExpRespObject = []string{ `{"_index":"metrics","_type":"trigger","_id":"B0tzT3wBosV6bFs8gJvY","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":8468,"_primary_term":1}`, `{"_index":"metrics","_type":"trigger","_id":"B0tzT3wBosV6bFs8gJvY","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":8468,"_primary_term":1}`, } d := DummyElasticClient{} foo, err := d.DummyElasticSearchClient(testServer.URL, ExpRespObject, ExpIndexObject, ExpRespObject, nil) defer d.FinishTest() apiConfig := config.APIConfig{EnvironmentName: "Test"} if err != nil { fmt.Printf("%v\n", err) } connection, err := Connect(foo, apiConfig) if err != nil { fmt.Printf("%v\n", err) } params := make(map[string]interface{}) params["some param"] = "some param value" ilogger := logger.NullLogger{} o := LoggingObject{ Instance: "Test", Time: ti, Component: "Test Component", Message: "Test Message", Params: params, Environment: "Test", User: "5838239847", } resp, err := InsertLogRecord(connection, o, ilogger) if err != nil { fmt.Printf("%v", err) } o = LoggingObject{ Instance: "Test", Time: ti2, Component: "Second Component", Message: "Test Message", Params: params, Environment: "Test", User: "5838239847", } resp2, err := InsertLogRecord(connection, o, ilogger) if err != nil { fmt.Printf("%v", err) } fmt.Printf("Index: %v\n", resp.Index) fmt.Printf("Type: %v\n", resp.Type) fmt.Printf("Result: %v\n", resp.Result) fmt.Printf("Status: %v\n", resp.Status) fmt.Printf("Index: %v\n", resp2.Index) fmt.Printf("Type: %v\n", resp2.Type) fmt.Printf("Result: %v\n", resp2.Result) fmt.Printf("Status: %v\n", resp2.Status)
Output: Index: metrics Type: trigger Result: created Status: 0 Index: metrics Type: trigger Result: created Status: 0
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InsertLogRecord ¶
func InsertLogRecord(es Connection, o LoggingObject, log logger.ILogger) (*elastic.IndexResponse, error)
InsertLogRecord - Insert a quick log message
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection - default connection object
type DummyElasticClient ¶
type DummyElasticClient struct {
// contains filtered or unexported fields
}
func (*DummyElasticClient) DummyElasticSearchClient ¶
func (*DummyElasticClient) FinishTest ¶
func (d *DummyElasticClient) FinishTest() error
type DummyHttpClient ¶
type DummyHttpClient struct { IndexedObjects []string ResponseObjects []string // contains filtered or unexported fields }
func MockHttpClient ¶
func MockHttpClient(responseMock []string, indexedObjects []string, responseObjects []string, t string) *DummyHttpClient
Click to show internal directories.
Click to hide internal directories.