mirror of
https://github.com/zhengkai/orca.git
synced 2026-02-04 16:52:26 +08:00
up
This commit is contained in:
@@ -9,8 +9,6 @@ RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30.0
|
|||||||
|
|
||||||
COPY . /project
|
COPY . /project
|
||||||
|
|
||||||
RUN cd /project/proto && make
|
|
||||||
|
|
||||||
RUN /project/server/build/build-server.sh prod
|
RUN /project/server/build/build-server.sh prod
|
||||||
|
|
||||||
# clean stage
|
# clean stage
|
||||||
|
|||||||
@@ -20,3 +20,63 @@ message EsMetricsToken {
|
|||||||
uint32 completion = 2;
|
uint32 completion = 2;
|
||||||
uint32 prompt = 3;
|
uint32 prompt = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message EsErrorTry {
|
||||||
|
EsError error = 1;
|
||||||
|
uint32 status = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsError {
|
||||||
|
repeated EsErrorRootCause root_cause = 1;
|
||||||
|
string type = 2;
|
||||||
|
string reason = 3;
|
||||||
|
uint32 line = 4;
|
||||||
|
uint32 col = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsErrorRootCause {
|
||||||
|
string type = 1;
|
||||||
|
string reason = 2;
|
||||||
|
uint32 line = 3;
|
||||||
|
uint32 col = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsResultDateHistogram {
|
||||||
|
EsResultDateHistogramAggregations aggregations = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsResultDateHistogramAggregations {
|
||||||
|
EsResultDateHistogramSum bytes_sum = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsResultDateHistogramSum {
|
||||||
|
repeated EsResultDateHistogramBucket buckets = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsResultDateHistogramBucket {
|
||||||
|
EsResultValueInt reqBytes = 1;
|
||||||
|
EsResultValueInt rspBytes = 2;
|
||||||
|
EsResultValueInt tokenTotal = 3;
|
||||||
|
EsResultValueInt tokenCompletion = 4;
|
||||||
|
EsResultValueInt tokenPrompt = 5;
|
||||||
|
uint32 doc_count = 6;
|
||||||
|
uint64 key = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsDateHistogramList {
|
||||||
|
repeated EsDateHistogram list = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsDateHistogram {
|
||||||
|
uint32 reqBytes = 1;
|
||||||
|
uint32 rspBytes = 2;
|
||||||
|
uint32 tokenTotal = 3;
|
||||||
|
uint32 tokenCompletion = 4;
|
||||||
|
uint32 tokenPrompt = 5;
|
||||||
|
uint32 count = 6;
|
||||||
|
uint32 ts = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EsResultValueInt {
|
||||||
|
uint32 value = 1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ fi
|
|||||||
|
|
||||||
. ./common.sh
|
. ./common.sh
|
||||||
|
|
||||||
|
if [ ! -e ../src/pb/req.pb.go ]; then
|
||||||
|
(cd ../../proto && protoc --go_out=../server/src ./*.proto)
|
||||||
|
fi
|
||||||
|
|
||||||
DATE=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S')
|
DATE=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S')
|
||||||
GO_VERSION=$(go version)
|
GO_VERSION=$(go version)
|
||||||
GIT_VERSION=$(./git-hash.sh)
|
GIT_VERSION=$(./git-hash.sh)
|
||||||
|
|||||||
@@ -15,18 +15,22 @@ import (
|
|||||||
//go:embed tpl/mapping.json
|
//go:embed tpl/mapping.json
|
||||||
var indexMapping string
|
var indexMapping string
|
||||||
|
|
||||||
func indexName(ts uint32) string {
|
func indexNameBase() string {
|
||||||
|
|
||||||
index := `orca-metrics`
|
index := `orca-metrics`
|
||||||
if !config.Prod {
|
if !config.Prod {
|
||||||
index = `dev-` + index
|
index = `dev-` + index
|
||||||
}
|
}
|
||||||
|
|
||||||
index = fmt.Sprintf(`%s-%s`, index, time.Unix(int64(ts), 0).Format(`2006.01.02`))
|
|
||||||
|
|
||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func indexName(ts uint32) string {
|
||||||
|
return fmt.Sprintf(`%s-%s`, indexNameBase(), time.Unix(int64(ts), 0).Format(`2006.01.02`))
|
||||||
|
}
|
||||||
|
|
||||||
|
func indexNameAll() string {
|
||||||
|
return indexNameBase() + `-*`
|
||||||
|
}
|
||||||
|
|
||||||
func createIndex() {
|
func createIndex() {
|
||||||
|
|
||||||
ts := zu.TS()
|
ts := zu.TS()
|
||||||
|
|||||||
75
server/src/es/search.go
Normal file
75
server/src/es/search.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package es
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"project/pb"
|
||||||
|
"project/util"
|
||||||
|
"project/zj"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LastItem ...
|
||||||
|
func LastItem() {
|
||||||
|
|
||||||
|
query := `{
|
||||||
|
"size": 100,
|
||||||
|
"sort": [
|
||||||
|
{
|
||||||
|
"ts": {
|
||||||
|
"order": "desc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`
|
||||||
|
zj.J(query)
|
||||||
|
|
||||||
|
/*
|
||||||
|
ab, err := Search(query)
|
||||||
|
if err != nil {
|
||||||
|
zj.W(`fail`, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
util.WriteFile(`search.json`, ab)
|
||||||
|
|
||||||
|
zj.J(string(ab))
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search ...
|
||||||
|
func Search(query string, m proto.Message) error {
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
re, err := theClient.Search(
|
||||||
|
theClient.Search.WithContext(ctx),
|
||||||
|
theClient.Search.WithIndex(indexNameAll()),
|
||||||
|
theClient.Search.WithBody(strings.NewReader(query)),
|
||||||
|
theClient.Search.WithTrackTotalHits(false),
|
||||||
|
)
|
||||||
|
defer cancel()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer re.Body.Close()
|
||||||
|
|
||||||
|
ab, err := io.ReadAll(re.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
et := &pb.EsErrorTry{}
|
||||||
|
util.JSONUnmarshal(ab, et)
|
||||||
|
e := et.GetError()
|
||||||
|
if e != nil {
|
||||||
|
return errors.New(e.Reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
util.WriteFile(`last-search.json`, ab)
|
||||||
|
|
||||||
|
return util.JSONUnmarshal(ab, m)
|
||||||
|
}
|
||||||
@@ -20,6 +20,8 @@ func Start() {
|
|||||||
es.Init()
|
es.Init()
|
||||||
|
|
||||||
if !config.Prod {
|
if !config.Prod {
|
||||||
|
// es.LastItem()
|
||||||
|
// st.DateHistogram()
|
||||||
go es.Test()
|
go es.Test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
53
server/src/st/date-histogram.go
Normal file
53
server/src/st/date-histogram.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package st
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"project/es"
|
||||||
|
"project/pb"
|
||||||
|
"project/zj"
|
||||||
|
|
||||||
|
_ "embed" //
|
||||||
|
|
||||||
|
"github.com/zhengkai/zu"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed tpl/date-histogram.json
|
||||||
|
var queryDateHistogramTpl string
|
||||||
|
|
||||||
|
// DateHistogram ...
|
||||||
|
func DateHistogram() {
|
||||||
|
|
||||||
|
query := fmt.Sprintf(
|
||||||
|
queryDateHistogramTpl,
|
||||||
|
`now-24h`,
|
||||||
|
`now`,
|
||||||
|
)
|
||||||
|
|
||||||
|
d := &pb.EsResultDateHistogram{}
|
||||||
|
err := es.Search(query, d)
|
||||||
|
if err != nil {
|
||||||
|
zj.W(`fail`, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
li := d.GetAggregations().GetBytesSum().GetBuckets()
|
||||||
|
if len(li) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
re := make([]*pb.EsDateHistogram, len(li))
|
||||||
|
for i, v := range li {
|
||||||
|
re[i] = &pb.EsDateHistogram{
|
||||||
|
Ts: uint32(v.GetKey() / 1000),
|
||||||
|
ReqBytes: v.GetReqBytes().GetValue(),
|
||||||
|
RspBytes: v.GetRspBytes().GetValue(),
|
||||||
|
TokenTotal: v.GetTokenTotal().GetValue(),
|
||||||
|
TokenCompletion: v.GetTokenCompletion().GetValue(),
|
||||||
|
TokenPrompt: v.GetTokenPrompt().GetValue(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
j := zu.JSONPretty(re)
|
||||||
|
// util.WriteFile(`date-histogram.json`, []byte(j))
|
||||||
|
zj.J(j)
|
||||||
|
}
|
||||||
46
server/src/st/tpl/date-histogram.json
Normal file
46
server/src/st/tpl/date-histogram.json
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"size": 0,
|
||||||
|
"query": {
|
||||||
|
"range": {
|
||||||
|
"ts": {
|
||||||
|
"gte": "%s",
|
||||||
|
"lt": "%s"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"aggs": {
|
||||||
|
"bytes_sum": {
|
||||||
|
"date_histogram": {
|
||||||
|
"field": "ts",
|
||||||
|
"calendar_interval": "1m"
|
||||||
|
},
|
||||||
|
"aggs": {
|
||||||
|
"tokenTotal": {
|
||||||
|
"sum": {
|
||||||
|
"field": "token.total"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tokenCompletion": {
|
||||||
|
"sum": {
|
||||||
|
"field": "token.completion"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tokenPrompt": {
|
||||||
|
"sum": {
|
||||||
|
"field": "token.prompt"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"reqBytes": {
|
||||||
|
"sum": {
|
||||||
|
"field": "reqBytes"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rspBytes": {
|
||||||
|
"sum": {
|
||||||
|
"field": "rspBytes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
server/src/st/web.go
Normal file
7
server/src/st/web.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package st
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("vim-go")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user