Loading...
Loading...
Compare original and translation side by side
perclipercli plugin test-schemaspercli plugin buildpackage modelclose({...})percli plugin test-schemaspercli plugin buildpercli plugin test-schemaspackage modelclose({...})percli plugin test-schemasschemas/<type>/<name>/migrate/migrate.cueschemas/<type>/<name>/migrate/migrate.cuepercli plugin startgithub.com/perses/shared/cue/commonpercli plugin startgithub.com/perses/shared/cue/commonpercli plugin generatepercli plugin generate| Cause | Symptom | Solution |
|---|---|---|
| "directory already exists" error | Remove or rename the existing directory, or generate into a different path |
| Unrecognized plugin type error | Use one of: Panel, Datasource, TimeSeriesQuery, TraceQuery, ProfileQuery, LogQuery, Variable, Explore |
| Missing required flag error | All four flags are required: |
| CUE schema compilation error: missing package | "cannot determine package name" | Add |
| CUE schema compilation error: unclosed close() | Syntax error in CUE | Ensure |
| CUE schema compilation error: bad import path | Import not found for shared types | Use exact path |
| JSON example does not match schema: extra fields | | Remove fields from JSON that are not defined in the CUE schema, or add them to the schema |
| JSON example does not match schema: wrong types | Type mismatch error | Ensure JSON values match CUE type declarations (string vs int vs bool) |
| JSON example does not match schema: missing required | Required field not present | Add all non-optional fields (those without |
| Archive missing mf-manifest.json | Run |
| Build cannot find plugin config | Run |
| 原因 | 症状 | 解决方案 |
|---|---|---|
| 提示「directory already exists」错误 | 删除或重命名现有目录,或在不同路径下生成项目 |
| 提示无法识别的插件类型错误 | 使用以下合法类型之一:Panel、Datasource、TimeSeriesQuery、TraceQuery、ProfileQuery、LogQuery、Variable、Explore |
| 提示缺少必填参数错误 | 四个参数均为必填: |
| CUE schema编译错误:缺少包声明 | 提示「cannot determine package name」 | 在.cue文件的导入语句后添加 |
| CUE schema编译错误:close()未闭合 | CUE语法错误 | 确保 |
| CUE schema编译错误:导入路径错误 | 共享类型导入未找到 | 使用精确路径 |
| JSON示例与schema不匹配:存在额外字段 | | 移除JSON中未在CUE schema定义的字段,或在schema中添加这些字段 |
| JSON示例与schema不匹配:类型错误 | 类型不匹配错误 | 确保JSON值与CUE类型声明一致(字符串、整数、布尔值等) |
| JSON示例与schema不匹配:缺少必填字段 | 必填字段不存在 | 向JSON示例中添加所有非可选字段(CUE中不带 |
| 归档包缺少mf-manifest.json | 先执行 |
| 构建无法找到插件配置 | 在模块根目录(package.json所在目录)执行 |
| Anti-Pattern | Why It Fails | Do Instead |
|---|---|---|
| Creating CUE schema without JSON example | | Always create both files together and run |
Not using | Without | Always wrap spec in |
| Skipping Grafana migration schema when equivalent exists | Users migrating from Grafana hit a dead end when no migration path exists for their panels | Check if a Grafana equivalent exists and create |
| Hard-coding default values in the React component | Users cannot configure the plugin's behavior through the dashboard JSON -- defaults are invisible | Define defaults as configurable fields in the CUE schema with sensible default values |
Copying schema from another plugin without adjusting | The | Always set |
| Building archive before running test-schemas | Schema errors ship in the archive and cause runtime failures on the Perses server | Run |
| 反模式 | 失败原因 | 正确做法 |
|---|---|---|
| 只创建CUE schema而不创建JSON示例 | | 始终同时创建两个文件,并立即运行 |
不为spec使用 | 没有 | 始终将spec包裹在 |
| 存在等效Grafana插件时跳过迁移schema | 从Grafana迁移的用户会因没有面板迁移路径而受阻 | 检查是否存在等效Grafana插件,若存在则创建 |
| 在React组件中硬编码默认值 | 用户无法通过仪表盘JSON配置插件行为——默认值不可见 | 在CUE schema中定义可配置的默认字段,并设置合理的默认值 |
从其他插件复制schema但未修改 | | 始终将 |
| 未运行test-schemas就构建归档包 | schema错误会被包含在归档包中,导致在Perses服务器运行时失败 | 运行 |
| Rationalization | Reality | Required Action |
|---|---|---|
| "The schema is simple, it doesn't need a JSON example" | Even simple schemas need validation -- typos in field names or types are invisible without a test | Create the JSON example and run test-schemas |
| "close() is too restrictive, I'll add it later" | Without close(), the schema validates nothing -- any garbage JSON passes | Add close() now, relax specific fields with |
| "The React component compiles so the plugin works" | React compilation says nothing about schema correctness or plugin registration | Run percli plugin test-schemas AND verify the archive structure |
| "I'll skip migration since most users start fresh" | Organizations migrating from Grafana are the primary adoption path -- migration is not optional when equivalents exist | Check for Grafana equivalent and create migration schema |
| "One test run passed, the schema is correct" | A single JSON example may not cover optional fields, edge cases, or constraint boundaries | Verify the example includes representative values for all fields |
| 错误理由 | 实际情况 | 必须执行的操作 |
|---|---|---|
| 「schema很简单,不需要JSON示例」 | 即使简单的schema也需要验证——字段名或类型的拼写错误在没有测试的情况下无法发现 | 创建JSON示例并运行test-schemas |
| 「close()太严格了,我之后再加」 | 没有close()时,schema不进行任何验证——任何无效JSON都会通过 | 立即添加close(),仅在必要时使用 |
| 「React组件编译通过了,所以插件没问题」 | React编译成功不代表schema正确或插件注册成功 | 运行percli plugin test-schemas并验证归档包结构 |
| 「我跳过迁移,因为大多数用户是从零开始使用」 | 从Grafana迁移的企业用户是主要的采用路径——存在等效插件时,迁移是必须的 | 检查是否存在等效Grafana插件并创建迁移schema |
| 「一次测试通过了,schema就正确了」 | 单个JSON示例可能无法覆盖可选字段、边缘情况或约束边界 | 确保示例包含所有字段的代表性值 |
percli plugin buildpercli plugin test-schemaspackage modelclose({...})kindpercli plugin test-schemaspercli plugin buildpackage modelclose({...})kindgithub.com/perses/shared/cue/commonpercli plugin generate \
--module.org=<org> \
--module.name=<name> \
--plugin.type=<Panel|Datasource|TimeSeriesQuery|TraceQuery|ProfileQuery|LogQuery|Variable|Explore> \
--plugin.name=<PluginName> \
<directory>percli plugin generate \
--module.org=<org> \
--module.name=<name> \
--plugin.type=<Panel|Datasource|TimeSeriesQuery|TraceQuery|ProfileQuery|LogQuery|Variable|Explore> \
--plugin.name=<PluginName> \
<directory>schemas/<plugin-type>/<plugin-name>/<plugin-name>.cuepackage model
import "github.com/perses/shared/cue/common" // 仅在需要共享类型时导入
kind: "<PluginName>"
spec: close({
// 必填字段(无?后缀)
field1: string
// 可选字段(带?后缀)
field2?: int
// 来自common的共享类型
format?: common.#format
})schemas/<plugin-type>/<plugin-name>/<plugin-name>.json{
"kind": "<PluginName>",
"spec": {
"field1": "example-value"
}
}schemas/<plugin-type>/<plugin-name>/migrate/migrate.cuepercli plugin test-schemaspercli plugin test-schemasschemas/<plugin-type>/<plugin-name>/<plugin-name>.cuepackage model
import "github.com/perses/shared/cue/common" // only if shared types needed
kind: "<PluginName>"
spec: close({
// Required fields (no ? suffix)
field1: string
// Optional fields (? suffix)
field2?: int
// Shared types from common
format?: common.#format
})schemas/<plugin-type>/<plugin-name>/<plugin-name>.json{
"kind": "<PluginName>",
"spec": {
"field1": "example-value"
}
}schemas/<plugin-type>/<plugin-name>/migrate/migrate.cuepercli plugin test-schemaspercli plugin test-schemassrc/<type>/<name>/src/<type>/<name>/undefinedundefined
**检查点**:所有schema测试通过。进入阶段5。
**Gate**: All schema tests pass. Proceed to Phase 5.percli plugin buildpercli plugin buildplugins-archive/plugins-archive/schemas/<plugin-type>/<plugin-name>/<plugin-name>.cueschemas/<plugin-type>/<plugin-name>/<plugin-name>.jsonschemas/<plugin-type>/<plugin-name>/migrate/migrate.cuesrc/<type>/<name>/github.com/perses/shared/cue/commonschemas/<plugin-type>/<plugin-name>/<plugin-name>.cueschemas/<plugin-type>/<plugin-name>/<plugin-name>.jsonschemas/<plugin-type>/<plugin-name>/migrate/migrate.cuesrc/<type>/<name>/github.com/perses/shared/cue/common