fix: trace opencode provider requests

This commit is contained in:
UniDesk Codex
2026-06-30 11:20:18 +08:00
parent 5863a51188
commit 00ebac6639
9 changed files with 667 additions and 16 deletions
+61 -6
View File
@@ -5645,13 +5645,20 @@ function opencodeRuntimeConfigForProfile(deploy, profile) {
const apiKeyEnv = configString(config.apiKeyEnv) || opencodeApiKeyEnvName(providerId);
const contextLimit = opencodePositiveInteger(config.contextLimit, 1000000, `deploy.lanes.${profile}.opencode.contextLimit`);
const outputLimit = opencodePositiveInteger(config.outputLimit, 384000, `deploy.lanes.${profile}.opencode.outputLimit`);
const upstreamBaseURL = configString(config.upstreamBaseURL) || configString(config.baseURL) || "https://opencode.ai/zen/go/v1";
const providerProxyPort = opencodePositiveInteger(config.providerProxyPort, 4097, `deploy.lanes.${profile}.opencode.providerProxyPort`);
const providerProxyBasePath = configString(config.providerProxyBasePath) || "/v1";
const providerProxyBaseURL = configString(config.providerProxyBaseURL) || `http://127.0.0.1:${providerProxyPort}${providerProxyBasePath}`;
return {
providerProfile,
providerId,
displayName: configString(config.displayName) || `AgentRun ${providerProfile}`,
model,
smallModel,
baseURL: configString(config.baseURL) || "https://opencode.ai/zen/go/v1",
baseURL: providerProxyBaseURL,
upstreamBaseURL,
providerProxyPort,
providerProxyBasePath,
npm: configString(config.npm) || "@ai-sdk/openai-compatible",
apiKeyEnv,
apiKeySecretRef: configString(config.apiKeySecretRef) || "hwlab-code-agent-provider/opencode-api-key",
@@ -5710,10 +5717,19 @@ function opencodeConfigContent(config) {
});
}
function opencodeServerManifest({ profile = "v03", source, deploy = null }) {
function opencodeServerManifest({ profile = "v03", source, deploy = null, catalog = null, registryPrefix = defaultRegistryPrefix, useDeployImages = false, sourceBranch = defaultBranch, gitReadUrl = defaultV02GitReadUrl, sourceRepo = defaultSourceRepo }) {
assert.ok(isRuntimeLane(profile), `opencode-server profile must be a runtime lane, got ${profile}`);
const namespace = namespaceNameForProfile(profile);
const name = "opencode-server";
const helperServiceId = "hwlab-cloud-web";
const envReuseServiceIds = envReuseServiceIdsForLane(deploy, profile);
const helperImage = runtimeImageForService({ catalog, deploy, serviceId: helperServiceId, source, registryPrefix, useDeployImages, digestPin: true, envReuseServiceIds });
const helperCommit = runtimeCommitForService({ catalog, deploy, serviceId: helperServiceId, source, registryPrefix, useDeployImages, digestPin: true, envReuseServiceIds });
const helperImageTag = runtimeImageTagForService({ catalog, deploy, serviceId: helperServiceId, source, registryPrefix, useDeployImages, digestPin: true, envReuseServiceIds });
const providerProxyBootSh = "deploy/runtime/boot/opencode-provider-proxy.sh";
const providerProxyBootMetadata = v02EnvReuseEnabled(catalog, helperServiceId, envReuseServiceIds)
? bootMetadataForService({ args: { sourceRepo: deploy?.lanes?.[profile]?.sourceRepo || sourceRepo, registryPrefix }, catalog, deployService: deployServiceForBoot(deploy, helperServiceId, profile), serviceId: helperServiceId, source })
: null;
const selector = {
"app.kubernetes.io/name": name,
"app.kubernetes.io/part-of": "hwlab",
@@ -5736,12 +5752,23 @@ function opencodeServerManifest({ profile = "v03", source, deploy = null }) {
"hwlab.pikastech.local/opencode-provider-profile": opencodeConfig.providerProfile,
"hwlab.pikastech.local/opencode-provider-id": opencodeConfig.providerId,
"hwlab.pikastech.local/opencode-model": opencodeConfig.model,
"hwlab.pikastech.local/opencode-provider-base-url": opencodeConfig.baseURL,
"hwlab.pikastech.local/opencode-provider-upstream-base-url": opencodeConfig.upstreamBaseURL,
"hwlab.pikastech.local/opencode-config-sha256": configSha256,
"hwlab.pikastech.local/opencode-api-key-secret-ref": `${apiKeySecretRef.name}/${apiKeySecretRef.key}`,
"hwlab.pikastech.local/agentrun-provider-secret-ref": `${opencodeConfig.agentrunSecretNamespace}/${opencodeConfig.agentrunSecretName}`,
"hwlab.pikastech.local/agentrun-provider-secret-keys": opencodeConfig.agentrunSecretKeys.join(","),
"hwlab.pikastech.local/values-printed": "false"
};
if (providerProxyBootMetadata) {
Object.assign(annotations, {
"hwlab.pikastech.local/opencode-provider-proxy-runtime-mode": providerProxyBootMetadata.runtimeMode,
"hwlab.pikastech.local/opencode-provider-proxy-boot-repo": providerProxyBootMetadata.bootRepo,
"hwlab.pikastech.local/opencode-provider-proxy-boot-commit": providerProxyBootMetadata.bootCommit,
"hwlab.pikastech.local/opencode-provider-proxy-boot-sh": providerProxyBootSh,
"hwlab.pikastech.local/opencode-provider-proxy-environment-digest": providerProxyBootMetadata.environmentDigest ?? "not_published"
});
}
const authSecretName = secretNameForProfile("hwlab-opencode-server-auth", profile);
return {
apiVersion: "v1",
@@ -5788,8 +5815,8 @@ function opencodeServerManifest({ profile = "v03", source, deploy = null }) {
name,
image: "ghcr.io/anomalyco/opencode:1.17.7",
imagePullPolicy: "IfNotPresent",
command: ["opencode"],
args: ["serve", "--hostname", "0.0.0.0", "--port", "4096"],
command: ["/bin/sh", "-ec"],
args: ["if ! command -v git >/dev/null 2>&1; then apk add --no-cache git; fi\nexec opencode serve --hostname 0.0.0.0 --port 4096"],
workingDir: "/workspace",
env: [
{ name: "HOME", value: "/workspace" },
@@ -5806,7 +5833,35 @@ function opencodeServerManifest({ profile = "v03", source, deploy = null }) {
livenessProbe: { tcpSocket: { port: "http" }, periodSeconds: 20, failureThreshold: 3 },
resources: { requests: { cpu: "100m", memory: "256Mi" }, limits: { cpu: "1", memory: "1Gi" } },
volumeMounts: [{ name: "workspace", mountPath: "/workspace" }]
}],
}, (() => {
const container = {
name: "opencode-provider-proxy",
image: helperImage,
imagePullPolicy: "IfNotPresent",
command: ["node", "/app/internal/dev-entrypoint/opencode-provider-proxy.mjs"],
env: [
{ name: "HWLAB_SERVICE_ID", value: "opencode-provider-proxy" },
{ name: "HWLAB_ENVIRONMENT", value: profile },
{ name: "HWLAB_COMMIT_ID", value: helperCommit },
{ name: "HWLAB_IMAGE", value: helperImage },
{ name: "HWLAB_IMAGE_TAG", value: helperImageTag },
{ name: "PORT", value: String(opencodeConfig.providerProxyPort) },
{ name: "HWLAB_OPENCODE_PROVIDER_PROXY_UPSTREAM_BASE_URL", value: opencodeConfig.upstreamBaseURL },
{ name: "HWLAB_OPENCODE_PROVIDER_PROXY_PUBLIC_BASE_PATH", value: opencodeConfig.providerProxyBasePath },
{ name: "HWLAB_OPENCODE_PROVIDER_PROXY_TIMEOUT_MS", value: "600000" },
{ name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", value: "http://otel-collector.platform-infra.svc.cluster.local:4318/v1/traces" },
{ name: "OTEL_SERVICE_NAME", value: "opencode-provider-proxy" }
],
ports: [{ name: "provider", containerPort: opencodeConfig.providerProxyPort }],
readinessProbe: { httpGet: { path: "/health/readiness", port: "provider" }, periodSeconds: 10, failureThreshold: 3 },
livenessProbe: { httpGet: { path: "/health/live", port: "provider" }, periodSeconds: 20, failureThreshold: 3 },
resources: { requests: { cpu: "25m", memory: "64Mi" }, limits: { cpu: "250m", memory: "256Mi" } }
};
if (providerProxyBootMetadata) {
applyEnvReuseBootEnv(container, providerProxyBootMetadata, { sourceBranch, gitReadUrl, bootSh: providerProxyBootSh });
}
return container;
})()],
volumes: [{ name: "workspace", persistentVolumeClaim: { claimName: `${name}-data` } }]
}
}
@@ -5991,7 +6046,7 @@ async function plannedFiles(args) {
if (workbenchRedis) putJson(`${runtimePath}/workbench-redis.yaml`, workbenchRuntimeRedisManifest({ profile, config: workbenchRedis, source }));
if (isRuntimeLane(profile)) putJson(`${runtimePath}/openfga.yaml`, v02OpenFgaManifest({ profile, source }));
if (isRuntimeLane(profile)) putJson(`${runtimePath}/observability.yaml`, observabilityManifest({ deploy, profile, namespace, labels: profileLabels, annotations, metricsSidecarScript }));
if (isRuntimeLane(profile)) putJson(`${runtimePath}/opencode.yaml`, opencodeServerManifest({ profile, source, deploy }));
if (isRuntimeLane(profile)) putJson(`${runtimePath}/opencode.yaml`, opencodeServerManifest({ profile, source, deploy, catalog: artifactCatalog, registryPrefix: args.registryPrefix, useDeployImages: args.useDeployImages, sourceBranch: args.sourceBranch, gitReadUrl: args.gitReadUrl, sourceRepo: args.sourceRepo }));
if (includeDeviceAgent) putJson(`${runtimePath}/device-agent-71-freq.yaml`, deviceAgent71FreqManifest({ profile, source, registryPrefix: args.registryPrefix, catalog: artifactCatalog, useDeployImages: args.useDeployImages }));
putJson(`${runtimePath}/node-frpc.yaml`, nodeFrpcManifest({ profile, source }));
}