Skip to content

Commit 7e6f8d0

Browse files
committed
Initial commit
0 parents  commit 7e6f8d0

File tree

9 files changed

+1064
-0
lines changed

9 files changed

+1064
-0
lines changed

.github/workflows/release.yaml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Release Binaries
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # Trigger on any tag starting with 'v'
7+
8+
jobs:
9+
release:
10+
name: Build and Release
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write # Needed for creating GitHub releases
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v4
21+
with:
22+
go-version: '1.22' # You can adjust this to your Go version
23+
24+
- name: Get tag version
25+
id: get_version
26+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
27+
28+
- name: Get dependencies
29+
run: go mod tidy
30+
31+
- name: Build binaries
32+
run: |
33+
mkdir -p release
34+
35+
# Build for Linux
36+
GOOS=linux GOARCH=amd64 go build -o release/workload-exporter-${{ steps.get_version.outputs.VERSION }}-linux-amd64 ./
37+
GOOS=linux GOARCH=arm64 go build -o release/workload-exporter-${{ steps.get_version.outputs.VERSION }}-linux-arm64 ./
38+
39+
# Build for macOS
40+
GOOS=darwin GOARCH=amd64 go build -o release/workload-exporter-${{ steps.get_version.outputs.VERSION }}-darwin-amd64 ./
41+
GOOS=darwin GOARCH=arm64 go build -o release/workload-exporter-${{ steps.get_version.outputs.VERSION }}-darwin-arm64 ./
42+
43+
# Build for Windows
44+
GOOS=windows GOARCH=amd64 go build -o release/workload-exporter-${{ steps.get_version.outputs.VERSION }}-windows-amd64.exe ./
45+
GOOS=windows GOARCH=386 go build -o release/workload-exporter-${{ steps.get_version.outputs.VERSION }}-windows-386.exe ./
46+
47+
- name: Create checksums
48+
run: |
49+
cd release
50+
for file in *; do
51+
sha256sum "$file" > "${file}.sha256"
52+
done
53+
cd ..
54+
55+
- name: Package binaries
56+
run: |
57+
cd release
58+
59+
# Linux
60+
tar czf workload-exporter-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz workload-exporter-${{ steps.get_version.outputs.VERSION }}-linux-amd64 workload-exporter-${{ steps.get_version.outputs.VERSION }}-linux-amd64.sha256
61+
tar czf workload-exporter-${{ steps.get_version.outputs.VERSION }}-linux-arm64.tar.gz workload-exporter-${{ steps.get_version.outputs.VERSION }}-linux-arm64 workload-exporter-${{ steps.get_version.outputs.VERSION }}-linux-arm64.sha256
62+
63+
# macOS
64+
tar czf workload-exporter-${{ steps.get_version.outputs.VERSION }}-darwin-amd64.tar.gz workload-exporter-${{ steps.get_version.outputs.VERSION }}-darwin-amd64 workload-exporter-${{ steps.get_version.outputs.VERSION }}-darwin-amd64.sha256
65+
tar czf workload-exporter-${{ steps.get_version.outputs.VERSION }}-darwin-arm64.tar.gz workload-exporter-${{ steps.get_version.outputs.VERSION }}-darwin-arm64 workload-exporter-${{ steps.get_version.outputs.VERSION }}-darwin-arm64.sha256
66+
67+
# Windows
68+
zip workload-exporter-${{ steps.get_version.outputs.VERSION }}-windows-amd64.zip workload-exporter-${{ steps.get_version.outputs.VERSION }}-windows-amd64.exe workload-exporter-${{ steps.get_version.outputs.VERSION }}-windows-amd64.exe.sha256
69+
zip workload-exporter-${{ steps.get_version.outputs.VERSION }}-windows-386.zip workload-exporter-${{ steps.get_version.outputs.VERSION }}-windows-386.exe workload-exporter-${{ steps.get_version.outputs.VERSION }}-windows-386.exe.sha256
70+
71+
cd ..
72+
73+
- name: Create Release
74+
uses: softprops/action-gh-release@v1
75+
with:
76+
name: Release ${{ steps.get_version.outputs.VERSION }}
77+
draft: false
78+
prerelease: false
79+
files: |
80+
release/*.tar.gz
81+
release/*.zip
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Go workspace file
15+
go.work
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go debugging files
21+
__debug_bin
22+
23+
# GoLand/JetBrains IDE files
24+
.idea/
25+
*.iws
26+
*.iml
27+
*.ipr
28+
.idea_modules/
29+
out/
30+
31+
# VSCode files (in case you use both)
32+
.vscode/
33+
*.code-workspace
34+
35+
# macOS system files
36+
.DS_Store
37+
.AppleDouble
38+
.LSOverride
39+
._*
40+
41+
# Windows system files
42+
Thumbs.db
43+
ehthumbs.db
44+
Desktop.ini
45+
46+
# Linux
47+
*~
48+
.directory
49+
50+
# Project specific: CockroachDB Export Tool output files
51+
# Exclude zip files generated by the export tool
52+
*.zip
53+
cockroach_export.zip
54+
*_export.zip
55+
56+
# Exclude unzipped content (temp directories that might be created)
57+
crdb-export-*/
58+
crdb-import-*/
59+
**/metadata.json
60+
**/*_schema.sql
61+
**/*_data.csv
62+
tmp/
63+
64+
# Misc
65+
workload-export.go

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# CockroachDB Workload Export Tool
2+
3+
A command-line utility for exporting workload data from a CockroachDB cluster into a portable zip file for analysis.
4+
5+
## Purpose
6+
7+
This tool simplifies the process of exporting workload data for analysis, including:
8+
9+
1. Statement and transaction statistics
10+
2. Contention events
11+
3. Cluster metadata, including node topology and configuration
12+
4. Table schemas
13+
5. Zone configurations
14+
6. System settings
15+
16+
## Installation
17+
18+
### From Binary Releases
19+
20+
Download the appropriate binary for your platform from the [releases page](https://github.com/cockroachlabs/workload-exporter/releases).
21+
22+
### From Source
23+
24+
```bash
25+
# Clone the repository
26+
git clone https://github.com/yourusername/workload-exporter.git
27+
cd workload-exporter
28+
29+
# Build the binary
30+
go build -o workload-exporter
31+
```
32+
33+
## Usage
34+
35+
### Export Command
36+
37+
Export workload data from a CockroachDB cluster to a zip file:
38+
39+
```bash
40+
workload-exporter export \
41+
-c "postgresql://user:password@host:26257/database?sslmode=verify-full" \
42+
[options]
43+
```
44+
45+
#### Export Options:
46+
47+
- `--connection-url`, `-c`: Connection string for CockroachDB (required)
48+
- `--output-file`, `-o`: Output zip file name (default: "workload-export.zip")
49+
- `--start`, `-s`: start time (default: current time - 6 hours)
50+
- `--end`, `-e`: End time (default: current time + 1 hour)
51+
52+
## Examples
53+
54+
### Basic Export
55+
56+
Export workload data:
57+
58+
```bash
59+
# Export
60+
workload-exporter export -c "postgresql://user:password@source-host:26257/?sslmode=verify-full"
61+
```
62+
63+
### Specific time period
64+
65+
Export for a specific time period:
66+
67+
```bash
68+
# Export a specific time window
69+
workload-exporter export -c "postgresql://user:password@host:26257/?sslmode=verify-full"
70+
-s '2025-04-18T13:25:00Z'
71+
-e '2025-04-18T20:25:00Z'
72+
```
73+
74+
### Custom output file
75+
76+
Export using a custom file:
77+
78+
```bash
79+
workload-exporter export -c "postgresql://user:password@host:26257/?sslmode=verify-full"
80+
-o 'my-export.zip'
81+
```
82+
83+
## File Format
84+
85+
The export zip file contains:
86+
87+
- `metadata.json`: Information about the export, including databases, tables, and configuration
88+
- One file per exported table in the format `[database].[table]`
89+
90+
## Building from Source
91+
92+
Requirements:
93+
- Go 1.18 or later
94+
95+
```bash
96+
# Get dependencies
97+
go mod tidy
98+
99+
# Build
100+
go build -o workload-exporter
101+
```
102+
103+
## License
104+
105+
[MIT License](LICENSE)

cmd/export.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package cmd
2+
3+
import (
4+
"github.com/cockroachlabs/workload-exporter/pkg/export"
5+
"github.com/spf13/cobra"
6+
"time"
7+
)
8+
9+
var connectionUrlFlag string
10+
var outputFileFlag string
11+
var startFlag string
12+
var endFlag string
13+
14+
var exportCmd = &cobra.Command{
15+
Use: "export",
16+
Short: "Export cluster workload",
17+
RunE: func(cmd *cobra.Command, args []string) error {
18+
19+
start, err := time.Parse(time.RFC3339, startFlag)
20+
if err != nil {
21+
return err
22+
}
23+
end, err := time.Parse(time.RFC3339, endFlag)
24+
if err != nil {
25+
return err
26+
}
27+
28+
exporter, err := export.NewExporter(export.Config{
29+
ConnectionString: connectionUrlFlag,
30+
OutputFile: outputFileFlag,
31+
TimeRange: export.TimeRange{
32+
Start: start,
33+
End: end,
34+
},
35+
})
36+
37+
if err != nil {
38+
return err
39+
}
40+
41+
err = exporter.Export()
42+
43+
if err != nil {
44+
return err
45+
}
46+
47+
return nil
48+
},
49+
}
50+
51+
func init() {
52+
rootCmd.AddCommand(exportCmd)
53+
54+
exportCmd.Flags().StringVarP(&connectionUrlFlag, "connection-url", "c", "", "connection url")
55+
exportCmd.Flags().StringVarP(&outputFileFlag, "output-file", "o", "workload-export.zip", "output file")
56+
exportCmd.Flags().StringVarP(&startFlag, "start", "s", defaultStartFlag(), "start time")
57+
exportCmd.Flags().StringVarP(&endFlag, "end", "e", defaultEndFlag(), "end time")
58+
}
59+
60+
func defaultStartFlag() string {
61+
return time.Now().UTC().Add(-6 * time.Hour).Format(time.RFC3339)
62+
}
63+
64+
func defaultEndFlag() string {
65+
return time.Now().UTC().Add(+1 * time.Hour).Format(time.RFC3339)
66+
}

cmd/root.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cmd
2+
3+
import (
4+
"github.com/sirupsen/logrus"
5+
"github.com/spf13/cobra"
6+
"os"
7+
)
8+
9+
var debugFlag bool
10+
11+
// rootCmd represents the base command when called without any subcommands
12+
var rootCmd = &cobra.Command{
13+
Use: "workload-analyzer",
14+
Short: "A brief description of your application",
15+
Long: `A longer description that spans multiple lines and likely contains
16+
examples and usage of using your application. For example:
17+
18+
Cobra is a CLI library for Go that empowers applications.
19+
This application is a tool to generate the needed files
20+
to quickly create a Cobra application.`,
21+
// Uncomment the following line if your bare application
22+
// has an action associated with it:
23+
// Run: func(cmd *cobra.Command, args []string) { },
24+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
25+
if debugFlag {
26+
logrus.SetLevel(logrus.DebugLevel)
27+
}
28+
},
29+
}
30+
31+
// Execute adds all child commands to the root command and sets flags appropriately.
32+
// This is called by main.main(). It only needs to happen once to the rootCmd.
33+
func Execute() {
34+
err := rootCmd.Execute()
35+
if err != nil {
36+
os.Exit(1)
37+
}
38+
}
39+
40+
func init() {
41+
// Here you will define your flags and configuration settings.
42+
// Cobra supports persistent flags, which, if defined here,
43+
// will be global for your application.
44+
45+
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.workload-analyzer.yaml)")
46+
47+
// Cobra also supports local flags, which will only run
48+
// when this action is called directly.
49+
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
50+
rootCmd.PersistentFlags().BoolVar(&debugFlag, "debug", false, "Show debug output")
51+
}

0 commit comments

Comments
 (0)