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

Pull request update/240215 #213

Merged
merged 7 commits into from
Feb 15, 2024
Merged
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
3 changes: 2 additions & 1 deletion arcee/arcee_receiver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,8 @@ async def get_run_console(request, run_id: str):
'mongo_url': "mongodb://{host}:{port}/admin".format(
host=host, port=port),
'mongo_database': db_name,
'mongo_migrations_path': 'arcee/arcee_receiver/migrations'
'mongo_migrations_path': os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'migrations')
}
manager = MigrationManager(config=Configuration(config=config_params))
manager.run()
Expand Down
23 changes: 16 additions & 7 deletions docker_images/cleanmongodb/clean-mongo-db.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,20 @@ def _delete_by_application(self, token):
return all_applications_deleted

def get_deleted_cloud_account(self):
result = None
session = self.get_session()
stmt = """SELECT cloudaccount.id FROM cloudaccount
stmt = """SELECT cloudaccount.id, organization.is_demo
FROM cloudaccount
JOIN organization
ON organization.id = cloudaccount.organization_id
WHERE (organization.deleted_at != 0
OR cloudaccount.deleted_at != 0)
AND cloudaccount.cleaned_at = 0
LIMIT 1"""
try:
result = session.execute(stmt).scalar()
result = next(session.execute(stmt))
except StopIteration:
pass
finally:
session.close()
return result
Expand Down Expand Up @@ -356,14 +360,14 @@ def delete_by_organization(self):
info = self.get_deleted_organization_info()
LOG.info('Organizations ML objects processing is completed')

def _delete_by_cloud_account(self, cloud_account_id):
def _delete_by_cloud_account(self, cloud_account_id, is_demo):
restapi_collections = [self.mongo_client.restapi.raw_expenses,
self.mongo_client.restapi.resources]
LOG.info(f'Started processing for cloud account {cloud_account_id}')
for collection in restapi_collections:
archive = False
if (collection == self.mongo_client.restapi.raw_expenses
and self.archive_enable):
and self.archive_enable and not is_demo):
archive = True
self.limits[collection] = self.delete_in_chunks(
collection, 'cloud_account_id', cloud_account_id,
Expand All @@ -378,11 +382,16 @@ def cloud_account_limits(self):
return [self.limits[x] for x in collections]

def delete_by_cloud_account(self):
cloud_account_id = self.get_deleted_cloud_account()
cloud_account_id, is_demo = self.get_deleted_cloud_account()
while cloud_account_id and all(
limit > 0 for limit in self.cloud_account_limits()):
self._delete_by_cloud_account(cloud_account_id)
cloud_account_id = self.get_deleted_cloud_account()
self._delete_by_cloud_account(cloud_account_id, is_demo)
cleaned_cloud_account_id = cloud_account_id
cloud_account_id, is_demo = self.get_deleted_cloud_account()
if cleaned_cloud_account_id == cloud_account_id:
# last cloud account that can't be cleaned up in current
# iteration, should be cleaned in the next run
break
LOG.info('Cloud accounts processing is completed')

def clean_mongo(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GET_TOKEN } from "api/auth/actionTypes";
import ButtonLoader from "components/ButtonLoader";
import Invitations from "components/Invitations";
import Logo from "components/Logo";
import { getLoginRedirectionPath } from "containers/AuthorizationContainer/AuthorizationContainer";
import { useApiData } from "hooks/useApiData";
import { SPACING_6 } from "utils/layouts";
import useStyles from "./AcceptInvitations.styles";
Expand Down Expand Up @@ -45,11 +46,15 @@ const AcceptInvitations = ({ invitations = [], activateScope, isLoadingProps = {
</Box>
<Box>
<ButtonLoader
messageId="goToDashboard"
messageId="proceedToOptScale"
size="medium"
color="primary"
variant="contained"
onClick={() => activateScope(userEmail)}
onClick={() =>
activateScope(userEmail, {
getOnSuccessRedirectionPath: ({ userEmail: scopeUserEmail }) => getLoginRedirectionPath(scopeUserEmail)
})
}
isLoading={isGetOrganizationsLoading || isCreateOrganizationLoading || isUpdateInvitationLoading}
startIcon={<NavigationIcon />}
customWrapperClass={classes.dashboardButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const OrganizationSelector = ({
isLoading={isLoading}
sx={isDownSm ? HIDDEN_SELECTOR_SX : SELECTOR_SX}
>
{organizations
{[...organizations]
.sort(({ name: nameA }, { name: nameB }) => nameA.localeCompare(nameB))
.map((obj) => (
<Item key={obj.name} value={obj.id}>
Expand Down Expand Up @@ -117,7 +117,7 @@ const OrganizationSelector = ({
disabled={isDemo}
tooltipTitle={isDemo ? <FormattedMessage id="notAvailableInLiveDemo" /> : null}
>
<FormattedMessage id="organizationsOverview" />
<FormattedMessage id="createNewOrganization" />
</Button>
</Selector>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const MetricChart = ({ lines, formatYAxis, emptyMessageId, legend, yFormat, isLo
margin: {
left: marginLeft,
top: 5,
bottom: 20,
bottom: 25,
right: 32
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ import { useOrganizationInfo } from "hooks/useOrganizationInfo";
import { HOME_FIRST_TIME, HOME, REGISTER, LOGIN } from "urls";
import { getQueryParams } from "utils/network";

export const getLoginRedirectionPath = (scopeUserEmail: string) => {
const { next = HOME, userEmail: userEmailQueryParameter } = getQueryParams();

if (userEmailQueryParameter) {
return userEmailQueryParameter === scopeUserEmail ? next : HOME;
}

return next;
};

const AuthorizationContainer = () => {
const { pathname } = useLocation();

const { invited: queryInvited, next = HOME, userEmail: userEmailQueryParameter } = getQueryParams();
const { invited: queryInvited, next = HOME } = getQueryParams();

const { authorize, register, isRegistrationInProgress, isAuthInProgress, thirdPartySignIn, setIsAuthInProgress } =
useNewAuthorization();
Expand All @@ -38,19 +48,11 @@ const AuthorizationContainer = () => {
);
};

const getLoginSuccessRedirectionPath = ({ userEmail }) => {
if (userEmailQueryParameter) {
return userEmailQueryParameter === userEmail ? next : HOME;
}

return next;
};

const onSubmitLogin = ({ email, password }) => {
authorize(
{ email, password },
{
getOnSuccessRedirectionPath: getLoginSuccessRedirectionPath
getOnSuccessRedirectionPath: ({ userEmail }) => getLoginRedirectionPath(userEmail)
}
);
};
Expand All @@ -59,7 +61,7 @@ const AuthorizationContainer = () => {
thirdPartySignIn(
{ provider, params },
{
getOnSuccessRedirectionPath: getLoginSuccessRedirectionPath
getOnSuccessRedirectionPath: ({ userEmail }) => getLoginRedirectionPath(userEmail)
}
);

Expand Down
6 changes: 3 additions & 3 deletions ngui/ui/src/hooks/useNewAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ACCEPT_INVITATIONS, HOME } from "urls";
import { trackEvent, GA_EVENT_CATEGORIES } from "utils/analytics";
import { checkError } from "utils/api";
import { isEmpty } from "utils/arrays";
import { getQueryParams } from "utils/network";
import { formQueryString, getQueryParams } from "utils/network";
import { useApiState } from "./useApiState";

export const PROVIDERS = Object.freeze({
Expand Down Expand Up @@ -115,7 +115,7 @@ export const useNewAuthorization = () => {
const { userEmail } = getState()?.[AUTH]?.[GET_TOKEN] ?? {};
Promise.resolve(activateScope(userEmail, { getOnSuccessRedirectionPath }));
} else {
navigate(ACCEPT_INVITATIONS);
navigate(`${ACCEPT_INVITATIONS}?${formQueryString(getQueryParams())}`);
}
})
.catch(() => {
Expand All @@ -140,7 +140,7 @@ export const useNewAuthorization = () => {
const { userEmail } = getState()?.[AUTH]?.[GET_TOKEN] ?? {};
Promise.resolve(activateScope(userEmail, { getOnSuccessRedirectionPath }));
} else {
navigate(ACCEPT_INVITATIONS);
navigate(`${ACCEPT_INVITATIONS}?${formQueryString(getQueryParams())}`);
}
})
.catch(() => {
Expand Down
2 changes: 1 addition & 1 deletion ngui/ui/src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const removeQueryParam = (key) => {
* // queryString = "age=27&name=Sally&surname=Wong"
*
*/
export const formQueryString = (params) => queryString.stringify(params);
export const formQueryString = (params: Record<string, unknown>) => queryString.stringify(params);

export const getMenuRootUrl = (menu) => {
const currentPath = getPathname();
Expand Down
22 changes: 22 additions & 0 deletions slacker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## How to prepare your OptScale cluster for Slack integration

1. Go to https://api.slack.com/apps to create a new Slack app. Enter a name and pick a workspace.

2. In the "OAuth & Permissions" tab paste a local cluster oauth_redirect slacker URL https://<public_cluster_ip>/slacker/v2/oauth_redirect to the "Redirect URLs" field. In the "Scopes" section add "Bot Token Scopes" permissions (`chat:write`, `im:history`, `chat:write.public`, `groups:write`, `channels:read`, `groups:read`).

3. In the "Interactivity & Shortcuts" tab enable the "Interactivity" switch and paste a cluster slacker event URL https://<public_cluster_ip>/slacker/v2/events to the "Request URL" field.

4. Update the optscale/optscale-deploy/overlay/user_template.yml overlay with "Client ID", "Client Secret", "Signing Secret" values from the "Basic Information" tab in "App Credentials" section.
```
slacker:
slack_signing_secret:
slack_client_id:
slack_client_secret:
```

5. Update your cluster with the new overlay:
`./runkube.py --with-elk --update-only <deployment name> <version>`

6. In the "Event Subscriptions" tab enable the "Enable Events" switch and paste a slacker events URL https://<public_cluster_ip>/slacker/v2/events to the "Request URL" field. Expand the "Subscribe to bot events" panel and add the following event types: `app_home_opened`, `message.im`, `member_joined_channel`.

7. In the "App Home" tab disable the "Home Tab" switch, enable the "Messages Tab" switch. In the "Messages Tab" tab check "Allow users to send Slash commands and messages from the messages tab".
Loading