Skip to content

Commit

Permalink
use index table in /metrics/index.json
Browse files Browse the repository at this point in the history
  • Loading branch information
lomik committed Jul 14, 2019
1 parent 9c9c96f commit 29c77cf
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"

"github.com/lomik/graphite-clickhouse/config"
"github.com/lomik/graphite-clickhouse/finder"
"github.com/lomik/graphite-clickhouse/helper/clickhouse"
"github.com/lomik/graphite-clickhouse/pkg/scope"
)
Expand All @@ -19,18 +20,35 @@ type Index struct {
}

func New(config *config.Config, ctx context.Context) (*Index, error) {
opts := clickhouse.Options{
Timeout: config.ClickHouse.TreeTimeout.Value(),
ConnectTimeout: config.ClickHouse.ConnectTimeout.Value(),
var reader io.ReadCloser
var err error

if config.ClickHouse.IndexTable != "" {
opts := clickhouse.Options{
Timeout: config.ClickHouse.IndexTimeout.Value(),
ConnectTimeout: config.ClickHouse.ConnectTimeout.Value(),
}
reader, err = clickhouse.Reader(
scope.WithTable(ctx, config.ClickHouse.IndexTable),
config.ClickHouse.Url,
fmt.Sprintf("SELECT Path FROM %s WHERE Date = '%s' AND Level >= %d AND Level < %d GROUP BY Path",
config.ClickHouse.IndexTable, finder.DefaultTreeDate, finder.TreeLevelOffset, finder.ReverseTreeLevelOffset),
opts,
)
} else {
opts := clickhouse.Options{
Timeout: config.ClickHouse.TreeTimeout.Value(),
ConnectTimeout: config.ClickHouse.ConnectTimeout.Value(),
}
reader, err = clickhouse.Reader(
scope.WithTable(ctx, config.ClickHouse.TreeTable),
config.ClickHouse.Url,
fmt.Sprintf("SELECT Path FROM %s GROUP BY Path", config.ClickHouse.TreeTable),
opts,
)
}
reader, err := clickhouse.Reader(
scope.WithTable(ctx, config.ClickHouse.TreeTable),
config.ClickHouse.Url,
fmt.Sprintf("SELECT Path FROM %s GROUP BY Path", config.ClickHouse.TreeTable),
opts,
)

if err != nil {
reader.Close()
return nil, err
}

Expand Down

0 comments on commit 29c77cf

Please sign in to comment.