1
0
mirror of synced 2025-12-23 11:54:18 -05:00

use prefix for ES indexes for tests (#30288)

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
This commit is contained in:
Peter Bengtsson
2022-08-26 23:10:30 +02:00
committed by GitHub
parent 83680f30b0
commit d977d39536
3 changed files with 29 additions and 4 deletions

View File

@@ -43,6 +43,20 @@ const legacyEnterpriseServerVersions = Object.fromEntries(
})
)
function getIndexPrefix() {
// This logic is mirrored in the scripts we use before running tests
// In particular, see the `index-test-fixtures` npm script.
// That's expected to be run before CI and local jest testing.
// The reason we have a deliberately different index name (by prefix)
// for testing compared to regular operation is to make it convenient
// for engineers working on local manual testing *and* automated
// testing without have to re-index different content (e.g. fixtures
// vs real content) on the same index name.
if (process.env.NODE_ENV === 'test') return 'tests_'
return ''
}
function convertLegacyVersionName(version) {
// In the olden days we used to use `?version=3.5&...` but we decided
// that's ambiguous and it should be `ghes-3.5` instead.
@@ -87,7 +101,10 @@ router.get(
return res.status(200).json([])
}
const indexName = `github-docs-${convertLegacyVersionName(version)}-${language}`
const indexName = `${getIndexPrefix()}github-docs-${convertLegacyVersionName(
version
)}-${language}`
const hits = []
try {
const searchResults = await getSearchResults({
@@ -205,7 +222,7 @@ const validationMiddleware = (req, res, next) => {
const version = versionAliases[search.version] || allVersions[search.version].miscVersionName
search.indexName = `github-docs-${version}-${search.language}` // github-docs-ghes-3.5-en
search.indexName = `${getIndexPrefix()}github-docs-${version}-${search.language}` // github-docs-ghes-3.5-en
req.search = search
return next()

View File

@@ -183,7 +183,7 @@
"build": "next build",
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon --inspect server.js",
"dev": "cross-env npm start",
"index-test-fixtures": "node script/search/index-elasticsearch.js -s tests/content/fixtures/search-indexes -l en -V ghae -V dotcom",
"index-test-fixtures": "node script/search/index-elasticsearch.js -s tests/content/fixtures/search-indexes -l en -V ghae -V dotcom --index-prefix tests",
"lint": "eslint '**/*.{js,mjs,ts,tsx}'",
"lint-translation": "cross-env NODE_OPTIONS=--experimental-vm-modules TEST_TRANSLATION=true jest tests/linting/lint-files.js",
"prepare": "husky install",

View File

@@ -13,11 +13,15 @@ import path from 'path'
import { Client } from '@elastic/elasticsearch'
import { program, Option } from 'commander'
import chalk from 'chalk'
import dotenv from 'dotenv'
import { languageKeys } from '../../lib/languages.js'
import { allVersions } from '../../lib/all-versions.js'
import { decompress } from '../../lib/search/compress.js'
// Now you can optionally have set the ELASTICSEARCH_URL in your .env file.
dotenv.config()
// Create an object that maps the "short name" of a version to
// all information about it. E.g
//
@@ -61,6 +65,7 @@ program
'-s, --source-directory <DIRECTORY>',
`Directory where records files are (default ${DEFAULT_SOURCE_DIRECTORY})`
)
.option('-p, --index-prefix <prefix>', 'Index string to put before index name')
.parse(process.argv)
main(program.opts())
@@ -122,10 +127,13 @@ async function main(opts) {
console.log(`Indexing on languages ${chalk.bold(languages.join(', '))}`)
}
const { indexPrefix } = opts
const prefix = indexPrefix ? `${indexPrefix}_` : ''
for (const language of languages) {
for (const versionKey of versionKeys) {
console.log(chalk.yellow(`Indexing ${chalk.bold(versionKey)} in ${chalk.bold(language)}`))
const indexName = `github-docs-${versionKey}-${language}`
const indexName = `${prefix}github-docs-${versionKey}-${language}`
console.time(`Indexing ${indexName}`)
await indexVersion(client, indexName, versionKey, language, sourceDirectory, verbose)