Skip to content

Commit

Permalink
Feature: Enable lucene index rebuild through UI
Browse files Browse the repository at this point in the history
  • Loading branch information
syalioune committed Dec 5, 2022
1 parent 122a8bc commit 5884326
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 29 deletions.
11 changes: 9 additions & 2 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
"component_firmware": "Firmware",
"component_file": "File",
"dates": "Dates",
"reindex": "Rebuild indexe(s)"
"reindex": "Rebuild index(es)"
},
"admin": {
"configuration": "Configuration",
Expand Down Expand Up @@ -610,7 +610,14 @@
"reindex_vulnerable_software": "Vulnerable software",
"reindex_submitted": "Reindex request submitted",
"reindex_error": "Error encountered while submitting reindex request",
"reindex_description": "Rebuild the lucenes indexes used by Dependency Track to perform full text search or fuzzy match. TODO (Be more explicit)"
"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);
121 changes: 95 additions & 26 deletions src/views/administration/configuration/Search.vue
Original file line number Diff line number Diff line change
@@ -1,41 +1,82 @@
<template>
<b-card no-body :header="header">
<b-card-body>
<p>{{ $t('admin.reindex_description') }}</p>
<br/>
<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>
<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,
Expand All @@ -45,13 +86,41 @@
cpe: false,
servicecomponent:false
},
labelIcon: {
dataOn: '\u2713',
dataOff: '\u2715'
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 === "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: 'indexes', propertyName: 'consistency.check.enabled', propertyValue: this.consistencyCheck.enabled},
{groupName: 'indexes', propertyName: 'consistency.check.cadence', propertyValue: this.consistencyCheck.cadence},
{groupName: '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();
Expand Down

0 comments on commit 5884326

Please sign in to comment.