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

Add support for explain.tensor.ru #5

Merged
merged 1 commit into from
May 25, 2020
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ On default, make install puts the compiled binary in `go/bin`.
```bash
postgres=# \o | plan-exporter
```
* You may wish to specify `--target [dalibo|depesz|tensor]` to customize your visualizer

1. Run explain query:
```bash
Expand Down Expand Up @@ -75,6 +76,7 @@ On default, make install puts the compiled binary in `go/bin`.
Available targets:
- `depesz` - https://explain.depesz.com [default]
- `dalibo` - https://explain.dalibo.com
- `tensor` - https://explain.tensor.ru

## Contact Information

Expand Down
36 changes: 36 additions & 0 deletions visualizer/tensor/tensor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Package tensor provides a query plan exporter for the Tensor visualizer.
package tensor

import (
"fmt"
"net/url"

"github.com/agneum/plan-exporter/client"
)

// visualizer constants
const (
VisualizerType = "tensor"
visualizerURL = "https://explain.tensor.ru/explain"
)

// Tensor defines a query plan exporter for the Tensor visualizer.
type Tensor struct {
}

// New creates a new Tensor exporter.
func New() *Tensor {
return &Tensor{}
}

// Export posts plan to a visualizer and returns link to the visualization plan page.
func (d *Tensor) Export(plan string) (string, error) {
formVal := url.Values{"explain": []string{plan}}

explainURL, err := client.MakeRequest(visualizerURL, formVal)
if err != nil {
return "", fmt.Errorf("failed to make a request: %w", err)
}

return explainURL, nil
}
4 changes: 4 additions & 0 deletions visualizer/visualizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/agneum/plan-exporter/pgscanner"
"github.com/agneum/plan-exporter/visualizer/dalibo"
"github.com/agneum/plan-exporter/visualizer/depesz"
"github.com/agneum/plan-exporter/visualizer/tensor"
)

// New creates a new query plan exporter by visualizer type.
Expand All @@ -17,6 +18,9 @@ func New(visualizer string) (pgscanner.PlanExporter, error) {

case depesz.VisualizerType:
return depesz.New(), nil

case tensor.VisualizerType:
return tensor.New(), nil
}

return nil, fmt.Errorf("unknown visualizer given %q", visualizer)
Expand Down