Add namespace_ancestry to issues index mapping
What does this MR do?
Related to #335825 (closed)
- Adds an Advanced Search migration to add a new mapping for the issues index. This mapping will hold
namespace_ancestry
in string format (example:group.id-subgroup.id-subsubgroup.id
) to allow prefix searching for group scoped issues searches. - Calculate the new field using the project namespace (method is flexible so it will support future implementation for other scopes: merge requests, notes, etc)
- Adds the new mapping to the issue mapping configuration (supports for new indexes created after this MR merges)
- Add new field to issue json document (if migration is completed)
- When groups or projects are transferred, we now always update the project and associated data in Elasticsearch. This is a slight change in behavior but required since we are now storing
namespace
data on associated documents - Some new helper methods + specs
Screenshots or Screencasts (strongly suggested)
How to setup and validate locally (strongly suggested)
Migration
Note: Ensure you have Elasticsearch enabled and setup for gdk. It is important that initial Elasticsearch setup is done on the default branch and not this branch. Otherwise the migration will already be marked as "completed" and you will not be able to test it using the steps below.
- open rails console
- run the migration using the background job:
Elastic::MigrationWorker.new.perform
- follow along in the
log/elasticsearch.log
file{"severity":"INFO","time":"2021-08-23T19:49:02.552Z","correlation_id":null,"message":"MigrationWorker: migration[AddNamespaceAncestryToIssuesMapping] executing migrate method"} {"severity":"INFO","time":"2021-08-23T19:49:02.559Z","correlation_id":null,"message":"[Elastic::Migration: 20210813134600] Adding namespace_ancestry to issues mapping"} {"severity":"INFO","time":"2021-08-23T19:49:02.655Z","correlation_id":null,"message":"MigrationWorker: migration[AddNamespaceAncestryToIssuesMapping] updating with completed: true"}
- verify that the mapping now contains the new field:
curl --request GET --url http://localhost:9200/gitlab-development-issues/_mappings
expand for mappings
{
"gitlab-development-issues-20210723-1604": {
"mappings": {
"dynamic": "strict",
"properties": {
"assignee_id": {
"type": "integer"
},
"author_id": {
"type": "integer"
},
"confidential": {
"type": "boolean"
},
"created_at": {
"type": "date"
},
"description": {
"type": "text"
},
"id": {
"type": "integer"
},
"iid": {
"type": "integer"
},
"issues_access_level": {
"type": "integer"
},
"namespace_ancestry": {
"type": "text",
"index_prefixes": {
"min_chars": 1,
"max_chars": 19
}
},
"project_id": {
"type": "integer"
},
"state": {
"type": "keyword"
},
"title": {
"type": "text"
},
"type": {
"type": "keyword"
},
"updated_at": {
"type": "date"
},
"upvotes": {
"type": "integer"
},
"visibility_level": {
"type": "integer"
}
}
}
}
}
Keeping documents up to date
Note: Migration should be run and completed
- create a new issue in a project (note the
id
of the new issue) - monitor the elasticsearch indexing in
log/elasticsearch.log
expand for logs
{"severity":"DEBUG","time":"2021-08-24T14:19:41.241Z","correlation_id":"01FDW8FW8BPQNZCSDH9RFBGB7C","class":"Elastic::ProcessBookkeepingService","redis_set":"elastic:incremental:updates:10:zset","message":"track_items","count":1,"tracked_items_encoded":"[[1,\"Issue 513 issue_513 project_41\"]]"}
{"severity":"INFO","time":"2021-08-24T14:20:22.246Z","correlation_id":"a87111226ed2b2f8899eff2175481698","message":"bulk_indexing_start","redis_set":"elastic:incremental:updates:10:zset","records_count":1,"first_score":1.0,"last_score":1.0}
{"severity":"INFO","time":"2021-08-24T14:20:22.381Z","correlation_id":"a87111226ed2b2f8899eff2175481698","message":"bulk_submitted","body_size_bytes":439,"bulk_count":1,"errors_count":0}
{"severity":"INFO","time":"2021-08-24T14:20:22.399Z","correlation_id":"a87111226ed2b2f8899eff2175481698","message":"bulk_indexing_end","redis_set":"elastic:incremental:updates:10:zset","records_count":1,"first_score":1.0,"last_score":1.0,"failures_count":0,"bulk_execution_duration_s":0.156389}
- verify that the issue has
namespace_ancestry
filled out in Elasticsearch (ex."namespace_ancestry": "26-109"
). repliace theid
below with the one from the first step
expand for curl
curl --request GET \
--url http://localhost:9200/gitlab-development-issues/_search \
--header 'Content-Type: application/json' \
--data '{
"query": {
"bool": {
"must": [
{
"match": {
"id": 513
}
}
]
}
},
"size": 500
}'
- create a new subgroup within the current namesapce
- move the project to the newly created subgroup
- monitor the elasticsearch indexing in
log/elasticsearch.log
expand for logs
{"severity":"DEBUG","time":"2021-08-24T14:25:39.904Z","correlation_id":"01FDW8TS8SGCX2XXRZP0MY7ZD7","class":"Elastic::ProcessBookkeepingService","redis_set":"elastic:incremental:updates:0:zset","message":"track_items","count":1,"tracked_items_encoded":"[[1,\"Project 41 project_41\"]]"}
{"severity":"DEBUG","time":"2021-08-24T14:25:40.322Z","correlation_id":"01FDW8TS8SGCX2XXRZP0MY7ZD7","class":"Elastic::ProcessInitialBookkeepingService","redis_set":"elastic:bulk:initial:0:zset","message":"track_items","count":1,"tracked_items_encoded":"[[1,\"Project 41 project_41\"]]"}
{"severity":"DEBUG","time":"2021-08-24T14:25:40.335Z","correlation_id":"01FDW8TS8SGCX2XXRZP0MY7ZD7","class":"Elastic::ProcessInitialBookkeepingService","redis_set":"elastic:bulk:initial:7:zset","message":"track_items","count":1,"tracked_items_encoded":"[[1,\"Issue 510 issue_510 project_41\"]]"}
{"severity":"DEBUG","time":"2021-08-24T14:25:40.337Z","correlation_id":"01FDW8TS8SGCX2XXRZP0MY7ZD7","class":"Elastic::ProcessInitialBookkeepingService","redis_set":"elastic:bulk:initial:1:zset","message":"track_items","count":1,"tracked_items_encoded":"[[1,\"Issue 511 issue_511 project_41\"]]"}
{"severity":"DEBUG","time":"2021-08-24T14:25:40.340Z","correlation_id":"01FDW8TS8SGCX2XXRZP0MY7ZD7","class":"Elastic::ProcessInitialBookkeepingService","redis_set":"elastic:bulk:initial:10:zset","message":"track_items","count":1,"tracked_items_encoded":"[[1,\"Issue 513 issue_513 project_41\"]]"}
{"severity":"DEBUG","time":"2021-08-24T14:25:41.568Z","correlation_id":"01FDW8TS8SGCX2XXRZP0MY7ZD7","message":"indexing_commit_range","project_id":41,"from_sha":"4b825dc642cb6eb9a060e54bf8d69288fbee4904","to_sha":"f7fc3155bfcdb72c3318c41d00b50a93ec64e6d1","index_wiki":false}
{"severity":"INFO","time":"2021-08-24T14:26:09.940Z","correlation_id":"2b8e8a68603ec65f1451f3ec1558d8aa","message":"bulk_indexing_start","redis_set":"elastic:incremental:updates:0:zset","records_count":1,"first_score":1.0,"last_score":1.0}
{"severity":"INFO","time":"2021-08-24T14:26:10.026Z","correlation_id":"2b8e8a68603ec65f1451f3ec1558d8aa","message":"bulk_submitted","body_size_bytes":697,"bulk_count":1,"errors_count":0}
{"severity":"INFO","time":"2021-08-24T14:26:10.044Z","correlation_id":"2b8e8a68603ec65f1451f3ec1558d8aa","message":"bulk_indexing_end","redis_set":"elastic:incremental:updates:0:zset","records_count":1,"first_score":1.0,"last_score":1.0,"failures_count":0,"bulk_execution_duration_s":0.104822}
{"severity":"INFO","time":"2021-08-24T14:26:10.383Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_indexing_start","redis_set":"elastic:bulk:initial:0:zset","records_count":1,"first_score":1.0,"last_score":1.0}
{"severity":"INFO","time":"2021-08-24T14:26:10.384Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_indexing_start","redis_set":"elastic:bulk:initial:1:zset","records_count":1,"first_score":1.0,"last_score":1.0}
{"severity":"INFO","time":"2021-08-24T14:26:10.386Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_indexing_start","redis_set":"elastic:bulk:initial:7:zset","records_count":1,"first_score":1.0,"last_score":1.0}
{"severity":"INFO","time":"2021-08-24T14:26:10.387Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_indexing_start","redis_set":"elastic:bulk:initial:10:zset","records_count":1,"first_score":1.0,"last_score":1.0}
{"severity":"INFO","time":"2021-08-24T14:26:10.675Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_submitted","body_size_bytes":2013,"bulk_count":4,"errors_count":0}
{"severity":"INFO","time":"2021-08-24T14:26:10.698Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_indexing_end","redis_set":"elastic:bulk:initial:0:zset","records_count":1,"first_score":1.0,"last_score":1.0,"failures_count":0,"bulk_execution_duration_s":0.314887}
{"severity":"INFO","time":"2021-08-24T14:26:10.701Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_indexing_end","redis_set":"elastic:bulk:initial:1:zset","records_count":1,"first_score":1.0,"last_score":1.0,"failures_count":0,"bulk_execution_duration_s":0.318188}
{"severity":"INFO","time":"2021-08-24T14:26:10.702Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_indexing_end","redis_set":"elastic:bulk:initial:7:zset","records_count":1,"first_score":1.0,"last_score":1.0,"failures_count":0,"bulk_execution_duration_s":0.318859}
{"severity":"INFO","time":"2021-08-24T14:26:10.702Z","correlation_id":"308c8cbfa9e247d442045db48375796f","message":"bulk_indexing_end","redis_set":"elastic:bulk:initial:10:zset","records_count":1,"first_score":1.0,"last_score":1.0,"failures_count":0,"bulk_execution_duration_s":0.319551}
- verify that the
namespace_ancestry
field is changed in Elasticsearch (ex."namespace_ancestry": "26-109-110"
)
expand for curl
curl --request GET \
--url http://localhost:9200/gitlab-development-issues/_search \
--header 'Content-Type: application/json' \
--data '{
"query": {
"bool": {
"must": [
{
"match": {
"id": 513
}
}
]
}
},
"size": 500
}'
- move the subgroup group (that you created and contains the project above) to a completely new namespace
- monitor the elasticsearch indexing in
log/elasticsearch.log
expand for logs
{"severity":"DEBUG","time":"2021-08-24T14:28:07.342Z","correlation_id":"01FDW8Z5M5N3ATG8CZ8WG4HZPX","class":"Elastic::ProcessInitialBookkeepingService","redis_set":"elastic:bulk:initial:0:zset","message":"track_items","count":1,"tracked_items_encoded":"[[2,\"Project 41 project_41\"]]"}
{"severity":"DEBUG","time":"2021-08-24T14:28:07.357Z","correlation_id":"01FDW8Z5M5N3ATG8CZ8WG4HZPX","class":"Elastic::ProcessInitialBookkeepingService","redis_set":"elastic:bulk:initial:7:zset","message":"track_items","count":1,"tracked_items_encoded":"[[2,\"Issue 510 issue_510 project_41\"]]"}
{"severity":"DEBUG","time":"2021-08-24T14:28:07.360Z","correlation_id":"01FDW8Z5M5N3ATG8CZ8WG4HZPX","class":"Elastic::ProcessInitialBookkeepingService","redis_set":"elastic:bulk:initial:1:zset","message":"track_items","count":1,"tracked_items_encoded":"[[2,\"Issue 511 issue_511 project_41\"]]"}
{"severity":"DEBUG","time":"2021-08-24T14:28:07.362Z","correlation_id":"01FDW8Z5M5N3ATG8CZ8WG4HZPX","class":"Elastic::ProcessInitialBookkeepingService","redis_set":"elastic:bulk:initial:10:zset","message":"track_items","count":1,"tracked_items_encoded":"[[2,\"Issue 513 issue_513 project_41\"]]"}
{"severity":"INFO","time":"2021-08-24T14:28:09.447Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_indexing_start","redis_set":"elastic:bulk:initial:0:zset","records_count":1,"first_score":2.0,"last_score":2.0}
{"severity":"INFO","time":"2021-08-24T14:28:09.449Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_indexing_start","redis_set":"elastic:bulk:initial:1:zset","records_count":1,"first_score":2.0,"last_score":2.0}
{"severity":"INFO","time":"2021-08-24T14:28:09.452Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_indexing_start","redis_set":"elastic:bulk:initial:7:zset","records_count":1,"first_score":2.0,"last_score":2.0}
{"severity":"INFO","time":"2021-08-24T14:28:09.454Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_indexing_start","redis_set":"elastic:bulk:initial:10:zset","records_count":1,"first_score":2.0,"last_score":2.0}
{"severity":"INFO","time":"2021-08-24T14:28:09.815Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_submitted","body_size_bytes":2001,"bulk_count":4,"errors_count":0}
{"severity":"INFO","time":"2021-08-24T14:28:09.832Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_indexing_end","redis_set":"elastic:bulk:initial:0:zset","records_count":1,"first_score":2.0,"last_score":2.0,"failures_count":0,"bulk_execution_duration_s":0.385293}
{"severity":"INFO","time":"2021-08-24T14:28:09.850Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_indexing_end","redis_set":"elastic:bulk:initial:1:zset","records_count":1,"first_score":2.0,"last_score":2.0,"failures_count":0,"bulk_execution_duration_s":0.403561}
{"severity":"INFO","time":"2021-08-24T14:28:09.851Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_indexing_end","redis_set":"elastic:bulk:initial:7:zset","records_count":1,"first_score":2.0,"last_score":2.0,"failures_count":0,"bulk_execution_duration_s":0.404316}
{"severity":"INFO","time":"2021-08-24T14:28:09.851Z","correlation_id":"aff6973f3b7c7637211b686d04d7f013","message":"bulk_indexing_end","redis_set":"elastic:bulk:initial:10:zset","records_count":1,"first_score":2.0,"last_score":2.0,"failures_count":0,"bulk_execution_duration_s":0.404895}
{"severity":"DEBUG","time":"2021-08-24T14:28:10.639Z","correlation_id":"01FDW8Z5M5N3ATG8CZ8WG4HZPX","message":"indexing_commit_range","project_id":41,"from_sha":"f7fc3155bfcdb72c3318c41d00b50a93ec64e6d1","to_sha":"f7fc3155bfcdb72c3318c41d00b50a93ec64e6d1","index_wiki":false}
- verify that the
namespace_ancestry
field is changed in Elasticsearch (ex."namespace_ancestry": "22-107-110"
)
expand for curl
curl --request GET \
--url http://localhost:9200/gitlab-development-issues/_search \
--header 'Content-Type: application/json' \
--data '{
"query": {
"bool": {
"must": [
{
"match": {
"id": 513
}
}
]
}
},
"size": 500
}'
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by Terri Chu