Skip to content

feat: mcp-log#1483

Open
Oxidaner wants to merge 9 commits into
apache:aifrom
Oxidaner:ai-log
Open

feat: mcp-log#1483
Oxidaner wants to merge 9 commits into
apache:aifrom
Oxidaner:ai-log

Conversation

@Oxidaner

@Oxidaner Oxidaner commented Jun 1, 2026

Copy link
Copy Markdown

Changes

  • Add observability.logs config for Loki providers.
  • Register two MCP tools:
    • search_logs
    • analyze_error_logs
    • get_log_capabilities
  • Query Loki via query_range and normalize log results.
  • Support filtering by common Loki labels such as app, service, instance, mesh, and log keywords.
  • Add a Grafana Alloy values example for collecting Kubernetes pod logs into Loki.

Test

go test ./pkg/config/observability ./pkg/console ./pkg/mcp/tools/log ./pkg/mcp/tools

@robocanic

robocanic commented Jun 6, 2026

Copy link
Copy Markdown
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
@Oxidaner

Oxidaner commented Jun 7, 2026

Copy link
Copy Markdown
Author

@robocanic done

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.logs configuration (default provider + Loki providers) with validation.
  • Introduce Loki client + log normalization + error-pattern analyzer and register MCP tools (search_logs, analyze_error_logs, plus get_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)
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/mcp/tools/log/loki.go Outdated
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"),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/mcp/tools/log/loki.go
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 ""
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/mcp/tools/log/loki.go
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/config/observability/logs.go Outdated
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))
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/mcp/register.go
Comment on lines +336 to +338
server.RegisterTool(&common.ToolDef{
Name: "get_log_capabilities",
Description: "获取日志查询能力,返回 Loki 当前可用 labels 以及查询参数到 labels 的映射",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@robocanic robocanic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Works! I' ve reviewed the PR generally and Copilot may left some useful comments, you can follow the review of Copilot and resolve them.

@Oxidaner

Copy link
Copy Markdown
Author

@robocanic done

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants