mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 02:59:00 +08:00
added test folder for testing interface
This commit is contained in:
parent
55f7f56acf
commit
606fa6591d
76
pkg/query-service/app/clickhouseReader/reader.go
Normal file
76
pkg/query-service/app/clickhouseReader/reader.go
Normal file
@ -0,0 +1,76 @@
|
||||
package clickhouseReader
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
minTimespanForProgressiveSearch = time.Hour
|
||||
minTimespanForProgressiveSearchMargin = time.Minute
|
||||
maxProgressiveSteps = 4
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoOperationsTable = errors.New("no operations table supplied")
|
||||
ErrNoIndexTable = errors.New("no index table supplied")
|
||||
ErrStartTimeRequired = errors.New("start time is required for search queries")
|
||||
)
|
||||
|
||||
// SpanWriter for reading spans from ClickHouse
|
||||
type TraceReader struct {
|
||||
db *sql.DB
|
||||
operationsTable string
|
||||
indexTable string
|
||||
spansTable string
|
||||
}
|
||||
|
||||
// NewTraceReader returns a TraceReader for the database
|
||||
func NewTraceReader(db *sql.DB, operationsTable, indexTable, spansTable string) *TraceReader {
|
||||
return &TraceReader{
|
||||
db: db,
|
||||
operationsTable: operationsTable,
|
||||
indexTable: indexTable,
|
||||
spansTable: spansTable,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TraceReader) getStrings(ctx context.Context, sql string, args ...interface{}) ([]string, error) {
|
||||
rows, err := r.db.QueryContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
values := []string{}
|
||||
|
||||
for rows.Next() {
|
||||
var value string
|
||||
if err := rows.Scan(&value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values = append(values, value)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// GetServices fetches the sorted service list that have not expired
|
||||
func (r *TraceReader) GetServices(ctx context.Context) ([]string, error) {
|
||||
|
||||
if r.operationsTable == "" {
|
||||
return nil, ErrNoOperationsTable
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("SELECT service FROM %s GROUP BY service", r.operationsTable)
|
||||
|
||||
return r.getStrings(ctx, query)
|
||||
}
|
22
pkg/query-service/app/druidReader/reader.go
Normal file
22
pkg/query-service/app/druidReader/reader.go
Normal file
@ -0,0 +1,22 @@
|
||||
package druidReader
|
||||
|
||||
import (
|
||||
"go.signoz.io/query-service/druidQuery"
|
||||
"go.signoz.io/query-service/model"
|
||||
)
|
||||
|
||||
type DruidReader struct {
|
||||
Client
|
||||
SqlClient
|
||||
}
|
||||
|
||||
func NewSpanReader() {
|
||||
initialize()
|
||||
}
|
||||
func initialize() {
|
||||
|
||||
}
|
||||
|
||||
func (druid *Druid) GetServices(client, query *model.GetServicesParams) {
|
||||
return druidQuery.GetServices(druid.sqlClient, query)
|
||||
}
|
12
pkg/query-service/app/fatory.go
Normal file
12
pkg/query-service/app/fatory.go
Normal file
@ -0,0 +1,12 @@
|
||||
// Reader finds and loads traces and other data from storage.
|
||||
type QueryReader interface {
|
||||
// GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error)
|
||||
GetServices(ctx context.Context)
|
||||
// GetOperations(ctx context.Context, query OperationQueryParameters) ([]Operation, error)
|
||||
// FindTraces(ctx context.Context, query *TraceQueryParameters) ([]*model.Trace, error)
|
||||
// FindTraceIDs(ctx context.Context, query *TraceQueryParameters) ([]model.TraceID, error)
|
||||
}
|
||||
|
||||
func NewQueryReader() {
|
||||
|
||||
}
|
20
pkg/query-service/test/clickhouse/clickhouse.go
Normal file
20
pkg/query-service/test/clickhouse/clickhouse.go
Normal file
@ -0,0 +1,20 @@
|
||||
package clickhouse
|
||||
|
||||
type ClickHouseReader struct {
|
||||
ClickHouseClientUrl string
|
||||
}
|
||||
|
||||
func connect() string {
|
||||
return "Connected to ClickHouse"
|
||||
}
|
||||
|
||||
func NewSpanReader() *ClickHouseReader {
|
||||
connect()
|
||||
return &ClickHouseReader{
|
||||
ClickHouseClientUrl: "http://localhost:9000",
|
||||
}
|
||||
}
|
||||
|
||||
func (chReader *ClickHouseReader) GetServices() string {
|
||||
return "Hello from ClickHouse"
|
||||
}
|
20
pkg/query-service/test/druid/druid.go
Normal file
20
pkg/query-service/test/druid/druid.go
Normal file
@ -0,0 +1,20 @@
|
||||
package druid
|
||||
|
||||
type DruidReader struct {
|
||||
DruidClientUrl string
|
||||
}
|
||||
|
||||
func connect() string {
|
||||
return "Connected to Druid"
|
||||
}
|
||||
|
||||
func NewSpanReader() *DruidReader {
|
||||
connect()
|
||||
return &DruidReader{
|
||||
DruidClientUrl: "http://localhost:8888",
|
||||
}
|
||||
}
|
||||
|
||||
func (druidReader *DruidReader) GetServices() string {
|
||||
return "Hello from Druid"
|
||||
}
|
27
pkg/query-service/test/test.go
Normal file
27
pkg/query-service/test/test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"go.signoz.io/query-service/test/clickhouse"
|
||||
"go.signoz.io/query-service/test/druid"
|
||||
)
|
||||
|
||||
type StorageReader interface {
|
||||
GetServices() string
|
||||
}
|
||||
|
||||
func main() {
|
||||
storage := os.Getenv("STORAGE")
|
||||
var client StorageReader
|
||||
|
||||
if storage == "druid" {
|
||||
client = druid.NewSpanReader()
|
||||
} else if storage == "clickhouse" {
|
||||
client = clickhouse.NewSpanReader()
|
||||
}
|
||||
|
||||
services := client.GetServices()
|
||||
fmt.Println(services)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user