Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI redundant requests fixes (#3347) Settings #3353

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- develop
- 'release/**'
- 'stage/**'
- 'ci/**'

workflow_dispatch:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
public class StorageRequestStat {
private Long userId;
private List<Entry> statistics;
private Long readRequests;
private Long writeRequests;
private Long totalRequests;

@Data
@Builder
public static class Entry {
private Integer storageId;
private Integer id;
private String storageName;
private Integer readRequests;
private Integer writeRequests;
private Integer totalRequests;
private Long readRequests;
private Long writeRequests;
private Long totalRequests;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.epam.pipeline.utils.ElasticsearchUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
Expand All @@ -39,6 +40,7 @@
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.ParsedSingleValueNumericMetricsAggregation;
Expand Down Expand Up @@ -67,6 +69,7 @@ public class StorageRequestManager {
SearchRequest.DEFAULT_INDICES_OPTIONS.expandWildcardsOpen(),
SearchRequest.DEFAULT_INDICES_OPTIONS.expandWildcardsClosed(),
SearchRequest.DEFAULT_INDICES_OPTIONS);
private static final int DEFAULT_ENTRIES_NUM = 10;

private final GlobalSearchElasticHelper elasticHelper;
private final PreferenceManager preferenceManager;
Expand All @@ -75,7 +78,7 @@ public StorageRequestStat getStatistics(final StorageStatsRequest request) {
final SearchSourceBuilder source = new SearchSourceBuilder()
.query(constructQueryFilter(request))
.sort(sorting.getField(), sorting.getOrder())
.size(Optional.ofNullable(request.getMaxEntries()).orElse(10));
.size(Optional.ofNullable(request.getMaxEntries()).orElse(DEFAULT_ENTRIES_NUM));

final SearchRequest esRequest = new SearchRequest()
.source(source)
Expand All @@ -87,11 +90,13 @@ public StorageRequestStat getStatistics(final StorageStatsRequest request) {

public StorageRequestStat getGroupedStats(final StorageStatsRequest request) {
final SearchSourceBuilder source = new SearchSourceBuilder()
.query(constructQueryFilter(request))
.size(Optional.ofNullable(request.getMaxEntries()).orElse(10));
.query(constructQueryFilter(request));

final TermsAggregationBuilder userAggregation = AggregationBuilders.terms(request.getGroupBy())
.field(request.getGroupBy()).size(Integer.MAX_VALUE);
.order(BucketOrder.aggregation(request.getSorting().getField(),
SortOrder.ASC == request.getSorting().getOrder()))
.field(request.getGroupBy())
.size(Optional.ofNullable(request.getMaxEntries()).orElse(DEFAULT_ENTRIES_NUM));

userAggregation.subAggregation(AggregationBuilders.sum(READ_REQUESTS).field(READ_REQUESTS));
userAggregation.subAggregation(AggregationBuilders.sum(WRITE_REQUESTS).field(WRITE_REQUESTS));
Expand All @@ -114,14 +119,11 @@ private StorageRequestStat mapAggregationToEntry(final Aggregations aggregations
return builder.build();
}
final Terms aggregation = aggregations.get(request.getGroupBy());
final Terms.Bucket bucket = aggregation.getBucketByKey(request.getUserId().toString());
if (Objects.isNull(bucket)) {
log.debug("Failed to load storage requests for user {}", request.getUserId());
return builder.build();
}
return builder.readRequests(parseAggregation(READ_REQUESTS, bucket.getAggregations()))
.writeRequests(parseAggregation(WRITE_REQUESTS, bucket.getAggregations()))
.totalRequests(parseAggregation(TOTAL_REQUESTS, bucket.getAggregations()))
return builder.statistics(
ListUtils.emptyIfNull(aggregation.getBuckets())
.stream()
.map(this::mapBucketToEntry)
.collect(Collectors.toList()))
.build();
}

Expand Down Expand Up @@ -150,11 +152,20 @@ private Long parseAggregation(final String name,
private StorageRequestStat.Entry mapStorageEntry(final SearchHit hit) {
final Map<String, Object> doc = hit.getSourceAsMap();
return StorageRequestStat.Entry.builder()
.storageId((Integer) doc.get("storage_id"))
.id((Integer) doc.get("storage_id"))
.storageName((String) doc.getOrDefault("storage_name", StringUtils.EMPTY))
.readRequests((Integer) doc.get(READ_REQUESTS))
.writeRequests((Integer) doc.get(WRITE_REQUESTS))
.totalRequests((Integer) doc.get(TOTAL_REQUESTS))
.readRequests((Long) doc.get(READ_REQUESTS))
.writeRequests((Long) doc.get(WRITE_REQUESTS))
.totalRequests((Long) doc.get(TOTAL_REQUESTS))
.build();
}

private StorageRequestStat.Entry mapBucketToEntry(final Terms.Bucket bucket) {
return StorageRequestStat.Entry.builder()
.id(bucket.getKeyAsNumber().intValue())
.readRequests(parseAggregation(READ_REQUESTS, bucket.getAggregations()))
.writeRequests(parseAggregation(WRITE_REQUESTS, bucket.getAggregations()))
.totalRequests(parseAggregation(TOTAL_REQUESTS, bucket.getAggregations()))
.build();
}

Expand Down
33 changes: 24 additions & 9 deletions client/src/components/settings/AWSRegionsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,12 +680,6 @@ export default class AWSRegionsForm extends React.Component {
};
};

@inject(() => {
const roles = new Roles();
roles.fetch();

return {roles};
})
@observer
class AWSRegionForm extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -831,12 +825,22 @@ class AWSRegionForm extends React.Component {
@observable groupsToAddPermission = [];
@observable usersToRemovePermissions = [];
@observable groupsToRemovePermissions = [];
@observable rolesRequest;
@observable rolesRequestPending = false;

@computed
get provider () {
return this.props.region ? this.props.region.provider : null;
}

@computed
get roles () {
if (this.rolesRequest && this.rolesRequest.loaded) {
return this.rolesRequest.value;
}
return null;
}

static Section = ({
title,
layout,
Expand Down Expand Up @@ -876,6 +880,16 @@ class AWSRegionForm extends React.Component {
);
};

loadRoles = async () => {
this.rolesRequest = new Roles();
this.rolesRequestPending = true;
await this.rolesRequest.fetch();
if (this.rolesRequest.error) {
message.error(this.rolesRequest.error, 5);
}
this.rolesRequestPending = false;
};

getFieldClassName = (field, defaultClassName) => {
const classNames = defaultClassName ? [defaultClassName] : [];
if (this.provider) {
Expand Down Expand Up @@ -1286,8 +1300,8 @@ class AWSRegionForm extends React.Component {
};

findGroupDataSource = () => {
const roles = (this.props.roles.loaded && this.state.groupSearchString) ? (
(this.props.roles.value || [])
const roles = (this.roles && this.state.groupSearchString) ? (
(this.roles || [])
.filter(r => r.name.toLowerCase().indexOf(this.state.groupSearchString.toLowerCase()) >= 0)
.map(r => r.predefined ? r.name : this.splitRoleName(r.name))
.filter(name => !this.addedGroupPermissions.includes(name))
Expand Down Expand Up @@ -1367,7 +1381,7 @@ class AWSRegionForm extends React.Component {
return <Alert type="warning" message={this.permissions.error} />;
}

const rolesList = (this.props.roles.loaded ? (this.props.roles.value || []) : []).map(r => r);
const rolesList = (this.roles || []).map(r => r);
const getSidName = (name, principal) => {
if (principal) {
return <UserName userName={name} />;
Expand Down Expand Up @@ -2245,6 +2259,7 @@ class AWSRegionForm extends React.Component {
};

componentDidMount () {
this.loadRoles();
this.props.onInitialize && this.props.onInitialize(this);
this.rebuild();
}
Expand Down
76 changes: 55 additions & 21 deletions client/src/components/settings/SystemEvents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {Component} from 'react';
import {computed, observable} from 'mobx';
import {inject, observer} from 'mobx-react';
import {
Alert,
Expand All @@ -18,8 +19,7 @@ import displayDate from '../../utils/displayDate';
import styles from './styles.css';

@inject(({authenticatedUserInfo}) => ({
authenticatedUserInfo,
notifications: new Notifications()
authenticatedUserInfo
}))
@observer
export default class SystemEvents extends Component {
Expand All @@ -30,16 +30,53 @@ export default class SystemEvents extends Component {
}
};

@observable
notificationsRequest;
@observable
notificationsRequestPending;

componentDidMount () {
this.loadNotifications();
}

componentDidUpdate () {
this.loadNotifications();
}

@computed
get notifications () {
if (this.notificationsRequest && this.notificationsRequest.loaded) {
return this.notificationsRequest.value;
}
return null;
}

loadNotifications = async (force = false) => {
if (
!force &&
(this.notificationsRequest || this.notificationsRequestPending)
) {
return;
}
this.notificationsRequestPending = true;
this.notificationsRequest = new Notifications();
await this.notificationsRequest.fetch();
if (this.notificationsRequest.error) {
this.notificationsRequest = null;
message.error(this.notificationsRequest.error, 5);
}
this.notificationsRequestPending = false;
};

updateNotification = async (notification) => {
const {notifications} = this.props;
const hide = message.loading('Updating notification...', 0);
const request = new UpdateNotification();
await request.send(notification);
if (request.error) {
hide();
message.error(request.error, 5);
} else {
await notifications.fetch();
await this.loadNotifications(true);
hide();
this.closeUpdateNotificationForm();
this.closeCreateNotificationForm();
Expand Down Expand Up @@ -79,7 +116,7 @@ export default class SystemEvents extends Component {
hide();
message.error(request.error, 5);
} else {
await this.props.notifications.fetch();
await this.loadNotifications(true);
hide();
}
};
Expand Down Expand Up @@ -133,23 +170,20 @@ export default class SystemEvents extends Component {
<Alert type="error" message="Access is denied" />
);
}
const {notifications} = this.props;
const data = (
notifications.loaded
? (notifications.value || []).map(n => n)
: []
).sort(
(a, b) => {
if (a.title > b.title) {
return 1;
} else if (a.title < b.title) {
return -1;
const data = (this.notifications || [])
.map(n => n)
.sort(
(a, b) => {
if (a.title > b.title) {
return 1;
} else if (a.title < b.title) {
return -1;
}
return 0;
}
return 0;
}
);
);
const refreshTable = () => {
notifications.fetch();
this.loadNotifications(true);
};
const onChangeState = (notification) => {
if (notification.state === 'ACTIVE') {
Expand Down Expand Up @@ -263,7 +297,7 @@ export default class SystemEvents extends Component {
}}
showHeader={false}
rowKey="notificationId"
loading={this.props.notifications.pending}
loading={this.notificationsRequestPending}
columns={columns}
dataSource={data}
expandedRowClassName={
Expand Down
Loading
Loading