Skip to content
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
18 changes: 18 additions & 0 deletions cmd/fanout-docgen/mcptools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package main
import (
"context"
"fmt"
"sort"
"strings"

"github.com/labstack/fanout/internal/mcp"
"github.com/labstack/fanout/internal/panel"
)

// toolCount is set by renderMCPTools so the summary line can report it.
Expand Down Expand Up @@ -150,6 +152,22 @@ func renderMCPTools() ([]byte, error) {
b.WriteString("\n")
}

b.WriteString("## Panel SQL relations\n\n")
relations := panel.SQLRelations()
names := make([]string, 0, len(relations))
for name := range relations {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
relation := relations[name]
fmt.Fprintf(&b, "### %s\n\n%s\n\n", name, mdx(relation.Description))
b.WriteString("| Column | SQL type | Means |\n|---|---|---|\n")
for _, column := range relation.Columns {
fmt.Fprintf(&b, "| `%s` | `%s` | %s |\n", column.Name, column.SQLType, cell(column.Description))
}
b.WriteString("\n")
}
b.WriteString("## Authentication\n\n")
b.WriteString("MCP uses OAuth, not a static key, and **not the ingest token** — an agent\n")
b.WriteString("presenting the ingest token is rejected. A client discovers the endpoints,\n")
Expand Down
9 changes: 9 additions & 0 deletions internal/agent/dashboard_eval_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func TestDashboardEvalGoldensCurrent(t *testing.T) {
t.Fatal(err)
}
defer tools.Close()
foundInventoryGuide := false
for _, definition := range tools.Definitions() {
if definition.Name == "create_dashboard" {
foundInventoryGuide = strings.Contains(definition.Description, "resource_inventory") && strings.Contains(definition.Description, "actual in-window event times") && strings.Contains(definition.Description, "not events or instances")
}
}
if !foundInventoryGuide {
t.Fatal("embedded AI tools lost the shared MCP inventory guidance")
}
ctx := dashboard.WithOwner(t.Context(), "owner")
authored := panel.Dashboard{Name: "Eval fixture", Time: panel.Time{From: &from, To: &to}, Panels: []panel.Panel{
{ID: "actual_latency", Title: "Latency", Viz: "stat", Query: &panel.Query{From: "spans", Measures: []string{"p95(duration_ms)"}, Where: []string{"service = 'checkout'", "namespace = 'shop'"}}, Unit: "ms", Thresholds: []panel.Threshold{{Value: 100, Status: "warn"}}},
Expand Down
4 changes: 2 additions & 2 deletions internal/api/panels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (f *fakePanels) ResolveVariables(context.Context, panel.ResolveRequest) (ma
}

func (f *fakePanels) Schema(_ context.Context, req panel.SchemaRequest) (*panel.Schema, error) {
return &panel.Schema{Window: req.Window}, nil
return &panel.Schema{Window: req.Window, SQLRelations: panel.SQLRelations()}, nil
}

func servePanels(t *testing.T, engine PanelEngine, method, path, body string) *httptest.ResponseRecorder {
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestVariableAndSchemaRoutes(t *testing.T) {
t.Fatalf("resolve %d %s", rec.Code, rec.Body)
}
rec = servePanels(t, &fakePanels{}, http.MethodGet, "/api/telemetry/schema?window=6h", "")
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `"window":"6h"`) {
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `"window":"6h"`) || !strings.Contains(rec.Body.String(), `"sql_relations":{"resource_inventory":`) || !strings.Contains(rec.Body.String(), `"sql_type":"TIMESTAMPTZ_NS"`) {
t.Fatalf("schema %d %s", rec.Code, rec.Body)
}
}
Expand Down
8 changes: 2 additions & 6 deletions internal/dashboard/defaults_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const reachabilitySQL = `WITH raw AS (
AND time < $__to::TIMESTAMP_NS::TIMESTAMPTZ_NS AND name='httpcheck.status' QUALIFY row_number() OVER (PARTITION BY series_id,time ORDER BY ingested_unix_nano DESC,value DESC)=1),
keyed AS (SELECT *,to_json([namespace,url,method,host])::VARCHAR AS entity,
coalesce(namespace,'')||' / '||coalesce(method,'method unknown')||' '||coalesce(url,'endpoint unknown')||' from '||coalesce(host,'vantage unknown') AS endpoint_from FROM raw),
service_hosts AS (SELECT DISTINCT namespace,resource['host.name']::VARCHAR AS host FROM spans WHERE $__window(start_time) AND service IS NOT NULL AND service<>''),
service_hosts AS (SELECT DISTINCT namespace,resource['host.name']::VARCHAR AS host FROM resource_inventory WHERE signal='spans' AND $__window(first_seen) AND service IS NOT NULL AND service<>''),
check_hosts AS (SELECT DISTINCT namespace,host FROM keyed WHERE $__window(time)),
vantage AS (SELECT count(*)>0 AND bool_and(coalesce(host<>'',false) AND EXISTS (SELECT 1 FROM service_hosts s WHERE s.namespace=check_hosts.namespace AND s.host=check_hosts.host)) AS all_local FROM check_hosts),
inventory AS (SELECT DISTINCT entity,endpoint_from||CASE WHEN all_local THEN ' (all checks run on service hosts; outside reachability unverified)' ELSE '' END AS endpoint_from FROM keyed CROSS JOIN vantage WHERE $__window(time)),
Expand Down Expand Up @@ -111,8 +111,4 @@ func containerCapacitySQL() string {
FROM results ORDER BY (reporting<>'reporting') DESC,status DESC NULLS LAST,namespace,host,container`
}

const versionObservationsSQL = `WITH resources AS MATERIALIZED (
SELECT namespace,service,resource,min(start_time) AS seen FROM spans WHERE $__window(start_time) GROUP BY namespace,service,resource
UNION ALL SELECT namespace,service,resource,min(time) AS seen FROM logs WHERE $__window(time) GROUP BY namespace,service,resource
UNION ALL SELECT namespace,service,resource,min(time) AS seen FROM metrics WHERE $__window(time) GROUP BY namespace,service,resource)
SELECT namespace,service,resource['service.version']::VARCHAR AS version,resource['process.runtime.name']::VARCHAR AS runtime_name,resource['process.runtime.version']::VARCHAR AS runtime_version,resource['telemetry.sdk.language']::VARCHAR AS sdk_language,resource['telemetry.sdk.version']::VARCHAR AS sdk_version,seen FROM resources`
const versionObservationsSQL = `SELECT namespace,service,resource['service.version']::VARCHAR AS version,resource['process.runtime.name']::VARCHAR AS runtime_name,resource['process.runtime.version']::VARCHAR AS runtime_version,resource['telemetry.sdk.language']::VARCHAR AS sdk_language,resource['telemetry.sdk.version']::VARCHAR AS sdk_version,first_seen AS seen FROM resource_inventory WHERE $__window(first_seen)`
Loading
Loading