Skip to content

Commit

Permalink
Enable lucene index rebuild through UI (DependencyTrack#338)
Browse files Browse the repository at this point in the history
* Feature: Enable lucene index rebuild through UI

See DependencyTrack/dependency-track#2104

Signed-off-by: Alioune SY <[email protected]>

* Feature: Enable lucene index rebuild through UI

See DependencyTrack/dependency-track#2104

Signed-off-by: Alioune SY <[email protected]>

* Fix: Restoring lucene index build during startup by having a dedicated listener

Takint into account review comments

Signed-off-by: Alioune SY <[email protected]>

Signed-off-by: Alioune SY <[email protected]>
  • Loading branch information
syalioune authored Dec 6, 2022
1 parent a87fd53 commit 46c49ce
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@
"component_device": "Device",
"component_firmware": "Firmware",
"component_file": "File",
"dates": "Dates"
"dates": "Dates",
"reindex": "Rebuild index(es)"
},
"admin": {
"configuration": "Configuration",
Expand Down Expand Up @@ -615,7 +616,24 @@
"jira_username": "Jira user (service account). The user must be provisioned to the appropriate jira instance and permitted to create issues.",
"jira_password": "Jira password",
"jira_ticket_type": "Jira ticket type",
"jira_project_key": "Jira project key"
"jira_project_key": "Jira project key",
"reindex_projects": "Projects",
"reindex_components": "Components",
"reindex_service_components": "Service components",
"reindex_vulnerabilities": "Vulnerabilities",
"reindex_licenses": "Licenses",
"reindex_cpes": "CPE",
"reindex_vulnerable_software": "Vulnerable software",
"reindex_submitted": "Reindex request submitted",
"reindex_error": "Error encountered while submitting reindex request",
"index_general_description": "Dependency Track uses Apache Lucene to enable full-text search on various entities like projects or vulnerabilities.",
"index_use_cases": "The full-text search feature is principally used for the search API (i.e. all the indexes) and internal analyzer fuzzy matching on CPE (i.e. the vulnerable software index).",
"index_issues_description": "The lucene indexes can degrade or drift from Dependency Track database over time. Even though DT does its best to minimize the drift, the administrative features below are provided to check or restore the indexes if need be. It must be used with caution.",
"index_consistency_check_description": "You can enable a periodic background task that will check that all indexes exists, are not corrupted and that their difference with Dependency Track database is under a defined threshold percentage. Any check failure will trigger a rebuild of the corresponding index. A restart is required to take cadence modification into account.",
"index_rebuild_description" : "You can selectively trigger an immediate rebuild of some or all indexes. The index rebuild will be perform by an asynchronous tasks. You can check the progress using Dependency Track logs.",
"enable_index_consistency_check": "Enable periodic consistency check",
"index_consistency_check_cadence": "Cadence (in minutes)",
"index_consistency_check_threshold": "Delta threshold (in percentage)"
},
"condition": {
"warning": "Warning",
Expand Down
3 changes: 2 additions & 1 deletion src/validation/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extend, configure } from 'vee-validate'
import { required, confirmed, min_value } from 'vee-validate/dist/rules'
import { required, confirmed, min_value, max_value } from 'vee-validate/dist/rules'

import i18n from '../i18n'

Expand All @@ -11,3 +11,4 @@ configure({
extend('required', required);
extend('confirmed', confirmed);
extend('min_value', min_value);
extend('max_value', max_value);
5 changes: 5 additions & 0 deletions src/views/administration/AdminMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
component: 'TaskScheduler',
name: this.$t('admin.task_scheduler'),
href: "#taskSchedulerTab"
},
{
component: 'Search',
name: this.$t('message.search'),
href: "#searchTab"
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion src/views/administration/Administration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import Jira from "./configuration/JiraConfig";
import InternalComponents from "./configuration/InternalComponents";
import TaskScheduler from "./configuration/TaskScheduler.vue";
import Search from "./configuration/Search.vue";
// Analyzer plugins
import InternalAnalyzer from "./analyzers/InternalAnalyzer";
import OssIndexAnalyzer from "./analyzers/OssIndexAnalyzer";
Expand Down Expand Up @@ -64,7 +65,7 @@
components: {
EventBus,
AdminMenu,
General, BomFormats, Email, Jira, InternalComponents, TaskScheduler,
General, BomFormats, Email, Jira, InternalComponents, TaskScheduler, Search,
InternalAnalyzer, OssIndexAnalyzer, VulnDbAnalyzer, SnykAnalyzer,
VulnSourceNvd, VulnSourceGitHubAdvisories, VulnSourceOSVAdvisories,
Cargo, Composer, Gem, GoModules, Hex, Maven, Npm, Nuget, Python,
Expand Down
140 changes: 140 additions & 0 deletions src/views/administration/configuration/Search.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<template>
<div>
<p>{{ $t('admin.index_general_description') }}</p>
<p>{{ $t('admin.index_use_cases') }}</p>
<p>{{ $t('admin.index_issues_description') }}</p>
<br/>
<b-card no-body :header="headers.consistencyCheck">
<b-card-body>
<p>{{ $t('admin.index_consistency_check_description') }}</p>
<c-switch id="consistency-check-enabled" color="primary" v-model="consistencyCheck.enabled" label v-bind="labelIcon" />{{$t('admin.enable_index_consistency_check')}}
<b-validated-input-group-form-input
id="consistency-check-cadence"
:label="$t('admin.index_consistency_check_cadence')"
input-group-size="mb-3"
rules="required|min_value:1"
type="number"
v-model="consistencyCheck.cadence"
:tooltip="consistencyCheck.cadenceTooltip"
/>
<b-validated-input-group-form-input
id="consistency-check-threshold"
:label="$t('admin.index_consistency_check_threshold')"
input-group-size="mb-3"
rules="required|min_value:1|max_value:100"
type="number"
v-model="consistencyCheck.threshold"
:tooltip="consistencyCheck.thresholdTooltip"
/>
</b-card-body>
<b-card-footer>
<b-button size="md" class="px-4" variant="outline-primary" @click="saveConsistencyCheckSettings">{{ $t('message.update') }}</b-button>
</b-card-footer>
</b-card>
<b-card no-body :header="headers.manualRebuild">
<b-card-body>
<p>{{ $t('admin.index_rebuild_description') }}</p>
<c-switch id="project" color="primary" v-model="type.project" label v-bind="labelIcon" />{{$t('admin.reindex_projects')}}
<br/>
<c-switch id="component" color="primary" v-model="type.component" label v-bind="labelIcon" />{{$t('admin.reindex_components')}}
<br/>
<c-switch id="vulnerability" color="primary" v-model="type.vulnerability" label v-bind="labelIcon" />{{$t('admin.reindex_vulnerabilities')}}
<br/>
<c-switch id="vulnerablesoftware" color="primary" v-model="type.vulnerablesoftware" label v-bind="labelIcon" />{{$t('admin.reindex_vulnerable_software')}}
<br/>
<c-switch id="servicecomponent" color="primary" v-model="type.servicecomponent" label v-bind="labelIcon" />{{$t('admin.reindex_service_components')}}
<br/>
<c-switch id="license" color="primary" v-model="type.license" label v-bind="labelIcon" />{{$t('admin.reindex_licenses')}}
<br/>
<c-switch id="cpe" color="primary" v-model="type.cpe" label v-bind="labelIcon" />{{$t('admin.reindex_cpes')}}
<br/>
</b-card-body>
<b-card-footer>
<b-button size="md" class="px-4" variant="outline-primary" @click="reindex">{{ $t('message.reindex') }}</b-button>
</b-card-footer>
</b-card>
</div>
</template>

<script>
import { Switch as cSwitch } from '@coreui/vue';
import BValidatedInputGroupFormInput from '../../../forms/BValidatedInputGroupFormInput';
import configPropertyMixin from "../mixins/configPropertyMixin";
import common from "../../../shared/common";
export default {
mixins: [configPropertyMixin],
props: {
header: String
},
components: {
cSwitch,
BValidatedInputGroupFormInput
},
data() {
return {
headers: {
consistencyCheck: this.header + " - Periodic consistency check",
manualRebuild: this.header + " - Manual rebuild"
},
type: {
project: false,
component: false,
vulnerability: false,
vulnerablesofware: false,
license: false,
cpe: false,
servicecomponent:false
},
consistencyCheck: {
enabled: false,
cadence: "4320",
cadenceTooltip: "",
threshold: "20",
thresholdTooltip: ""
}
}
},
created () {
this.axios.get(this.configUrl).then((response) => {
let configItems = response.data.filter(function (item) { return item.groupName === "search-indexes" });
for (let i=0; i<configItems.length; i++) {
let item = configItems[i];
switch (item.propertyName) {
case "consistency.check.enabled":
this.consistencyCheck.enabled = common.toBoolean(item.propertyValue); break;
case "consistency.check.cadence":
this.consistencyCheck.cadence = item.propertyValue;
this.consistencyCheck.cadenceTooltip = item.description; break;
case "consistency.check.delta.threshold":
this.consistencyCheck.threshold = item.propertyValue;
this.consistencyCheck.thresholdTooltip = item.description; break;
}
}
});
},
methods: {
saveConsistencyCheckSettings: function() {
this.updateConfigProperties([
{groupName: 'search-indexes', propertyName: 'consistency.check.enabled', propertyValue: this.consistencyCheck.enabled},
{groupName: 'search-indexes', propertyName: 'consistency.check.cadence', propertyValue: this.consistencyCheck.cadence},
{groupName: 'search-indexes', propertyName: 'consistency.check.delta.threshold', propertyValue: this.consistencyCheck.threshold}
]);
},
reindex: function() {
let url = `${this.$api.BASE_URL}/${this.$api.URL_SEARCH}/reindex`;
let params = new URLSearchParams();
Object.entries(this.type).forEach(([key, value]) => {
if(value) {
params.append('type', key.toUpperCase());
}
});
this.axios.post(url, null, { params: params }).then((response) => {
this.$toastr.s(this.$t('admin.reindex_submitted'));
}).catch((error) => {
this.$toastr.s(this.$t('admin.reindex_error'));
});
}
}
}
</script>

0 comments on commit 46c49ce

Please sign in to comment.