Skip to content

Conversation

@fisx
Copy link
Contributor

@fisx fisx commented Jan 14, 2026

https://wearezeta.atlassian.net/browse/WPB-21366

brig-index needs to talk to postgres now. this PR adds --config-file brig.yaml to its cli.

this makes the already complicated cli even more complicated and also partially redundant. cleaning this up is left as FUTUREWORK.

This work is based on an earlier, failed attempt

Checklist

  • Add a new entry in an appropriate subdirectory of changelog.d
  • Read and follow the PR guidelines

@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Jan 14, 2026
@fisx fisx force-pushed the WPB-21366-refactor-brig-index-cli branch 5 times, most recently from 0fdbd99 to 06df69c Compare January 16, 2026 07:38
@fisx
Copy link
Contributor Author

fisx commented Jan 16, 2026

manual testing

Apply this patch:

modified   integration/test/Test/Apps.hs
@@ -21,7 +21,9 @@ module Test.Apps where

 import API.Brig
 import qualified API.BrigInternal as BrigI
 import SetupHelpers
+import System.IO (appendFile)
 import Testlib.Prelude

 testCreateApp :: (HasCallStack) => App ()
@@ -53,6 +55,14 @@ testCreateApp = do
   bindResponse (getUser owner appIdObject) $ \resp -> do
     resp.status `shouldMatchInt` 200
     resp.json %. "type" `shouldMatch` "app"
+    ownerId <- owner %. "id" >>= asString
+    liftIO do
+      appendFile "/tmp/debug" ("OWNER=" <> ownerId <> "\n")
+      appendFile "/tmp/debug" ("TEAM=" <> tid <> "\n")
+      appendFile "/tmp/debug" ("APP=" <> appId <> "\n")

   -- Creator should have type "regular"
   bindResponse (getUser owner owner) $ \resp -> do

Then create an "old" app without the types field in UserDoc:

$ git co 3a9ffecd6a3ea7ba66c4967af7cfa6433dddeff1~1
$ rm -f /tmp/debug ; make ci-safe package=integration TEST_INCLUDE=testCreateApp

The "old" app is now generated, and /tmp/debug now contains team id, owner id, and app details. with that, we can first check if the app has been created properly, and then build the search query:

$ . /tmp/debug
$ make cr

make cr deletes ES indices, so we need to create them again from cassandra:

$ ./dist/brig-index reindex \
    --elasticsearch-server https://localhost:9200 \
    --elasticsearch-ca-cert ./libs/wire-subsystems/test/resources/elasticsearch-ca.pem \
    --elasticsearch-credentials ./libs/wire-subsystems/test/resources/elasticsearch-credentials.yaml
$ curl -X GET -H 'Z-Connection: conn' -H "Z-User: $OWNER" "http://127.0.0.1:8082/v15/teams/$TEAM/apps/$APP" | jq .
{
  "accent_id": 0,
  "assets": [],
  "category": "ai",
  "description": "some description of this app",
  "metadata": {},
  "name": "chappie",
  "picture": []
}

$ curl -v -X GET -H 'Z-Connection: conn' -H "Z-User: $OWNER" "http://127.0.0.1:8082/v15/users/example.com/$APP" | jq .type
"app"
$ curl -X GET -H 'Z-Connection: conn' -H "Z-User: $OWNER" "http://127.0.0.1:8082/v15/search/contacts?q=chappie&domain=example.com" | jq .documents
[
  {
    "accent_id": 0,
    "handle": null,
    "id": "660158b5-a535-4552-9eb6-bdfc262a5da1",
    "name": "chappie",
    "qualified_id": {
      "domain": "example.com",
      "id": "660158b5-a535-4552-9eb6-bdfc262a5da1"
    },
    "team": "894f3e29-5b1f-452d-bdbf-47fd5dfeb135"
  }
]

Note that there is no type field, that's expected because we're on an old commit. Now back to where ES indexing supports user type:

$ git co WPB-21366-refactor-brig-index-cli
$ make cr
$ curl -X GET -H 'Z-Connection: conn' -H "Z-User: $OWNER" "http://127.0.0.1:8082/v15/teams/$TEAM/apps/$APP" | jq .name
"chappie"
$ curl -X GET -H 'Z-Connection: conn' -H "Z-User: $OWNER" "http://127.0.0.1:8082/v15/search/contacts?q=chappie&domain=example.com" | jq .documents
[]

Damn, make cr destroyed the indices again!

$ make es-reindex
$ curl -X GET -H 'Z-Connection: conn' -H "Z-User: $OWNER" "http://127.0.0.1:8082/v15/search/contacts?q=chappie&domain=example.com" | jq .documents[0].type
"app"

@fisx fisx marked this pull request as ready for review January 19, 2026 08:14
@fisx fisx requested review from a team as code owners January 19, 2026 08:14
@fisx fisx requested a review from Copilot January 19, 2026 08:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the brig-index CLI tool to use the main brig.yaml configuration file instead of requiring redundant CLI parameters. This change was necessary because brig-index now needs to access PostgreSQL, which would have made the CLI even more bloated with additional parameters.

Changes:

  • Added a --config-file flag to brig-index that reads brig.yaml for connection settings (Elasticsearch, Cassandra, PostgreSQL, Galley)
  • Enabled the getUserType function to properly distinguish between regular users, bots, and app users by integrating AppStore access
  • Updated all invocations of brig-index across tests, Makefile, integration scripts, and Helm charts to use the new config file approach

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
services/brig/index/src/Main.hs Added config file parser and loading logic using --config-file flag
services/brig/src/Brig/Index/Eval.hs Updated runCommand and runSem to accept Brig.Opts; added PostgreSQL pool initialization and AppStore interpreter
services/brig/src/Brig/Index/Options.hs Added FUTUREWORK comment about further simplification opportunities
services/brig/test/integration/Index/Create.hs Updated test calls to runCommand with brigOpts parameter
services/brig/test/integration/API/Search.hs Updated test calls to runCommand with opts parameter
libs/wire-subsystems/src/Wire/IndexedUserStore/Bulk/ElasticSearch.hs Uncommented and enabled getUserType implementation with AppStore access
integration/test/Test/Apps.hs Enhanced tests to verify user types across team boundaries
integration/scripts/integration-dynamic-backends-brig-index.sh Updated to use --config-file flag
charts/elasticsearch-index/templates/migrate-data.yaml Added brig config/secrets volume mounts and --config-file argument
charts/elasticsearch-index/templates/create-index.yaml Added brig config/secrets volume mounts and config file arguments
Makefile Refactored es-reset to use --config-file and deduplicated db-migrate target
services/brig/brig.cabal Added yaml dependency to brig-index executable
changelog.d/5-internal/brig-index-config-dedup Added internal changelog entry
changelog.d/0-release-notes/WPB-21366-refactor-brig-index-cli Added release notes about PostgreSQL requirement

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fisx fisx force-pushed the WPB-21366-refactor-brig-index-cli branch 2 times, most recently from b2a39fe to 1891b46 Compare January 20, 2026 07:53
@fisx fisx force-pushed the WPB-21366-refactor-brig-index-cli branch 2 times, most recently from c7b862a to f73e596 Compare January 20, 2026 13:47
@fisx fisx requested a review from blackheaven January 20, 2026 14:56
fisx added 3 commits January 21, 2026 13:23
- new target "es-migrate" (must be separate from "es-reset" because to avoid cyclical dep with `make cr`)
- "cr" target now uses "es-reset" as dependency
- new target "postgres-migrate", make it dependency of "db-migrate"
- fix phonyness annotation of "postgres-schema"
@fisx fisx force-pushed the WPB-21366-refactor-brig-index-cli branch from 5d20fdc to 35c2c45 Compare January 21, 2026 12:26
@fisx fisx merged commit 294ee04 into develop Jan 21, 2026
11 checks passed
@fisx fisx deleted the WPB-21366-refactor-brig-index-cli branch January 21, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants