Skip to content

Commit

Permalink
feat: unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Jun 23, 2021
1 parent ee81c6c commit ca4d1e9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 36 deletions.
6 changes: 4 additions & 2 deletions collector/app/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (

func initHttpServer(a *App) observer.Handler {
return func(coll map[info.Info]*config.Config) {
a.Logger().Info("about to start server")

dataID := serverconfig.DataID

a.Logger().Info(fmt.Sprintf("start to get config: group = %s, dataID = %s", a.ACMGroup(), dataID))

cc, ok := coll[info.Info{
Group: a.ACMGroup(),
DataID: dataID,
Expand Down Expand Up @@ -77,6 +77,8 @@ func initTablestoreClient(a *App) observer.Handler {
return func(coll map[info.Info]*config.Config) {
dataID := tablestoreconfig.DataID

a.Logger().Info(fmt.Sprintf("start to get config: group = %s, dataID = %s", a.ACMGroup(), dataID))

cc, ok := coll[info.Info{
Group: a.ACMGroup(),
DataID: dataID,
Expand Down
43 changes: 21 additions & 22 deletions collector/server/controller/profile/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"reflect"
"strconv"
"time"

Expand Down Expand Up @@ -466,28 +467,26 @@ func searchProfile(tb *env.TablestoreClient, req MergeProfileReq, offset int32)
*/
func unMarshalProfileRow(row *tablestore.Row) *profilemodel.Model {
result := new(profilemodel.Model)
for _, v := range row.Columns {
switch v.ColumnName {
case profilemodel.CreateTime:
result.CreateTime = v.Value.(int64)
case profilemodel.GoVersion:
result.GoVersion = v.Value.(string)
case profilemodel.Host:
result.Host = v.Value.(string)
case profilemodel.IP:
result.IP = v.Value.(string)
case profilemodel.ProfileType:
result.ProfileType = v.Value.(string)
case profilemodel.SendTime:
result.SendTime = v.Value.(int64)
case profilemodel.Service:
result.Service = v.Value.(string)
case profilemodel.ServiceVersion:
result.ServiceVersion = v.Value.(string)
case profilemodel.ObjectName:
result.ObjectName = v.Value.(string)
case profilemodel.Size:
result.Size = v.Value.(int64)
ve := reflect.ValueOf(result).Elem()
te := reflect.TypeOf(result).Elem()
ret := make(map[string]reflect.Value)
for i := 0; i < te.NumField(); i++ {
tag := te.Field(i).Tag.Get("ots")
ret[tag] = ve.Field(i)
}
for _, column := range row.Columns {
v, ok := ret[column.ColumnName]
if !ok {
continue
}
if !v.IsValid() || !v.CanSet() {
continue
}
switch v.Kind() {
case reflect.String:
v.SetString(column.Value.(string))
case reflect.Int64:
v.SetInt(column.Value.(int64))
}
}
return result
Expand Down
18 changes: 17 additions & 1 deletion collector/server/controller/profile/controller_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
package profile

import "testing"
import (
"testing"

"github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore"
)

func TestUploadPath(t *testing.T) {
t.Logf(UploadPath("abc", "bcf", "cpu", "efg"))
}

func TestUnMarshalProfileRow(t *testing.T) {
row := new(tablestore.Row)
row.Columns = append(row.Columns, &tablestore.AttributeColumn{
ColumnName: "profile_id",
Value: "dfdfdkfmdkfkdfkdm",
}, &tablestore.AttributeColumn{
ColumnName: "size",
Value: int64(64),
})
unMarshalProfileRow(row)
}
22 changes: 11 additions & 11 deletions collector/server/model/profilemodel/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const (
)

type Model struct {
ProfileId string `json:"profile_id"`
Service string `json:"service"`
ServiceVersion string `json:"service_version"`
Host string `json:"host"`
IP string `json:"ip"`
GoVersion string `json:"go_version"`
ProfileType string `json:"profile_type"`
SendTime int64 `json:"send_time"`
CreateTime int64 `json:"create_time"`
ObjectName string `json:"object_name"`
Size int64 `json:"size"`
ProfileId string `ots:"profile_id"`
Service string `ots:"service"`
ServiceVersion string `ots:"service_version"`
Host string `ots:"host"`
IP string `ots:"ip"`
GoVersion string `ots:"go_version"`
ProfileType string `ots:"profile_type"`
SendTime int64 `ots:"send_time"`
CreateTime int64 `ots:"create_time"`
ObjectName string `ots:"object_name"`
Size int64 `ots:"size"`
}
1 change: 1 addition & 0 deletions script/tablestore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package script

0 comments on commit ca4d1e9

Please sign in to comment.