Skip to content

Commit c7a73cc

Browse files
Make logs better (#38)
1 parent eabab13 commit c7a73cc

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

tools/get_logs.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import (
1313

1414
type GetLogsHandlerArgs struct {
1515
TimeConfig utils.TimeConfig `json:"time_config" jsonschema:"required,description=The time period to get the logs for. e.g. if you want the get the logs for the last 5 minutes you would set time_period=5 and time_window=Minutes. You can also set an absoulute time range by setting start_time and end_time"`
16-
Filters map[string][]string `json:"filters" jsonschema:"description=Log attributes to restrict the search to. Keys are anded together and values in the keys are ORed. e.g. {service.name: [/k8s/test/test /k8s/test/test2] namespace:[test]} will return all logs emited from (service.name = /k8s/test/test OR /k8s/test/test2) AND (namespace = test). Get the possible filter keys from the get_attribute_keys tool and possible values of a filter key from the get_attribute_values tool. If you are looking to get logs of a certain severity you should look up the log_level filter."`
17-
ExcludeFilters map[string][]string `json:"excludeFilters" jsonschema:"description=Log attributes to exclude from the search. Keys are anded together and values in the keys are ORed. e.g. {service.name: [/k8s/test/test /k8s/test/test2] namespace:[test]} will return all logs emited from NOT ((service.name = /k8s/test/test OR /k8s/test/test2) AND (namespace = test)). Get the possible filter keys from the get_attribute_keys tool and possible values of a filter key from the get_attribute_values tool. If you are looking to get logs of a certain severity you should look up the log_level filter."`
18-
Regexes []string `json:"regexes" jsonschema:"description=Regexes to apply to the log messages. Only the logs with messages that match these regexes will be returned. Regexes are ANDed together. For example if you want to get logs with message that contains the word 'fish' and 'chips' you would set the regexes as ['fish' 'chips']. If you want to OR you should use the | operator in a single regex. regexes only match the body of the log so do not use this to match things like service names. If you want to get error logs use log_level filters instead."`
19-
ExcludeRegexes []string `json:"excludeRegexes" jsonshcema:"description=Regexes to exclude the log. Log messages that match these regexes will not be returned. Exclude regexes are ORed together. For example if you want to get logs with messages that do not contain the word 'fish' or 'chips' you would set the exclude regexes as ['fish' 'chips']. regexes only match the body of the log so do not use this to match things like service names. If you want to get error logs use log_level filters instead."`
16+
Filters map[string][]string `json:"attributeFilters" jsonschema:"description=You must use get_attribute_keys and get_attribute_values before setting this. Log attributes to restrict the search to. Keys are anded together and values in the keys are ORed. e.g. {service.name: [/k8s/test/test /k8s/test/test2] namespace:[test]} will return all logs emited from (service.name = /k8s/test/test OR /k8s/test/test2) AND (namespace = test). Get the possible filter keys from the get_attribute_keys tool and possible values of a filter key from the get_attribute_values tool. If you are looking to get logs of a certain severity you should look up the log_level filter."`
17+
ExcludeFilters map[string][]string `json:"attributeExcludeFilters" jsonschema:"description=You must use get_attribute_keys and get_attribute_values before setting this.Log attributes to exclude from the search. Keys are anded together and values in the keys are ORed. e.g. {service.name: [/k8s/test/test /k8s/test/test2] namespace:[test]} will return all logs emited from NOT ((service.name = /k8s/test/test OR /k8s/test/test2) AND (namespace = test)). Get the possible filter keys from the get_attribute_keys tool and possible values of a filter key from the get_attribute_values tool. If you are looking to get logs of a certain severity you should look up the log_level filter."`
18+
Regex string `json:"regex" jsonschema:"description=Regex to apply to the log search re2 format. Any match in the log message will cause it to be returned. Use the filters parameter log_level if you want to look for logs of a certain severity"`
2019
Environments []string `json:"environments" jsonschema:"description=The environments to get logs from. If empty logs from all environments will be returned"`
2120
}
2221

@@ -26,13 +25,17 @@ func GetLogsHandler(ctx context.Context, arguments GetLogsHandlerArgs) (*mcpgola
2625
return nil, fmt.Errorf("error calculating time range: %v", err)
2726
}
2827

28+
var regexes = []string{}
29+
if arguments.Regex != "" {
30+
regexes = append(regexes, arguments.Regex)
31+
}
32+
2933
request := model.GetLogsRequest{
3034
StartTime: startTime,
3135
EndTime: endTime,
3236
Filters: arguments.Filters,
3337
ExcludeFilters: arguments.ExcludeFilters,
34-
Regexes: arguments.Regexes,
35-
ExcludeRegexes: arguments.ExcludeRegexes,
38+
Regexes: regexes,
3639
Environments: arguments.Environments,
3740
}
3841

tools/tools.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ var MetoroToolsList = []MetoroTools{
2323
Handler: GetNamespacesHandler,
2424
},
2525
{
26-
Name: "get_logs",
27-
Description: `Get individual log lines. Results are limited to 100 logs so try to use filters and regexes to narrow down what you are looking for.
28-
Use this tool when you are interested in the contents of the log lines to get more information to answer why/what.
29-
If you want to check existence use get_timeseries_data tool with type=logs to get count of logs.`,
30-
Handler: GetLogsHandler,
26+
Name: "get_logs",
27+
Description: `Get logs from all or specific services/hosts/pods. Before calling this you MUST first call get_attribute_keys and get_attribute_values. Results are limited to 100 logs lines. Log lines are large so if you want to check for trends you should use get_timeseries_data with the log type then us this after to drill in. Before using this you MUST first call get_attribute_keys to get the possible log attribute keys which can be used as Filter/ExcludeFilter keys.`,
28+
Handler: GetLogsHandler,
3129
},
3230
{
3331
Name: "get_traces",

0 commit comments

Comments
 (0)