Skip to content

[v0/v1 migration] FilterStatVarsByEntity migration#1898

Open
nick-nlb wants to merge 6 commits into
datacommonsorg:masterfrom
nick-nlb:v2-migration-variable-filter
Open

[v0/v1 migration] FilterStatVarsByEntity migration#1898
nick-nlb wants to merge 6 commits into
datacommonsorg:masterfrom
nick-nlb:v2-migration-variable-filter

Conversation

@nick-nlb
Copy link
Copy Markdown
Contributor

Issue

b/513324218

Description

The api/stats/stat-var-search was broken under the following circumstances:

  • VAI was enabled
  • BT was not in use
  • Entities were passed into the payload (these are used to filter the results from VAI.

No results were returned in these circumstances (whereas results were successfully filtered by sv/entity observation existence and returned when using BT).

The reason for this was that FilterStatVarsByEntity had not been migrated and was relying on the existence of the BT cache.

This PR creates a v3 (and diverted v2) implementation of the FilterStatVarsByEntity.

Testing

The problem is immediately visible on the dev scatter tool.

You can replicate it by:

  • opening up the hierarchy without choosing a place and searching for "farms"
  • the search will work (bring up results) as no filtering is occurring.
  • delete the search from the search bar
  • select United States as a place and "Counties" as the breakdown contained place.
  • once again, search for "farms"
  • you will now get no results.

Performing the same steps on production will give you a list of farm related stat vars that have been filtered to show only ones relevant to the place chosen.

Local Testing

To replicate the scenario we see in dev, you can start mixer with:

./run_server.sh \
    --feature_flags_path=$PWD/deploy/featureflags/local.yaml \
    --spanner_graph_info="$(cat deploy/storage/spanner_graph_info.yaml)" \
    --use_spanner_graph=true \
    --use_base_bigtable=false

The key flag is use_base_bigtable. By setting it to false, we disable BT, and in fact, we should be doing all our local testing this way if we want to truly test a Spanner only environment.

With big table set to false, in master you will see the same error as in dev. In this branch, you will see filtered results that should be identical to those found in production.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements the FilterStatVarsByEntity method across the server architecture, including updates to the DataSource interface, dispatcher, and V2/V3 handlers. Specific implementations were added for Spanner, remote clients, and SQL data sources, supported by new unit tests and golden files. Review feedback suggests refining the response merging logic in DataSources to prevent potential nil pointer dereferences and optimizing the Spanner implementation with an early return when the input variable list is empty to avoid unnecessary database queries.

Comment thread internal/server/datasources/datasources.go Outdated
Comment thread internal/server/spanner/datasource.go
@nick-nlb nick-nlb marked this pull request as ready for review May 15, 2026 23:39
@nick-nlb nick-nlb requested a review from clincoln8 May 15, 2026 23:39
Copy link
Copy Markdown
Contributor

@clincoln8 clincoln8 left a comment

Choose a reason for hiding this comment

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

Thanks Nick, this is beautifully done!

Just a small nit to add some error logging. Mixer has been historically lacking in helpful logging/debugging traces, so we're trying to push for more observability in general (of course where reasonable).

resp := &pb.FilterStatVarsByEntityResponse{}
err := util.FetchRemote(rc.metadata, rc.httpClient, "/v2/variable/filter", req, resp)
if err != nil {
return nil, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: consider logging an error here before returning


rows, err := sds.client.CheckVariableExistence(ctx, ids, entities)
if err != nil {
return nil, fmt.Errorf("error checking variable existence: %w", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: either log an error here or ensure that that lower level method CheckVariableExistence has adequate logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants