fix: ts issue fixed with live tail (#3397)

This commit is contained in:
Nityananda Gohain 2023-08-22 16:48:44 +05:30 committed by GitHub
parent b6e111b835
commit 2df5a9d72d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 46 deletions

View File

@ -4600,6 +4600,8 @@ func (r *ClickHouseReader) GetSpanAttributeKeys(ctx context.Context) (map[string
func (r *ClickHouseReader) LiveTailLogsV3(ctx context.Context, query string, timestampStart uint64, idStart string, client *v3.LogsLiveTailClient) { func (r *ClickHouseReader) LiveTailLogsV3(ctx context.Context, query string, timestampStart uint64, idStart string, client *v3.LogsLiveTailClient) {
if timestampStart == 0 { if timestampStart == 0 {
timestampStart = uint64(time.Now().UnixNano()) timestampStart = uint64(time.Now().UnixNano())
} else {
timestampStart = uint64(utils.GetEpochNanoSecs(int64(timestampStart)))
} }
ticker := time.NewTicker(time.Duration(r.liveTailRefreshSeconds) * time.Second) ticker := time.NewTicker(time.Duration(r.liveTailRefreshSeconds) * time.Second)

View File

@ -2,7 +2,6 @@ package v3
import ( import (
"fmt" "fmt"
"math"
"strings" "strings"
"go.signoz.io/signoz/pkg/query-service/constants" "go.signoz.io/signoz/pkg/query-service/constants"
@ -165,20 +164,6 @@ func buildLogsTimeSeriesFilterQuery(fs *v3.FilterSet, groupBy []v3.AttributeKey)
return queryString, nil return queryString, nil
} }
// getZerosForEpochNano returns the number of zeros to be appended to the epoch time for converting it to nanoseconds
func getZerosForEpochNano(epoch int64) int64 {
count := 0
if epoch == 0 {
count = 1
} else {
for epoch != 0 {
epoch /= 10
count++
}
}
return int64(math.Pow(10, float64(19-count)))
}
func buildLogsQuery(panelType v3.PanelType, start, end, step int64, mq *v3.BuilderQuery, graphLimitQtype string, preferRPM bool) (string, error) { func buildLogsQuery(panelType v3.PanelType, start, end, step int64, mq *v3.BuilderQuery, graphLimitQtype string, preferRPM bool) (string, error) {
filterSubQuery, err := buildLogsTimeSeriesFilterQuery(mq.Filters, mq.GroupBy) filterSubQuery, err := buildLogsTimeSeriesFilterQuery(mq.Filters, mq.GroupBy)
@ -187,7 +172,7 @@ func buildLogsQuery(panelType v3.PanelType, start, end, step int64, mq *v3.Build
} }
// timerange will be sent in epoch millisecond // timerange will be sent in epoch millisecond
timeFilter := fmt.Sprintf("(timestamp >= %d AND timestamp <= %d)", start*getZerosForEpochNano(start), end*getZerosForEpochNano(end)) timeFilter := fmt.Sprintf("(timestamp >= %d AND timestamp <= %d)", utils.GetEpochNanoSecs(start), utils.GetEpochNanoSecs(end))
selectLabels := getSelectLabels(mq.AggregateOperator, mq.GroupBy) selectLabels := getSelectLabels(mq.AggregateOperator, mq.GroupBy)

View File

@ -828,36 +828,6 @@ func TestBuildLogsQuery(t *testing.T) {
} }
} }
var testGetZerosForEpochNanoData = []struct {
Name string
Epoch int64
Multiplier int64
Result int64
}{
{
Name: "Test 1",
Epoch: 1680712080000,
Multiplier: 1000000,
Result: 1680712080000000000,
},
{
Name: "Test 1",
Epoch: 1680712080000000000,
Multiplier: 1,
Result: 1680712080000000000,
},
}
func TestGetZerosForEpochNano(t *testing.T) {
for _, tt := range testGetZerosForEpochNanoData {
Convey("testGetZerosForEpochNanoData", t, func() {
multiplier := getZerosForEpochNano(tt.Epoch)
So(multiplier, ShouldEqual, tt.Multiplier)
So(tt.Epoch*multiplier, ShouldEqual, tt.Result)
})
}
}
var testOrderBy = []struct { var testOrderBy = []struct {
Name string Name string
PanelType v3.PanelType PanelType v3.PanelType

View File

@ -2,6 +2,7 @@ package utils
import ( import (
"fmt" "fmt"
"math"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@ -228,3 +229,18 @@ func getPointerValue(v interface{}) interface{} {
return v return v
} }
} }
// GetEpochNanoSecs takes epoch and returns it in ns
func GetEpochNanoSecs(epoch int64) int64 {
temp := epoch
count := 0
if epoch == 0 {
count = 1
} else {
for epoch != 0 {
epoch /= 10
count++
}
}
return temp * int64(math.Pow(10, float64(19-count)))
}

View File

@ -387,3 +387,32 @@ func TestClickHouseFormattedValue(t *testing.T) {
}) })
} }
} }
var testGetEpochNanoSecsData = []struct {
Name string
Epoch int64
Multiplier int64
Result int64
}{
{
Name: "Test 1",
Epoch: 1680712080000,
Result: 1680712080000000000,
},
{
Name: "Test 1",
Epoch: 1680712080000000000,
Result: 1680712080000000000,
},
}
func TestGetEpochNanoSecs(t *testing.T) {
for _, tt := range testGetEpochNanoSecsData {
t.Run(tt.Name, func(t *testing.T) {
got := GetEpochNanoSecs(tt.Epoch)
if !reflect.DeepEqual(got, tt.Result) {
t.Errorf("ClickHouseFormattedValue() = %v, want %v", got, tt.Result)
}
})
}
}