技能 编程开发 Glean多环境配置与部署

Glean多环境配置与部署

v20260423
glean-multi-env-setup
本技能用于指导Glean企业搜索在开发、预发布和生产环境中的配置与部署,核心在于实现环境隔离。它指导用户如何使用不同的数据源和API凭证来管理Dev、Staging和Prod环境,涵盖了完整的推广工作流、环境验证和错误处理,确保系统稳定性和搜索结果的准确性。
获取技能
154 次下载
概览

Glean Multi-Environment Setup

Overview

Glean enterprise search requires environment isolation to prevent test data from polluting production search results. Each environment uses its own datasource names, API tokens, and connector configurations. Sandbox indexes synthetic test documents, staging indexes a curated subset of real documents for search quality validation, and production indexes the full corpus. Connector changes must be tested in staging before promotion to avoid breaking search relevance for end users.

Environment Configuration

const gleanConfig = (env: string) => ({
  development: {
    apiToken: process.env.GLEAN_API_TOKEN_DEV!, baseUrl: "https://sandbox.glean.com/api/v1",
    datasourceSuffix: "_sandbox", indexingEnabled: true, searchQualityChecks: false,
  },
  staging: {
    apiToken: process.env.GLEAN_API_TOKEN_STG!, baseUrl: "https://staging.glean.com/api/v1",
    datasourceSuffix: "_staging", indexingEnabled: true, searchQualityChecks: true,
  },
  production: {
    apiToken: process.env.GLEAN_API_TOKEN_PROD!, baseUrl: "https://app.glean.com/api/v1",
    datasourceSuffix: "_prod", indexingEnabled: true, searchQualityChecks: false,
  },
}[env]);

Environment Files

# Per-env files: .env.development, .env.staging, .env.production
GLEAN_API_TOKEN_{DEV|STG|PROD}=<token>
GLEAN_BASE_URL=https://{sandbox|staging|app}.glean.com/api/v1
GLEAN_DATASOURCE_SUFFIX={_sandbox|_staging|_prod}
GLEAN_INSTANCE={sandbox|staging|production}

Environment Validation

function validateGleanEnv(env: string): void {
  const suffix = { development: "_DEV", staging: "_STG", production: "_PROD" }[env];
  const required = [`GLEAN_API_TOKEN${suffix}`, "GLEAN_BASE_URL", "GLEAN_INSTANCE"];
  const missing = required.filter((k) => !process.env[k]);
  if (missing.length) throw new Error(`Missing Glean env vars for ${env}: ${missing.join(", ")}`);
}

Promotion Workflow

# 1. Index test documents in sandbox
curl -X POST "$GLEAN_BASE_URL/indexing/datasources/wiki_sandbox/documents" \
  -H "Authorization: Bearer $GLEAN_API_TOKEN_DEV" -d @test-docs.json

# 2. Validate search quality in staging
curl "$GLEAN_BASE_URL/search" -H "Authorization: Bearer $GLEAN_API_TOKEN_STG" \
  -d '{"query": "onboarding guide"}' | jq '.results[:3].title'

# 3. Compare relevance scores against baseline
node scripts/compare-search-quality.js --env staging --baseline baseline.json

# 4. Promote connector config to production
cp connectors/staging/*.json connectors/production/
curl -X POST "$GLEAN_BASE_URL/indexing/datasources/wiki_prod/crawl" \
  -H "Authorization: Bearer $GLEAN_API_TOKEN_PROD"

Environment Matrix

SettingDev (Sandbox)StagingProd
Data SourceSynthetic test docsSubset of real docsFull document index
Datasource Suffix_sandbox_staging_prod
ConnectorsMock connectorsReal connectorsReal connectors
User AccessDevelopers onlyQA + developersAll employees
Crawl FrequencyManualDailyContinuous

Error Handling

IssueCauseFix
Datasource not foundSuffix mismatch between env and configVerify GLEAN_DATASOURCE_SUFFIX matches connector registration
401 on indexing APIToken scoped to wrong instanceRegenerate token in the correct Glean admin console
Search returns stale resultsCrawl not triggered after promotionManually trigger crawl via indexing API
Connector sync failsOAuth credentials expired for data sourceRe-authorize connector in Glean admin for the target env
Staging indexes prod dataConnector config copied without suffix updateAlways update datasource names when promoting configs

Resources

Next Steps

See glean-deploy-integration.

信息
分类 编程开发
名称 glean-multi-env-setup
版本 v20260423
大小 4.39KB
更新时间 2026-04-28
语言