-
Notifications
You must be signed in to change notification settings - Fork 61
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(coral): Subscription details: Fix consumer offsets #2017
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0981b8b
feat(coral): Do not eagerly fetch Consumer offsets, render all partit…
3dc63fa
fix(core/coral): Make OffsetDetails properties required, remove prett…
3d3385c
Merge branch 'main' into 1453-fix-consumer-offsets
203a9ce
Merge branch 'main' into 1453-fix-consumer-offsets
446fc9f
Merge branch 'main' into 1453-fix-consumer-offsets
62db210
Merge branch 'main' into 1453-fix-consumer-offsets
programmiri d6f2733
Merge branch 'main' into 1453-fix-consumer-offsets
programmiri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 5 additions & 4 deletions
9
cluster-api/src/main/java/io/aiven/klaw/clusterapi/models/consumergroup/OffsetDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package io.aiven.klaw.clusterapi.models.consumergroup; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class OffsetDetails { | ||
private String topicPartitionId; | ||
@NotNull private String topicPartitionId; | ||
|
||
private String currentOffset; | ||
@NotNull private String currentOffset; | ||
|
||
private String endOffset; | ||
@NotNull private String endOffset; | ||
|
||
private String lag; | ||
@NotNull private String lag; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
...l/src/app/features/topics/details/subscriptions/components/ConsumerOffsetsValues.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { cleanup, screen } from "@testing-library/react"; | ||
import { userEvent } from "@testing-library/user-event"; | ||
import { ConsumerOffsetsValues } from "src/app/features/topics/details/subscriptions/components/ConsumerOffsetsValues"; | ||
import { getConsumerOffsets } from "src/domain/acl/acl-api"; | ||
import { ConsumerOffsets } from "src/domain/acl/acl-types"; | ||
import { customRender } from "src/services/test-utils/render-with-wrappers"; | ||
|
||
jest.mock("src/domain/acl/acl-api"); | ||
|
||
const mockGetConsumerOffsets = getConsumerOffsets as jest.MockedFunction< | ||
typeof getConsumerOffsets | ||
>; | ||
|
||
const testOffsetsDataOnePartition: ConsumerOffsets[] = [ | ||
{ | ||
topicPartitionId: "0", | ||
currentOffset: "0", | ||
endOffset: "0", | ||
lag: "0", | ||
}, | ||
]; | ||
|
||
const testOffsetsDataTwoPartitions: ConsumerOffsets[] = [ | ||
{ | ||
topicPartitionId: "0", | ||
currentOffset: "0", | ||
endOffset: "0", | ||
lag: "0", | ||
}, | ||
{ | ||
topicPartitionId: "1", | ||
currentOffset: "0", | ||
endOffset: "0", | ||
lag: "0", | ||
}, | ||
]; | ||
|
||
const testOffsetsNoData: ConsumerOffsets[] = []; | ||
|
||
const props = { | ||
topicName: "aivtopic3", | ||
consumerGroup: "-na-", | ||
environment: "1", | ||
setError: jest.fn(), | ||
}; | ||
|
||
describe("ConsumerOffsetValues.tsx", () => { | ||
beforeEach(() => { | ||
customRender(<ConsumerOffsetsValues {...props} />, { | ||
queryClient: true, | ||
}); | ||
}); | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
cleanup(); | ||
}); | ||
|
||
it("does not call getConsumerOffsets on load", () => { | ||
expect(mockGetConsumerOffsets).not.toHaveBeenCalled(); | ||
}); | ||
it("renders correct initial state", () => { | ||
const fetchButton = screen.getByRole("button", { | ||
name: "Fetch the consumer offsets of the current subscription", | ||
}); | ||
const offsetsText = screen.getByText("Fetch offsets to display data."); | ||
|
||
expect(fetchButton).toBeEnabled(); | ||
expect(offsetsText).toBeVisible(); | ||
}); | ||
it("renders Consumer offsets when clicking Fetch offsets button (one partition)", async () => { | ||
mockGetConsumerOffsets.mockResolvedValue(testOffsetsDataOnePartition); | ||
|
||
const fetchButton = screen.getByRole("button", { | ||
name: "Fetch the consumer offsets of the current subscription", | ||
}); | ||
|
||
await userEvent.click(fetchButton); | ||
|
||
const offsets = screen.getByText( | ||
"Partition 0: Current offset 0 | End offset 0 | Lag 0" | ||
); | ||
expect(offsets).toBeVisible(); | ||
|
||
const refetchButton = screen.getByRole("button", { | ||
name: "Refetch the consumer offsets of the current subscription", | ||
}); | ||
|
||
expect(refetchButton).toBeEnabled(); | ||
}); | ||
it("renders Consumer offsets when clicking Fetch offsets button (two partitions)", async () => { | ||
mockGetConsumerOffsets.mockResolvedValue(testOffsetsDataTwoPartitions); | ||
|
||
const fetchButton = screen.getByRole("button", { | ||
name: "Fetch the consumer offsets of the current subscription", | ||
}); | ||
|
||
await userEvent.click(fetchButton); | ||
|
||
const offsetsPartitionOne = screen.getByText( | ||
"Partition 0: Current offset 0 | End offset 0 | Lag 0" | ||
); | ||
const offsetsPartitionTwo = screen.getByText( | ||
"Partition 1: Current offset 0 | End offset 0 | Lag 0" | ||
); | ||
expect(offsetsPartitionOne).toBeVisible(); | ||
expect(offsetsPartitionTwo).toBeVisible(); | ||
|
||
const refetchButton = screen.getByRole("button", { | ||
name: "Refetch the consumer offsets of the current subscription", | ||
}); | ||
|
||
expect(refetchButton).toBeEnabled(); | ||
}); | ||
it("renders no data message when clicking Fetch offsets button (no data)", async () => { | ||
mockGetConsumerOffsets.mockResolvedValue(testOffsetsNoData); | ||
|
||
const fetchButton = screen.getByRole("button", { | ||
name: "Fetch the consumer offsets of the current subscription", | ||
}); | ||
|
||
await userEvent.click(fetchButton); | ||
|
||
const noOffsets = screen.getByText("No offsets are currently retained."); | ||
|
||
expect(noOffsets).toBeVisible(); | ||
|
||
const refetchButton = screen.getByRole("button", { | ||
name: "Refetch the consumer offsets of the current subscription", | ||
}); | ||
|
||
expect(refetchButton).toBeEnabled(); | ||
}); | ||
}); |
125 changes: 125 additions & 0 deletions
125
coral/src/app/features/topics/details/subscriptions/components/ConsumerOffsetsValues.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { Box, Button, Grid, Skeleton, Typography } from "@aivenio/aquarium"; | ||
import refreshIcon from "@aivenio/aquarium/dist/src/icons/refresh"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useEffect, useState } from "react"; | ||
import { getConsumerOffsets } from "src/domain/acl/acl-api"; | ||
import { ConsumerOffsets } from "src/domain/acl/acl-types"; | ||
import { HTTPError } from "src/services/api"; | ||
import { parseErrorMsg } from "src/services/mutation-utils"; | ||
|
||
interface ConsumerOffsetsProps { | ||
setError: (error: string) => void; | ||
topicName: string; | ||
environment: string; | ||
consumerGroup?: string; | ||
} | ||
|
||
const parseOffsetsContent = ({ | ||
topicPartitionId, | ||
currentOffset, | ||
endOffset, | ||
lag, | ||
}: ConsumerOffsets) => { | ||
return `Partition ${topicPartitionId}: Current offset ${currentOffset} | End offset ${endOffset} | Lag ${lag}`; | ||
}; | ||
|
||
const ConsumerOffsetsValues = ({ | ||
setError, | ||
topicName, | ||
environment, | ||
consumerGroup, | ||
}: ConsumerOffsetsProps) => { | ||
const [shouldFetch, setShouldFetch] = useState(false); | ||
const { | ||
data: offsetsData = [], | ||
error: offsetsError, | ||
isFetched: offsetsDataFetched, | ||
isFetching, | ||
refetch, | ||
} = useQuery<ConsumerOffsets[], HTTPError>( | ||
["getConsumerOffsets", topicName, environment, consumerGroup], | ||
{ | ||
queryFn: () => { | ||
return getConsumerOffsets({ | ||
topicName, | ||
env: environment, | ||
consumerGroupId: consumerGroup || "", | ||
}); | ||
}, | ||
enabled: shouldFetch, | ||
} | ||
); | ||
|
||
useEffect(() => { | ||
if (offsetsError !== null) { | ||
setError(parseErrorMsg(offsetsError)); | ||
} | ||
}, [offsetsError]); | ||
|
||
return ( | ||
<Grid style={{ gridTemplateColumns: "70% 30%" }}> | ||
<Grid.Item> | ||
{!shouldFetch && ( | ||
<Typography.Default htmlTag="dd"> | ||
Fetch offsets to display data. | ||
</Typography.Default> | ||
)} | ||
<Box.Flex flexDirection="column"> | ||
{offsetsData.length === 0 && offsetsDataFetched && ( | ||
<Typography.Default htmlTag="dd"> | ||
No offsets are currently retained. | ||
</Typography.Default> | ||
)} | ||
{isFetching ? ( | ||
<Box.Flex | ||
flexDirection={"column"} | ||
gap={"2"} | ||
data-testid={"offsets-skeleton"} | ||
> | ||
{/* Render one skeleton on first fetch | ||
Render as many skeletons as partitions for refetch */} | ||
{(offsetsData.length === 0 ? ["skeleton"] : offsetsData).map( | ||
(_, index) => { | ||
return <Skeleton key={index} height={22} width={350} />; | ||
} | ||
)} | ||
</Box.Flex> | ||
) : ( | ||
offsetsData.map((data, index) => { | ||
return ( | ||
<Typography.Default | ||
key={data.topicPartitionId || index} | ||
htmlTag="dd" | ||
> | ||
{parseOffsetsContent(data)} | ||
</Typography.Default> | ||
); | ||
}) | ||
)} | ||
</Box.Flex> | ||
</Grid.Item> | ||
<Grid.Item justifySelf="right" alignSelf="end"> | ||
<Button.Secondary | ||
key="button" | ||
onClick={() => { | ||
if (!shouldFetch) { | ||
setShouldFetch(true); | ||
return; | ||
} | ||
refetch(); | ||
}} | ||
disabled={isFetching} | ||
loading={isFetching} | ||
aria-label={`${ | ||
shouldFetch ? "Refetch" : "Fetch" | ||
} the consumer offsets of the current subscription`} | ||
icon={refreshIcon} | ||
> | ||
{shouldFetch ? "Refetch" : "Fetch"} offsets | ||
</Button.Secondary> | ||
</Grid.Item> | ||
</Grid> | ||
); | ||
}; | ||
|
||
export { ConsumerOffsetsValues }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, I also thought we've already removed that 🤔