feat: mcp-log#1483
Open
Oxidaner wants to merge 9 commits into
Open
Conversation
of interface error-analyse
of interface error-analyse
Contributor
|
Please merge the ai branch and resolve the conflicts. |
# Conflicts: # pkg/console/component.go # pkg/mcp/tools/search.go # pkg/mcp/tools/service.go
Author
|
@robocanic done |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds MCP-based log observability by introducing a Loki-backed log query provider, registering new MCP tools for searching/analyzing logs, and providing configuration + example Alloy values for collecting Kubernetes pod logs into Loki.
Changes:
- Add
observability.logsconfiguration (default provider + Loki providers) with validation. - Introduce Loki client + log normalization + error-pattern analyzer and register MCP tools (
search_logs,analyze_error_logs, plusget_log_capabilities). - Add documentation/examples for Loki ingestion via Grafana Alloy and update sample app config.
Reviewed changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/mcp/tools/search.go | Formatting-only alignment in search tool result map. |
| pkg/mcp/tools/log/tools.go | Defines MCP tool handlers + argument parsing for Loki-backed log features. |
| pkg/mcp/tools/log/tools_test.go | Adds unit tests covering LogQL generation, Loki querying, normalization, and error analysis. |
| pkg/mcp/tools/log/model.go | Adds request/response models for log search, capabilities, and error analysis. |
| pkg/mcp/tools/log/loki.go | Implements Loki query_range/labels calls, label caching, LogQL building, and log normalization. |
| pkg/mcp/tools/log/analyzer.go | Implements error log grouping into normalized patterns. |
| pkg/mcp/register.go | Registers the new log-related MCP tools with schemas and handlers. |
| pkg/console/component.go | Formatting-only field alignment. |
| pkg/config/observability/logs.go | Adds log-provider config types + validation/default-provider selection. |
| pkg/config/observability/config.go | Wires observability.logs into overall observability config validation. |
| docs/examples/observability/alloy-values.yaml | Provides an Alloy Helm values example to collect K8s pod logs into Loki with matching labels. |
| app/dubbo-admin/dubbo-admin.yaml | Documents sample observability.logs configuration (commented) in the app config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+46
to
+50
| pattern.Count++ | ||
| pattern.LastSeen = item.Timestamp | ||
| if len(pattern.Examples) < 3 { | ||
| pattern.Examples = append(pattern.Examples, item) | ||
| } |
Comment on lines
+500
to
+504
| Severity: firstNonEmpty(extractLogField(raw, "level", "severity"), firstLabel(stream.Stream, "level", "severity", "detected_level")), | ||
| Message: message, | ||
| TraceID: extractLogField(raw, "trace_id", "traceId", "traceid"), | ||
| SpanID: extractLogField(raw, "span_id", "spanId", "spanid"), | ||
| TraceFlags: extractLogField(raw, "trace_flags", "traceFlags", "traceflags"), |
Comment on lines
+579
to
+588
|
|
||
| func extractTextLogField(message string, keys ...string) string { | ||
| for _, key := range keys { | ||
| pattern := regexp.MustCompile(`(?i)(?:^|[\s{,])"?` + regexp.QuoteMeta(key) + `"?\s*[:=]\s*"?([^"\s,}]+)`) | ||
| if matches := pattern.FindStringSubmatch(message); len(matches) == 2 { | ||
| return matches[1] | ||
| } | ||
| } | ||
| return "" | ||
| } |
Comment on lines
+595
to
+597
| case "mesh", "app", "appName", "service", "serviceName", "service_name", "instance", "instanceName", | ||
| "pod", "level", "severity", "detected_level", "trace_id", "traceId", "traceid", "span_id", "spanId", "spanid": | ||
| continue |
Comment on lines
+69
to
+71
| if _, err := url.Parse(provider.Endpoint); err != nil { | ||
| return bizerror.Wrap(err, bizerror.ConfigError, fmt.Sprintf("invalid log provider endpoint: %s", provider.Endpoint)) | ||
| } |
Comment on lines
+336
to
+338
| server.RegisterTool(&common.ToolDef{ | ||
| Name: "get_log_capabilities", | ||
| Description: "获取日志查询能力,返回 Loki 当前可用 labels 以及查询参数到 labels 的映射", |
robocanic
reviewed
Jun 13, 2026
Author
|
@robocanic done |
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Changes
observability.logsconfig for Loki providers.search_logsanalyze_error_logsget_log_capabilitiesquery_rangeand normalize log results.Test
go test ./pkg/config/observability ./pkg/console ./pkg/mcp/tools/log ./pkg/mcp/tools