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

Adding logs by stack #242

Merged
merged 1 commit into from
Sep 24, 2016
Merged
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
56 changes: 25 additions & 31 deletions api/rpc/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,26 @@ func (logs *Logs) Get(ctx context.Context, in *GetRequest) (*GetReply, error) {
}

masterQuery := elastic.NewBoolQuery()
if in.ServiceId != "" {
masterQuery.Must(elastic.NewPrefixQuery("service_id", in.ServiceId))
}
if in.ServiceName != "" {
masterQuery.Must(elastic.NewPrefixQuery("service_name", in.ServiceName))
}
if in.ContainerId != "" {
masterQuery.Must(elastic.NewPrefixQuery("container_id", in.ContainerId))
}
if in.NodeId != "" {
masterQuery.Must(elastic.NewPrefixQuery("node_id", in.NodeId))
}
if in.ServiceIsh != "" {
queryString := elastic.NewQueryStringQuery(in.ServiceIsh + "*")
queryString.Field("service_id")
queryString.Field("service_name")
queryString.AnalyzeWildcard(true)
masterQuery.Must(queryString)
if in.Container != "" {
masterQuery.Must(elastic.NewPrefixQuery("container_id", in.Container))
}
if in.Message != "" {
queryString := elastic.NewQueryStringQuery(in.Message + "*")
queryString.Field("message")
queryString.AnalyzeWildcard(true)
masterQuery.Must(queryString)
}
if in.Node != "" {
masterQuery.Must(elastic.NewPrefixQuery("node_id", in.Node))
}
if in.Service != "" {
masterQuery.Should(elastic.NewPrefixQuery("service_id", in.Service))
masterQuery.Should(elastic.NewPrefixQuery("service_name", in.Service))
}
if in.Stack != "" {
masterQuery.Should(elastic.NewPrefixQuery("stack_id", in.Stack))
masterQuery.Should(elastic.NewPrefixQuery("stack_name", in.Stack))
}
// TODO timestamp queries

// Perform request
Expand Down Expand Up @@ -134,25 +129,24 @@ func parseProtoLogEntry(data []byte) (logEntry LogEntry, err error) {

func filter(entry *LogEntry, in *GetRequest) bool {
match := true
if in.ServiceId != "" {
match = strings.EqualFold(entry.ServiceId, in.ServiceId)
if in.Container != "" {
match = strings.HasPrefix(strings.ToLower(entry.ContainerId), strings.ToLower(in.Container))
}
if in.ServiceName != "" {
match = strings.EqualFold(entry.ServiceName, in.ServiceName)
}
if in.ContainerId != "" {
match = strings.EqualFold(entry.ContainerId, in.ContainerId)
if in.Message != "" {
match = strings.Contains(strings.ToLower(entry.Message), strings.ToLower(in.Message))
}
if in.NodeId != "" {
match = strings.EqualFold(entry.NodeId, in.NodeId)
if in.Node != "" {
match = strings.HasPrefix(strings.ToLower(entry.NodeId), strings.ToLower(in.Node))
}
if in.ServiceIsh != "" {
if in.Service != "" {
serviceID := strings.ToLower(entry.ServiceId)
serviceName := strings.ToLower(entry.ServiceName)
match = strings.HasPrefix(serviceID, strings.ToLower(in.ServiceIsh)) || strings.HasPrefix(serviceName, strings.ToLower(in.ServiceIsh))
match = strings.HasPrefix(serviceID, strings.ToLower(in.Service)) || strings.HasPrefix(serviceName, strings.ToLower(in.Service))
}
if in.Message != "" {
match = strings.Contains(strings.ToLower(entry.Message), strings.ToLower(in.Message))
if in.Stack != "" {
stackID := strings.ToLower(entry.StackId)
stackName := strings.ToLower(entry.StackName)
match = strings.HasPrefix(stackID, strings.ToLower(in.Stack)) || strings.HasPrefix(stackName, strings.ToLower(in.Stack))
}
return match
}
66 changes: 32 additions & 34 deletions api/rpc/logs/logs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions api/rpc/logs/logs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ message LogEntry {
}

message GetRequest {
string timestamp = 1;
string service_id = 2;
string service_name = 3;
string message = 4;
string container_id = 5;
string node_id = 6;
sint64 size = 7;
string service_ish = 8;
string container = 1;
string message = 2;
string node = 3;
sint64 size = 4;
string service = 5;
string stack = 6;
}

message GetReply {
Expand Down
Loading