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

fix: add agent wizard #2407

Merged
merged 4 commits into from
Nov 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
2 changes: 2 additions & 0 deletions src/api/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type SilenceNotificationResponse = {
description?: string;
recursive?: boolean;
namespace?: string;
error?: string;
source?: "source1" | "source2" | "source3";
};

Expand Down Expand Up @@ -87,6 +88,7 @@ export type NotificationSilenceItem = {
namespace: string;
description?: string;
filter?: string;
error?: string;
from: string;
until: string;
recursive?: boolean;
Expand Down
19 changes: 3 additions & 16 deletions src/components/Agents/Add/AddAgentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {
import { GenerateAgent, GeneratedAgent } from "../../../api/services/agents";
import { Button } from "../../../ui/Buttons/Button";
import { Modal } from "../../../ui/Modal";
import FormikAutocompleteDropdown from "../../Forms/Formik/FormikAutocompleteDropdown";
import FormikKeyValueMapField from "../../Forms/Formik/FormikKeyValueMapField";
import FormikTextInput from "../../Forms/Formik/FormikTextInput";
import { toastError, toastSuccess } from "../../Toast/toast";
import { Agent } from "../AgentPage";
import DeleteAgentButton from "../DeleteAgentButton";
import FormikScheduleField from "@flanksource-ui/components/Forms/Formik/FormikScheduleField";

export type AgentFormValues = GenerateAgent & {
kubernetes?: Record<string, any>;
Expand Down Expand Up @@ -158,21 +158,8 @@ export default function AgentForm({
hint="Scrapes built-in and custom resource definitions and creates catalog items and a topology from Cluster --> Namespace --> Pod"
/>
{Boolean(values.kubernetes?.enabled) === true && (
<FormikAutocompleteDropdown
options={[
{ label: "1m", value: "1m" },
{ label: "5m", value: "5m" },
{ label: "10m", value: "10m" },
{
label: "30m",
value: "30m"
},
{ label: "1h", value: "1h" },
{ label: "2h", value: "2h" },
{ label: "6h", value: "6h" },
{ label: "12h", value: "12h" },
{ label: "24h", value: "24h" }
]}
<FormikScheduleField
type="scraper"
name="kubernetes.schedule"
label="Scrape Interval"
hintPosition="top"
Expand Down
61 changes: 19 additions & 42 deletions src/components/Agents/InstalAgentInstruction/InstallAgentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,23 @@ export default function InstallAgentModal({
updateHelmRepo: true,
releaseName: "mc-agent",
chartUrl: "https://flanksource.github.io/charts",
// You can add more values here to be passed to the template for the
// values section of the HelmRelease
values: [
{
key: "upstream.createSecret",
value: "true"
},
{
key: "upstream.host",
value: baseUrl
},
{
key: "upstream.username",
value: "token"
},
{
key: "upstream.password",
value: generatedAgent?.access_token
},
{
key: "upstream.agentName",
value: agentFormValues?.name
values: {
upstream: {
createSecret: "true",
host: baseUrl,
username: "token",
password: generatedAgent?.access_token,
agentName: agentFormValues?.name
},
...(pushTelemetry?.enabled
? [
{
key: "pushTelemetry.enabled",
value: "true"
},
{
key: "pushTelemetry.topologyName",
value: `${pushTelemetry.topologyName}`
? {
pushTelemetry: {
enabled: "true",
topologyName: pushTelemetry.topologyName
}
]
: [])
]
}
: {})
}
},
...(kubeOptions?.enabled
? [
Expand All @@ -143,16 +124,12 @@ export default function InstallAgentModal({
namespace: "mission-control-agent",
repoName: "flanksource",
releaseName: "mc-agent-kubernetes",
values: [
{
key: "clusterName",
value: agentFormValues?.name
},
{
key: "scraper.schedule",
value: kubeOptions.schedule
values: {
clusterName: agentFormValues?.name,
scraper: {
schedule: kubeOptions.schedule
}
]
}
}
]
: [])
Expand Down
3 changes: 1 addition & 2 deletions src/components/Forms/Configs/KubernetesConfigsFormEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export default function KubernetesConfigsFormEditor({
/>

<FormikScheduleField
type="medium"
value="@every 30m"
type="scraper"
name={`${name}.schedule`}
hint="Schedule at which to perform a full import, if Watch is enabled can be set to a longer window"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Forms/Formik/FormikAutocompleteDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useField } from "formik";
import { useCallback, useEffect, useState } from "react";
import CreatableSelect from "react-select/creatable";

type FormikSelectDropdownProps = {
export type FormikSelectDropdownProps = {
name: string;
required?: boolean;
label?: string;
Expand Down
48 changes: 36 additions & 12 deletions src/components/Forms/Formik/FormikScheduleField.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import FormikAutocompleteDropdown from "./FormikAutocompleteDropdown";
import FormikAutocompleteDropdown, {
FormikSelectDropdownProps
} from "./FormikAutocompleteDropdown";

const types = {
short: [
Expand Down Expand Up @@ -31,6 +33,34 @@ const types = {
value: "@every 4h"
}
],

scraper: [
{
label: "@every 15m",
value: "@every 15m"
},
{
label: "@every 30m",
value: "@every 30m"
},
{
label: "@hourly",
value: "@hourly"
},
{
label: "@every 2h",
value: "@every 2h"
},
{
label: "@every 4h",
value: "@every 4h"
},

{
label: "@daily",
value: "@daily"
}
],
medium: [
{
label: "@every 5m",
Expand Down Expand Up @@ -119,25 +149,19 @@ const types = {
};

type Props = {
name: string;
type?: keyof typeof types;
hint?: string;
value?: string;
};
} & Omit<FormikSelectDropdownProps, "options">;

export default function FormikScheduleField({
name,
hint,
label = "Schedule",
type = "default",
value
...props
}: Props) {
return (
<FormikAutocompleteDropdown
name={name}
label="Schedule"
hint={hint}
required
label={label}
options={types[type]}
{...props}
/>
);
}
13 changes: 12 additions & 1 deletion src/components/Notifications/Rules/NotificationsRulesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import FormikTextInput from "../../Forms/Formik/FormikTextInput";
import NotificationsRecipientsTabs from "../../Forms/Notifications/NotificationsRecipientsTabs";
import DeleteResource from "../../SchemaResourcePage/Delete/DeleteResource";
import CanEditResource from "../../Settings/CanEditResource";
import ErrorMessage from "@flanksource-ui/ui/FormControls/ErrorMessage";
import { omit } from "lodash";

type NotificationsFormProps = {
onSubmit: (notification: Partial<NotificationRules>) => void;
Expand All @@ -34,7 +36,11 @@ export default function NotificationsRulesForm({
updated_at: undefined,
...(!notification?.id && { source: "UI" })
}}
onSubmit={(values) => onSubmit(values as Partial<NotificationRules>)}
onSubmit={(values) =>
onSubmit(
omit(values, "most_common_error") as Partial<NotificationRules>
)
}
validateOnBlur
validateOnChange
>
Expand All @@ -53,6 +59,11 @@ export default function NotificationsRulesForm({
required
/>
<FormikTextInput name="filter" label="Filter" />
<ErrorMessage
message={notification?.most_common_error}
className="h-full pl-2 align-top"
/>

<NotificationsRecipientsTabs />
<FormikAutocompleteDropdown
isClearable
Expand Down
26 changes: 1 addition & 25 deletions src/components/Notifications/Rules/NotificationsRulesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { NotificationRules } from "@flanksource-ui/api/types/notifications";
import { Modal } from "@flanksource-ui/ui/Modal";
import MRTDataTable from "@flanksource-ui/ui/MRTDataTable/MRTDataTable";
import { useAtom } from "jotai";
import { useCallback } from "react";
import { useSearchParams } from "react-router-dom";
import EditNotificationRules from "./EditNotificationRules";
import {
notificationMostCommonErrorAtom,
notificationsRulesTableColumns
} from "./notificationsRulesTableColumns";
import { notificationsRulesTableColumns } from "./notificationsRulesTableColumns";

type NotificationsTableProps = {
notifications: NotificationRules[];
Expand All @@ -29,14 +24,6 @@ export default function NotificationsRulesTable({

const selectedNotificationId = searchParams.get("id");

const [mostCommonErrorNotification, setMostCommonErrorNotification] = useAtom(
notificationMostCommonErrorAtom
);
const modalTitle =
mostCommonErrorNotification?.title ??
mostCommonErrorNotification?.person?.name ??
mostCommonErrorNotification?.team?.name;

const onSelectNotification = useCallback(
(notification: NotificationRules) => {
const id = notification.id;
Expand All @@ -48,17 +35,6 @@ export default function NotificationsRulesTable({

return (
<>
{mostCommonErrorNotification && (
<Modal
open={mostCommonErrorNotification !== undefined}
onClose={() => setMostCommonErrorNotification(undefined)}
title={`${modalTitle ?? "Most Common Error"}`}
>
<div className="flex flex-col p-4">
{mostCommonErrorNotification.most_common_error}
</div>
</Modal>
)}
<MRTDataTable
data={notifications ?? []}
columns={notificationsRulesTableColumns}
Expand Down
Loading
Loading