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

export statements #778

Merged
merged 24 commits into from
Nov 5, 2020
Merged

export statements #778

merged 24 commits into from
Nov 5, 2020

Conversation

baurine
Copy link
Collaborator

@baurine baurine commented Oct 22, 2020

close #565

What did:

  • Export the queried statements result as .csv format file

Screenshots:

(mocked time delays)
3

WeCom20201026-110427@2x

WeCom20201026-110456@2x

@baurine baurine marked this pull request as draft October 22, 2020 13:51
@baurine baurine changed the title export statements [wip] export statements Oct 22, 2020
@baurine baurine marked this pull request as ready for review October 26, 2020 05:15
@baurine baurine changed the title [wip] export statements export statements Oct 26, 2020
Comment on lines 275 to 291
csvData := [][]string{fields}
for _, overview := range overviews {
row := []string{}
v := reflect.ValueOf(overview)
for _, field := range fields {
filedName := fieldsMap[field]
s := v.FieldByName(filedName)
var val string
switch s.Interface().(type) {
case int:
val = strconv.FormatInt(s.Int(), 10)
default:
val = s.String()
}
row = append(row, val)
}
csvData = append(csvData, row)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some 3rd-party library for easier use? This logic may be the same when exporting slow queries.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, let me have a check.

Copy link
Collaborator Author

@baurine baurine Oct 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this lib can help us: https://github.com/oleiade/reflections , let me try it.

But it doesn't reduce much code, we need to extract it to a util method when we need to reuse it.

Co-authored-by: Wenxuan <hi@breeswish.org>
pkg/apiserver/statement/statement.go Outdated Show resolved Hide resolved
pkg/apiserver/statement/statement.go Outdated Show resolved Hide resolved
pkg/apiserver/statement/statement.go Outdated Show resolved Hide resolved
ui/lib/apps/Statement/pages/List/index.tsx Outdated Show resolved Hide resolved
pkg/apiserver/statement/statement.go Outdated Show resolved Hide resolved
secretKey := cryptopasta.NewEncryptionKey()

rowBuf := bytes.NewBuffer(nil)
csvwriter := csv.NewWriter(rowBuf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library implements an encrypted io.Reader / io.Writer, which could be a better choice. Maybe you can have a try: https://github.com/Xeoncross/go-aesctr-with-hmac

The encapsulation of the stream is file stream -> encrypted stream -> csv stream.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you! let me have a look. Since I found zip the encrypted file won't reduce the size much, so I think it doesn't need to zip file in local, right? but to still zip it when sending data back to the client after being decrypted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, we use gzip already. Is there any further benefit of packaging as a zip for transmission?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, let me focus on the encryption first.

Copy link
Collaborator Author

@baurine baurine Oct 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works fine! and the final flow likes this:

image

@baurine baurine marked this pull request as draft October 29, 2020 03:53
@baurine
Copy link
Collaborator Author

baurine commented Oct 29, 2020

Encrypt and decrypt flow:

image

@baurine
Copy link
Collaborator Author

baurine commented Oct 29, 2020

New effect:

(Mocked time delays)
6

@baurine baurine marked this pull request as ready for review October 29, 2020 09:35
@unbyte
Copy link
Contributor

unbyte commented Oct 29, 2020

#778 (comment) is better

improvement of UX:

message.info({content, key, duration: 0}) // 0 means close manually

and close message before download

message.destory(key)

reference: https://ant.design/components/message-cn/

@breezewish
Copy link
Member

There is a spinner message: https://codesandbox.io/s/3yq1h

@baurine
Copy link
Collaborator Author

baurine commented Oct 29, 2020

There is a spinner message: https://codesandbox.io/s/3yq1h

Cool!

@baurine
Copy link
Collaborator Author

baurine commented Oct 29, 2020

New effect:

7

@baurine
Copy link
Collaborator Author

baurine commented Oct 30, 2020

TODO:

  • export all fields instead of selected fields

@breezewish
Copy link
Member

@baurine Is this PR ready to merge?

@baurine
Copy link
Collaborator Author

baurine commented Nov 4, 2020

@baurine Is this PR ready to merge?

Yep,I think so.

@breezewish breezewish merged commit ab97091 into pingcap:master Nov 5, 2020
@unbyte unbyte mentioned this pull request Nov 7, 2020
@baurine baurine deleted the export-statements branch November 9, 2020 14:34
breezewish pushed a commit that referenced this pull request Nov 26, 2020
breezewish added a commit that referenced this pull request Nov 26, 2020
* misc: Increase ulimit to 65535 for test env (#756)
* test: Fix frontend CI (#752)
* ui: fix dayjs i18n (#755)
* ui: handle error globally (#757)
* statement, slow_query: support all fields in list page (#749)
* ui: memorize expand/collapse full text in detail pages (#775)
* ui: break loop dependencies (#771)
* ui: fix browser compatibility check (#776)
* ui: Refine store location, add zoom and pan (#772)
* ui: show disk usage information for statement and slow query (#777)
* ui: use qps instead of ops (#786)
* statement: support export (#778)
*: Fix slow query and start_ts not working in some cases (#793)
* ui: fix errors doesn't display (#794)
* ui: fix the error message doesn't show correct (#799)
* slow_queries: support export (#792)
* ui: add MySqlFormatter to customize the sql formatter (#805)
*: fix query statement detail error cause by round (#806)
* ui: copy original content instead of formatted content for CopyLink (#802)
* add min height of topology canvas (#804)
* metrics: Support customize Prometheus address (#808)
* clusterinfo: Refine (#815)
* ui: Open statement and slow log in new tab (#816)
* ui: add more time field for slow query detail page (#810)
* slowlog: Improve descriptions (#817)
* build: add action to check release-version is changed for release branch
* Release v2020.11.26.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Requirement Request: Data Export in statement
3 participants