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

Replace restful-react #275

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
45a71df
Try Docker build without python3-dev
disrupted Dec 5, 2022
4487421
Update uvicorn
disrupted Dec 5, 2022
feb92e0
Install build-essentials
disrupted Dec 5, 2022
a0839ec
Fix typo
disrupted Dec 5, 2022
dce648e
Try multi-stage backend build
disrupted Dec 5, 2022
7bbc557
Use `.` instead of `source`
disrupted Dec 5, 2022
d0c279c
Replace linux headers package
disrupted Dec 5, 2022
a592caa
Copy app
disrupted Dec 5, 2022
fd01fb1
Install libc6-dev
disrupted Dec 5, 2022
af378c4
Install package in final step
disrupted Dec 5, 2022
550693e
Install graphviz package in prod
disrupted Dec 5, 2022
889010b
Install graphviz package in prod
disrupted Dec 5, 2022
0bafb93
Don't bother cleaning up temporary builder
disrupted Dec 5, 2022
845bc5f
Copy only necessary files
disrupted Dec 5, 2022
1aa6bc7
Include pyproject.toml
disrupted Dec 5, 2022
8db9f65
Include readme
disrupted Dec 5, 2022
b8a9f8b
Fix path
disrupted Dec 5, 2022
f9ee90c
Try without pip install
disrupted Dec 5, 2022
fe36bfc
Revert
disrupted Dec 5, 2022
867f7b7
Revert
disrupted Dec 5, 2022
7ab1908
Remove restful-react
disrupted Dec 5, 2022
9e7de7f
Install openapi-codegen
disrupted Dec 5, 2022
fa4c589
Create config
disrupted Dec 5, 2022
78cf386
Delete old fetchers
disrupted Dec 5, 2022
18d9e23
Generate new fetchers
disrupted Dec 5, 2022
e5e374a
Update usage of fetchers
disrupted Dec 5, 2022
56cf3a8
Update tests
disrupted Dec 5, 2022
61fb8d7
Merge remote-tracking branch 'origin/main' into refactor/replace-rest…
disrupted Dec 5, 2022
acb1fbb
Supply QueryClient globally through custom _app component
disrupted Dec 5, 2022
8f9fe21
Fix import
disrupted Dec 5, 2022
047c58f
Supply QueryClient in test
disrupted Dec 5, 2022
d127beb
Supply QueryClient in test
disrupted Dec 5, 2022
b2d692e
Update Details
disrupted Dec 5, 2022
91d8ed3
Update Schema
disrupted Dec 5, 2022
bf9a9b1
Disable lazy queries
disrupted Dec 5, 2022
0fb9c29
Merge remote-tracking branch 'origin/main' into refactor/replace-rest…
disrupted Apr 12, 2023
7b6a8b1
Update `npm run generate-fetcher` command
disrupted Apr 12, 2023
2b5f738
Update fetchers
disrupted Apr 12, 2023
6a50d77
Update browserslist
disrupted Apr 12, 2023
41fb4d2
Fix react-query dependency
disrupted Apr 12, 2023
99ec308
Fix import
disrupted Apr 12, 2023
8d7833f
Install react-query-devtools
disrupted Apr 12, 2023
b6ca473
Fix import
disrupted Apr 12, 2023
2391667
Rewrite mock
disrupted Apr 12, 2023
fec9887
Update openapi-codegen
disrupted May 10, 2023
edfc1b6
Confirm bug
disrupted May 11, 2023
fbd34c8
Update openapi-codegen
disrupted May 11, 2023
9a00d92
Fix bug
disrupted May 11, 2023
55dfcd0
Fix Next.js middleware
disrupted Jun 6, 2023
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
11 changes: 10 additions & 1 deletion frontend/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import {
act,
fireEvent,
Expand All @@ -9,10 +10,18 @@ import mockRouter from "next-router-mock";
import singletonRouter from "next/router";
import nock from "nock";
import React from "react";
import App from "../components/App";
import AppComponent from "../components/App";

jest.mock("next/router", () => require("next-router-mock"));

const queryClient = new QueryClient();

const App = () => (
<QueryClientProvider client={queryClient}>
<AppComponent />
</QueryClientProvider>
);

// -- Mock GraphVisualization
jest.mock("../components/graph/Visualization", () => {
return function StubGraphVisualization() {
Expand Down
46 changes: 23 additions & 23 deletions frontend/__tests__/Details.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import nock from "nock";
import React from "react";
import { RestfulProvider } from "restful-react";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import {
fireEvent,
render,
waitFor,
waitForElementToBeRemoved,
} from "@testing-library/react";
import nock from "nock";
import React from "react";
import Details from "../components/Details";

const queryClient = new QueryClient();

describe("display node information", () => {
beforeAll(() => {
Object.defineProperty(window, "matchMedia", {
Expand All @@ -33,9 +34,9 @@ describe("display node information", () => {
});

const { findByTestId, asFragment } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<Details nodeId="1" />
</RestfulProvider>
</QueryClientProvider>
);

await findByTestId("no-node-info");
Expand All @@ -50,9 +51,9 @@ describe("display node information", () => {
});

const { findByText, asFragment } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<Details nodeId="2" />
</RestfulProvider>
</QueryClientProvider>
);

await findByText("connector");
Expand All @@ -67,9 +68,9 @@ describe("display node information", () => {
});

const { findByText, asFragment } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<Details nodeId="2" />
</RestfulProvider>
</QueryClientProvider>
);

await findByText("connector");
Expand Down Expand Up @@ -106,9 +107,9 @@ describe("display node information", () => {
"http://localhost:5601/app/kibana#/discover?_a=(columns:!(_source),query:(language:lucene,query:'kubernetes.labels.app:%20%22atm-fraud-transactionavroproducer%22'))"
);
const { findByText, asFragment, queryByText } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<Details nodeId="atm-fraud-transactionavroproducer" />
</RestfulProvider>
</QueryClientProvider>
);

await findByText("streaming-app");
Expand Down Expand Up @@ -191,18 +192,17 @@ describe("display node information", () => {
});

nock("http://localhost")
.get(
"/api/node/linking/atm-fraud-incoming-transactions-topic?link_type=grafana"
)
.get("/api/node/linking/atm-fraud-incoming-transactions-topic")
.query({ link_type: "grafana" })
.reply(
200,
"http://localhost:3000/d/path/to/dashboard?var-topics=atm-fraud-incoming-transactions-topic"
);

const { getByText, findByText, getByTestId } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<Details nodeId="atm-fraud-incoming-transactions-topic" />
</RestfulProvider>
</QueryClientProvider>
);

await findByText("v2"); // get dropdown menu for schema version
Expand Down Expand Up @@ -252,9 +252,9 @@ describe("display node information", () => {
.reply(404);

const { findByTestId } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<Details nodeId="atm-fraud-incoming-transactions-topic" />
</RestfulProvider>
</QueryClientProvider>
);

await findByTestId("no-schema-versions");
Expand All @@ -280,9 +280,9 @@ describe("display node information", () => {
.reply(200, []);

const { findByTestId } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<Details nodeId="atm-fraud-incoming-transactions-topic" />
</RestfulProvider>
</QueryClientProvider>
);

await findByTestId("no-schema-versions");
Expand Down Expand Up @@ -312,9 +312,9 @@ describe("display node information", () => {
.reply(404);

const { findByTestId } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<Details nodeId="atm-fraud-incoming-transactions-topic" />
</RestfulProvider>
</QueryClientProvider>
);

await findByTestId("no-schema");
Expand Down
8 changes: 5 additions & 3 deletions frontend/__tests__/DetailsCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render } from "@testing-library/react";
import nock from "nock";
import React from "react";
import { RestfulProvider } from "restful-react";
import DetailsCard from "../components/DetailsCard";
import Node from "../components/graph/Node";

const queryClient = new QueryClient();

describe("display card for node details", () => {
beforeAll(() => {
Object.defineProperty(window, "matchMedia", {
Expand Down Expand Up @@ -38,9 +40,9 @@ describe("display card for node details", () => {
});

const { queryByText } = render(
<RestfulProvider base="http://localhost">
<QueryClientProvider client={queryClient}>
<DetailsCard node={node} />
</RestfulProvider>
</QueryClientProvider>
);

expect(queryByText("test-app-name - Details")).toBeInTheDocument();
Expand Down
11 changes: 10 additions & 1 deletion frontend/__tests__/Search.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { fireEvent, render, within } from "@testing-library/react";
import nock from "nock";
import React from "react";
import App from "../components/App";
import AppComponent from "../components/App";

jest.mock("next/router", () => require("next-router-mock"));

const queryClient = new QueryClient();

const App = () => (
<QueryClientProvider client={queryClient}>
<AppComponent />
</QueryClientProvider>
);

// -- Mock GraphVisualization
jest.mock("../components/graph/Visualization", () => {
return function StubGraphVisualization() {
Expand Down
65 changes: 29 additions & 36 deletions frontend/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
import { useRouter } from "next/router";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { useResizeDetector } from "react-resize-detector";
import { useMutate } from "restful-react";
import {
HTTPValidationError,
useGetMetricsApiMetricsGet,
useGetPipelinesApiPipelinesGet,
useGetPositionedGraphApiGraphGet,
} from "./api/fetchers";
useUpdateApiUpdatePost,
} from "./api/apiComponents";
import { HTTPValidationError } from "./api/apiSchemas";
import DetailsCard from "./DetailsCard";
import Node from "./graph/Node";
import GraphVisualization from "./graph/Visualization";
Expand Down Expand Up @@ -68,15 +68,14 @@ const App: React.FC = () => {
localStorage.setItem(REFRESH_INTERVAL, refreshInterval.toString());
}, [refreshInterval]);

const { mutate: update, loading: isUpdating } = useMutate({
verb: "POST",
path: "/api/update",
});
const { mutate: update, isLoading: isUpdating, isError: isUpdateError } =
useUpdateApiUpdatePost();

const {
data: graph,
loading: isLoadingGraph,
error: graphError,
isLoading: isLoadingGraph,
isError: isGraphError,
refetch: graphRefetch,
} = useGetPositionedGraphApiGraphGet({
queryParams: currentPipeline !== ALL_PIPELINES
Expand All @@ -87,24 +86,24 @@ const App: React.FC = () => {
const {
refetch: retryPipelineGraph,
error: retryPipelineGraphError,
isError: isRetryPipelineGraphError,
data: retryPipelineGraphData,
} = useGetPositionedGraphApiGraphGet({
queryParams: { pipeline_name: currentPipeline },
lazy: true,
});
}, { enabled: false });

const {
data: pipelines,
loading: isLoadingPipelines,
isLoading: isLoadingPipelines,
error: pipelineError,
} = useGetPipelinesApiPipelinesGet({});

const {
data: metrics,
loading: isLoadingMetrics,
isLoading: isLoadingMetrics,
refetch: refetchMetrics,
error: metricsError,
} = useGetMetricsApiMetricsGet({ lazy: true });
} = useGetMetricsApiMetricsGet({}, { enabled: false });

useEffect(() => {
if (refreshInterval && refreshInterval > 0) {
Expand Down Expand Up @@ -132,38 +131,31 @@ const App: React.FC = () => {
}, [graph, query]);

useEffect(() => {
if (graphError) {
if (isGraphError) {
let errorMessage: string | undefined;
if ("data" in graphError) {
// specific pipeline was not found
const data = graphError["data"] as HTTPValidationError;
if (data.detail) {
errorMessage = data.detail.toString();
}
// specific pipeline was not found
const data = graphError.payload as HTTPValidationError;
if (data.detail) {
errorMessage = data.detail.toString();
}
message.error(errorMessage || "Failed loading graph", 5);

if (graphError.status === 404 && currentPipeline !== ALL_PIPELINES) {
if (isGraphError && currentPipeline !== ALL_PIPELINES) {
// check if a re-scrape solves it
const hideMessage = message.warning("Refreshing pipelines", 0);
update({})
.then(() => {
retryPipelineGraph();
})
.catch(() => {
redirectAllPipelines();
})
.finally(() => {
hideMessage();
});
update({});
if (isUpdateError) {
redirectAllPipelines();
} else {
hideMessage();
}
}
}
}, [graphError]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (
retryPipelineGraphError
&& retryPipelineGraphError.status === 404
isRetryPipelineGraphError
&& currentPipeline !== ALL_PIPELINES
) {
// pipeline still not found
Expand Down Expand Up @@ -261,9 +253,10 @@ const App: React.FC = () => {
key="3"
style={{ float: "right", marginLeft: "auto" }}
onClick={() => {
update({})
.then(() => router.reload())
.catch(() => message.error("Failed to update!"));
update({});
router.reload();
// .then(() => router.reload())
// .catch(() => message.error("Failed to update!"));
}}
>
<Button type="dashed" ghost={true}>
Expand Down
27 changes: 14 additions & 13 deletions frontend/components/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import copy from "copy-to-clipboard";
import React from "react";
import ReactJson from "react-json-view";
import {
NodeInfoListItem,
useGetLinkingApiNodeLinkingNodeIdGet,
useGetNodeInfoApiNodeNodeIdGet,
} from "./api/fetchers";
} from "./api/apiComponents";
import { NodeInfoListItem } from "./api/apiSchemas";
import style from "./Details.module.css";
import Schema from "./Schema";

Expand All @@ -16,17 +16,17 @@ interface DetailsProps {
}

const Details = ({ nodeId }: DetailsProps) => {
const { data, loading, error } = useGetNodeInfoApiNodeNodeIdGet({
node_id: nodeId,
const { data, isLoading, isError } = useGetNodeInfoApiNodeNodeIdGet({
pathParams: { nodeId: nodeId },
});
if (loading) {
if (isLoading) {
return (
<div className={style.loadingSpinnerContainer}>
<Spin tip="Loading..." />
</div>
);
}
if (!data || error) {
if (!data || isError) {
return (
<Alert
data-testid="no-node-info"
Expand Down Expand Up @@ -82,14 +82,15 @@ const NodeInfoDetail = ({ infoListItem, nodeId }: NodeInfoDetailProps) => {
};

const LinkInfo = ({ infoListItem, nodeId }: NodeInfoDetailProps) => {
const { data: linkToService, loading } = useGetLinkingApiNodeLinkingNodeIdGet(
{
node_id: nodeId,
queryParams: { link_type: infoListItem.value as string },
}
);
const { data: linkToService, isLoading } =
useGetLinkingApiNodeLinkingNodeIdGet(
{
pathParams: { nodeId: nodeId },
queryParams: { link_type: infoListItem.value as string },
}
);

if (loading) {
if (isLoading) {
return <Spin tip="Loading link..." />;
}
if (linkToService) {
Expand Down
Loading