-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: mcp-log #1483
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
Open
Oxidaner
wants to merge
9
commits into
apache:ai
Choose a base branch
from
Oxidaner:ai-log
base: ai
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: mcp-log #1483
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5e948a8
feat: add loki log mcp tools
Oxidaner 3d4fdfe
docs: add loki log config example
Oxidaner 34cd9fd
feat:The joint debugging
Oxidaner a88a029
docs: add alloy loki values example
Oxidaner 5a81097
feat:The joint debugging
Oxidaner 5634162
feat:support traceId
Oxidaner 55968cf
feat:add get_log_capabilities
Oxidaner a080fba
Merge remote-tracking branch 'upstream/ai' into ai-log
Oxidaner c855c21
feat:Make modifications based on copilot's suggestions
Oxidaner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Example values for the Grafana Alloy Helm chart. | ||
| # The generated Loki labels match the MCP log tools: | ||
| # - appName filters app/appName labels | ||
| # - serviceName filters service/serviceName/service_name labels | ||
| # - instanceName filters instance/instanceName/pod labels | ||
| # - mesh filters the mesh label | ||
| # | ||
| # traceId is intentionally not promoted to a Loki label in this example. | ||
| # Trace IDs are usually high-cardinality values; use the MCP keywords filter | ||
| # or add custom log parsing if your deployment requires trace-id lookup. | ||
|
|
||
| global: | ||
| image: | ||
| registry: m.daocloud.io/docker.io | ||
|
|
||
| image: | ||
| registry: m.daocloud.io/docker.io | ||
| repository: grafana/alloy | ||
| pullPolicy: IfNotPresent | ||
|
|
||
| controller: | ||
| type: deployment | ||
| replicas: 1 | ||
|
|
||
| configReloader: | ||
| enabled: false | ||
|
|
||
| rbac: | ||
| create: true | ||
|
|
||
| serviceAccount: | ||
| create: true | ||
|
|
||
| alloy: | ||
| enableReporting: false | ||
|
|
||
| mounts: | ||
| varlog: false | ||
| dockercontainers: false | ||
|
|
||
| resources: | ||
| requests: | ||
| cpu: 50m | ||
| memory: 128Mi | ||
| limits: | ||
| cpu: 300m | ||
| memory: 512Mi | ||
|
|
||
| configMap: | ||
| create: true | ||
| content: |- | ||
| logging { | ||
| level = "info" | ||
| format = "logfmt" | ||
| } | ||
|
|
||
| discovery.kubernetes "pods" { | ||
| role = "pod" | ||
| } | ||
|
|
||
| discovery.relabel "dubbo_pod_logs" { | ||
| targets = discovery.kubernetes.pods.targets | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_namespace"] | ||
| regex = "default|dubbo-system|dubbo-samples-shop|logging" | ||
| action = "keep" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_namespace"] | ||
| target_label = "namespace" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_pod_name"] | ||
| target_label = "pod" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_pod_name"] | ||
| target_label = "instance" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_pod_container_name"] | ||
| target_label = "container" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_pod_container_name"] | ||
| regex = "(.+)" | ||
| target_label = "service_name" | ||
| action = "replace" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_pod_label_app"] | ||
| regex = "(.+)" | ||
| target_label = "service_name" | ||
| action = "replace" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] | ||
| regex = "(.+)" | ||
| target_label = "service_name" | ||
| action = "replace" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_pod_label_app"] | ||
| regex = "(.+)" | ||
| target_label = "app" | ||
| action = "replace" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"] | ||
| regex = "(.+)" | ||
| target_label = "app" | ||
| action = "replace" | ||
| } | ||
|
|
||
| rule { | ||
| source_labels = ["__meta_kubernetes_namespace", "__meta_kubernetes_pod_container_name"] | ||
| separator = "/" | ||
| target_label = "job" | ||
| } | ||
| } | ||
|
|
||
| loki.source.kubernetes "dubbo_pod_logs" { | ||
| targets = discovery.relabel.dubbo_pod_logs.output | ||
| forward_to = [loki.process.dubbo_logs.receiver] | ||
| } | ||
|
|
||
| loki.process "dubbo_logs" { | ||
| forward_to = [loki.write.local.receiver] | ||
|
|
||
| stage.decolorize {} | ||
|
|
||
| stage.static_labels { | ||
| values = { | ||
| cluster = "k8s1.28.2", | ||
| mesh = "nacos2.5", | ||
| } | ||
| } | ||
| } | ||
|
|
||
| loki.write "local" { | ||
| endpoint { | ||
| url = "http://loki.logging.svc.cluster.local:3100/loki/api/v1/push" | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package observability | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/url" | ||
|
|
||
| "github.com/duke-git/lancet/v2/strutil" | ||
|
|
||
| "github.com/apache/dubbo-admin/pkg/common/bizerror" | ||
| ) | ||
|
|
||
| type LogProviderType string | ||
|
|
||
| const ( | ||
| LogProviderLoki LogProviderType = "loki" | ||
| ) | ||
|
|
||
| type LogsConfig struct { | ||
| DefaultProvider string `json:"defaultProvider" yaml:"defaultProvider"` | ||
| Providers []LogProviderConfig `json:"providers" yaml:"providers"` | ||
| } | ||
|
|
||
| type LogProviderConfig struct { | ||
| Name string `json:"name" yaml:"name"` | ||
| Type LogProviderType `json:"type" yaml:"type"` | ||
| Endpoint string `json:"endpoint" yaml:"endpoint"` | ||
| Tenant string `json:"tenant,omitempty" yaml:"tenant,omitempty"` | ||
| } | ||
|
|
||
| func (c *LogsConfig) Validate() error { | ||
| if c == nil || len(c.Providers) == 0 { | ||
| return nil | ||
| } | ||
| if strutil.IsBlank(c.DefaultProvider) { | ||
| return bizerror.New(bizerror.ConfigError, "default log provider is required") | ||
| } | ||
|
|
||
| foundDefault := false | ||
| for _, provider := range c.Providers { | ||
| if strutil.IsBlank(provider.Name) { | ||
| return bizerror.New(bizerror.ConfigError, "log provider name is required") | ||
| } | ||
| if provider.Name == c.DefaultProvider { | ||
| foundDefault = true | ||
| } | ||
| if provider.Type != LogProviderLoki { | ||
| return bizerror.New(bizerror.ConfigError, fmt.Sprintf("unsupported log provider type: %s", provider.Type)) | ||
| } | ||
| if strutil.IsBlank(provider.Endpoint) { | ||
| return bizerror.New(bizerror.ConfigError, "log provider endpoint is required") | ||
| } | ||
| parsed, err := url.Parse(provider.Endpoint) | ||
| if err != nil { | ||
| return bizerror.Wrap(err, bizerror.ConfigError, fmt.Sprintf("invalid log provider endpoint: %s", provider.Endpoint)) | ||
| } | ||
| if parsed.Scheme == "" || parsed.Host == "" { | ||
| return bizerror.New(bizerror.ConfigError, fmt.Sprintf("invalid log provider endpoint: %s", provider.Endpoint)) | ||
| } | ||
| } | ||
| if !foundDefault { | ||
| return bizerror.New(bizerror.ConfigError, fmt.Sprintf("default log provider %q is not configured", c.DefaultProvider)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (c *LogsConfig) Default() (LogProviderConfig, bool) { | ||
| if c == nil { | ||
| return LogProviderConfig{}, false | ||
| } | ||
| for _, provider := range c.Providers { | ||
| if provider.Name == c.DefaultProvider { | ||
| return provider, true | ||
| } | ||
| } | ||
| return LogProviderConfig{}, false | ||
| } |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done