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

create download button to download metadata in blocks #3259

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ NOTE: As semantic versioning states all 0.y.z releases can contain breaking chan
We use *breaking :warning:* to mark changes that are not backward compatible (relates only to v0.y.z releases.)

## Unreleased
- [#3259](https://github.com/thanos-io/thanos/pull/3259) Thanos BlockViewer: Added a button in the blockviewer that allows users to download the metadata of a block.

- [#3261](https://github.com/thanos-io/thanos/pull/3261) Thanos Store: Use segment files specified in meta.json file, if present. If not present, Store does the LIST operation as before.
- [#3276](https://github.com/thanos-io/thanos/pull/3276) Query Frontend: Support query splitting and retry for labels and series requests.
Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/react-app/src/pages/graph/PanelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const PanelListContent: FC<PanelListProps> = ({

useEffect(() => {
// Convert stores data to a unified stores array.
let storeList: Store[] = [];
for (let type in stores) {
const storeList: Store[] = [];
for (const type in stores) {
storeList.push(...stores[type]);
}
setStoreData(storeList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('BlockDetails', () => {
// do nothing
},
};

window.URL.createObjectURL = jest.fn();
const blockDetails = mount(<BlockDetails {...defaultProps} />);

it('renders a heading with block ulid', () => {
Expand Down Expand Up @@ -79,6 +79,13 @@ describe('BlockDetails', () => {
expect(div.find('span').text()).toBe(sampleBlock.thanos.source);
});

it('renders the download button', () => {
const div = blockDetails.find({ 'data-testid': 'download' });
window.URL.createObjectURL = jest.fn(() => 'details');
expect(div).toHaveLength(1);
expect(div.find('a').text()).toBe('Download meta.json');
});

it('renders a list of the labels', () => {
const div = blockDetails.find({ 'data-testid': 'labels' });
const list = div.find('ul');
Expand Down
8 changes: 8 additions & 0 deletions pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { FC } from 'react';
import { Block } from './block';
import styles from './blocks.module.css';
import moment from 'moment';
import { Button } from 'reactstrap';
import { download } from './helpers';

export interface BlockDetailsProps {
block: Block | undefined;
Expand Down Expand Up @@ -63,6 +65,12 @@ export const BlockDetails: FC<BlockDetailsProps> = ({ block, selectBlock }) => {
))}
</ul>
</div>
<hr />
<div data-testid="download">
onprem marked this conversation as resolved.
Show resolved Hide resolved
<a href={download(block)} download="meta.json">
<Button>Download meta.json</Button>
</a>
</div>
</>
)}
</div>
Expand Down
6 changes: 6 additions & 0 deletions pkg/ui/react-app/src/thanos/pages/blocks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ export const sortBlocks = (blocks: Block[], label: string): { [source: string]:
});
return sortedPool;
};

export const download = (blob: Block): string => {
const url = window.URL.createObjectURL(new Blob([JSON.stringify(blob, null, 2)], { type: 'application/json' }));

return url;
};