Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ release/deployment/helm-chart/umbrella/Chart.lock

**/kitex_remote_config.json
.coda/
.coco
backend/script/errorx/.env
.cursor/
AGENTS.md
11 changes: 10 additions & 1 deletion backend/modules/evaluation/application/experiment_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,12 +1104,21 @@ func (e *experimentApplication) InsightAnalysisExperiment(ctx context.Context, r
if err != nil {
return nil, err
}

var startTime, endTime *int64
if got.StartAt != nil {
startTime = gptr.Of(got.StartAt.UnixMilli())
}
if got.EndAt != nil {
endTime = gptr.Of(got.EndAt.UnixMilli())
}

recordID, err := e.CreateAnalysisRecord(ctx, &entity.ExptInsightAnalysisRecord{
SpaceID: req.GetWorkspaceID(),
ExptID: req.GetExptID(),
CreatedBy: session.UserID,
Status: entity.InsightAnalysisStatus_Running,
}, session)
}, session, gptr.Indirect(startTime), gptr.Indirect(endTime))
if err != nil {
return nil, err
}
Expand Down
17 changes: 13 additions & 4 deletions backend/modules/evaluation/application/experiment_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"reflect"
"strconv"
"testing"
"time"

"github.com/bytedance/gg/gptr"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -3599,11 +3600,15 @@ func TestInsightAnalysisExperiment(t *testing.T) {

t.Run("成功创建洞察分析", func(t *testing.T) {
// Mock the manager.Get call
mockManager.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.Experiment{CreatedBy: "test-user"}, nil)
mockManager.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.Experiment{
CreatedBy: "test-user",
StartAt: &[]time.Time{time.Now()}[0],
EndAt: &[]time.Time{time.Now()}[0],
}, nil)
// Mock the auth.AuthorizationWithoutSPI call
mockAuth.EXPECT().AuthorizationWithoutSPI(gomock.Any(), gomock.Any()).Return(nil)
// Mock the CreateAnalysisRecord call
mockInsightService.EXPECT().CreateAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(123), nil)
mockInsightService.EXPECT().CreateAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(123), nil)

_, err := app.InsightAnalysisExperiment(ctx, req)
assert.NoError(t, err)
Expand All @@ -3627,9 +3632,13 @@ func TestInsightAnalysisExperiment(t *testing.T) {
})

t.Run("创建分析记录失败", func(t *testing.T) {
mockManager.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.Experiment{CreatedBy: "test-user"}, nil)
mockManager.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.Experiment{
CreatedBy: "test-user",
StartAt: &[]time.Time{time.Now()}[0],
EndAt: &[]time.Time{time.Now()}[0],
}, nil)
mockAuth.EXPECT().AuthorizationWithoutSPI(gomock.Any(), gomock.Any()).Return(nil)
mockInsightService.EXPECT().CreateAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(0), errors.New("create analysis record error"))
mockInsightService.EXPECT().CreateAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(0), errors.New("create analysis record error"))

_, err := app.InsightAnalysisExperiment(ctx, req)
assert.Error(t, err)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import (

//go:generate mockgen -destination=mocks/trace_agent.go -package=mocks . IAgentAdapter
type IAgentAdapter interface {
CallTraceAgent(ctx context.Context, spaceID int64, url string) (int64, error)
CallTraceAgent(ctx context.Context, spaceID int64, url string, startTime, endTime int64) (int64, error)
GetReport(ctx context.Context, spaceID, reportID int64) (report string, status entity.ReportStatus, err error)
}
8 changes: 5 additions & 3 deletions backend/modules/evaluation/domain/entity/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ type ExportCSVEvent struct {
ExperimentID int64
SpaceID int64

Session *Session
ExportScene ExportScene
CreatedAt int64
Session *Session
ExportScene ExportScene
CreatedAt int64
ExptStartTime int64 // Unix Time
ExptEndTime int64 // Unix Time
}

type ExportScene int
Expand Down
4 changes: 2 additions & 2 deletions backend/modules/evaluation/domain/service/insight_analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

type IExptInsightAnalysisService interface {
CreateAnalysisRecord(ctx context.Context, record *entity.ExptInsightAnalysisRecord, session *entity.Session) (int64, error)
GenAnalysisReport(ctx context.Context, spaceID, exptID, recordID, CreateAt int64) error
CreateAnalysisRecord(ctx context.Context, record *entity.ExptInsightAnalysisRecord, session *entity.Session, startTime, endTime int64) (int64, error)
GenAnalysisReport(ctx context.Context, spaceID, exptID, recordID, CreateAt, startTime, endTime int64) error
GetAnalysisRecordByID(ctx context.Context, spaceID, exptID, recordID int64, session *entity.Session) (*entity.ExptInsightAnalysisRecord, error)
ListAnalysisRecord(ctx context.Context, spaceID, exptID int64, page entity.Page, session *entity.Session) ([]*entity.ExptInsightAnalysisRecord, int64, error)
DeleteAnalysisRecord(ctx context.Context, spaceID, exptID, recordID int64) error
Expand Down
30 changes: 17 additions & 13 deletions backend/modules/evaluation/domain/service/insight_analysis_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ func NewInsightAnalysisService(repo repo.IExptInsightAnalysisRecordRepo,
}
}

func (e ExptInsightAnalysisServiceImpl) CreateAnalysisRecord(ctx context.Context, record *entity.ExptInsightAnalysisRecord, session *entity.Session) (int64, error) {
func (e ExptInsightAnalysisServiceImpl) CreateAnalysisRecord(ctx context.Context, record *entity.ExptInsightAnalysisRecord, session *entity.Session, startTime, endTime int64) (int64, error) {
recordID, err := e.repo.CreateAnalysisRecord(ctx, record)
if err != nil {
return 0, err
}

exportEvent := &entity.ExportCSVEvent{
ExportID: recordID,
ExperimentID: record.ExptID,
SpaceID: record.SpaceID,
ExportScene: entity.ExportSceneInsightAnalysis,
CreatedAt: time.Now().Unix(),
ExportID: recordID,
ExperimentID: record.ExptID,
SpaceID: record.SpaceID,
ExportScene: entity.ExportSceneInsightAnalysis,
CreatedAt: time.Now().Unix(),
ExptStartTime: startTime,
ExptEndTime: endTime,
}
err = e.exptPublisher.PublishExptExportCSVEvent(ctx, exportEvent, gptr.Of(time.Second*3))
if err != nil {
Expand All @@ -76,7 +78,7 @@ func (e ExptInsightAnalysisServiceImpl) CreateAnalysisRecord(ctx context.Context
return recordID, nil
}

func (e ExptInsightAnalysisServiceImpl) GenAnalysisReport(ctx context.Context, spaceID, exptID, recordID, CreateAt int64) (err error) {
func (e ExptInsightAnalysisServiceImpl) GenAnalysisReport(ctx context.Context, spaceID, exptID, recordID, CreateAt, startTime, endTime int64) (err error) {
analysisRecord, err := e.repo.GetAnalysisRecordByID(ctx, spaceID, exptID, recordID)
if err != nil {
return err
Expand Down Expand Up @@ -125,7 +127,7 @@ func (e ExptInsightAnalysisServiceImpl) GenAnalysisReport(ctx context.Context, s
return err
}

reportID, err := e.agentAdapter.CallTraceAgent(ctx, spaceID, url)
reportID, err := e.agentAdapter.CallTraceAgent(ctx, spaceID, url, startTime, endTime)
if err != nil {
return err
}
Expand All @@ -135,11 +137,13 @@ func (e ExptInsightAnalysisServiceImpl) GenAnalysisReport(ctx context.Context, s

// 发送时间检查分析报告生成状态
exportEvent := &entity.ExportCSVEvent{
ExportID: recordID,
ExperimentID: exptID,
SpaceID: spaceID,
ExportScene: entity.ExportSceneInsightAnalysis,
CreatedAt: CreateAt,
ExportID: recordID,
ExperimentID: exptID,
SpaceID: spaceID,
ExportScene: entity.ExportSceneInsightAnalysis,
CreatedAt: CreateAt,
ExptStartTime: startTime,
ExptEndTime: endTime,
}
err = e.exptPublisher.PublishExptExportCSVEvent(ctx, exportEvent, gptr.Of(time.Minute*3))
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestExptInsightAnalysisServiceImpl_CreateAnalysisRecord(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setup()
result, err := service.CreateAnalysisRecord(ctx, tt.record, tt.session)
result, err := service.CreateAnalysisRecord(ctx, tt.record, tt.session, 0, 0)
if tt.wantErr {
assert.Error(t, err)
} else {
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestExptInsightAnalysisServiceImpl_GenAnalysisReport(t *testing.T) {
}, nil)
mocks.exptResultExportService.EXPECT().DoExportCSV(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
mocks.fileClient.EXPECT().SignDownloadReq(gomock.Any(), gomock.Any(), gomock.Any()).Return("http://test-url.com", make(map[string][]string), nil)
mocks.agentAdapter.EXPECT().CallTraceAgent(gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(123), nil)
mocks.agentAdapter.EXPECT().CallTraceAgent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(123), nil)
mocks.publisher.EXPECT().PublishExptExportCSVEvent(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
mocks.repo.EXPECT().UpdateAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
},
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestExptInsightAnalysisServiceImpl_GenAnalysisReport(t *testing.T) {
}, nil)
mocks.exptResultExportService.EXPECT().DoExportCSV(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
mocks.fileClient.EXPECT().SignDownloadReq(gomock.Any(), gomock.Any(), gomock.Any()).Return("http://test-url.com", make(map[string][]string), nil)
mocks.agentAdapter.EXPECT().CallTraceAgent(gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(0), errors.New("agent error"))
mocks.agentAdapter.EXPECT().CallTraceAgent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(0), errors.New("agent error"))
mocks.repo.EXPECT().UpdateAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, record *entity.ExptInsightAnalysisRecord, opts ...db.Option) error {
assert.Equal(t, entity.InsightAnalysisStatus_Failed, record.Status)
return nil
Expand All @@ -289,7 +289,7 @@ func TestExptInsightAnalysisServiceImpl_GenAnalysisReport(t *testing.T) {
}, nil)
mocks.exptResultExportService.EXPECT().DoExportCSV(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
mocks.fileClient.EXPECT().SignDownloadReq(gomock.Any(), gomock.Any(), gomock.Any()).Return("http://test-url.com", make(map[string][]string), nil)
mocks.agentAdapter.EXPECT().CallTraceAgent(gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(123), nil)
mocks.agentAdapter.EXPECT().CallTraceAgent(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(123), nil)
mocks.publisher.EXPECT().PublishExptExportCSVEvent(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("publish error"))
mocks.repo.EXPECT().UpdateAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, record *entity.ExptInsightAnalysisRecord, opts ...db.Option) error {
assert.Equal(t, entity.InsightAnalysisStatus_Failed, record.Status)
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestExptInsightAnalysisServiceImpl_GenAnalysisReport(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setup()
err := service.GenAnalysisReport(ctx, tt.spaceID, tt.exptID, tt.recordID, tt.createAt)
err := service.GenAnalysisReport(ctx, tt.spaceID, tt.exptID, tt.recordID, tt.createAt, 0, 0)
if tt.wantErr {
assert.Error(t, err)
} else {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (e *ExptExportConsumer) HandleMessage(ctx context.Context, ext *mq.MessageE
func (e *ExptExportConsumer) handleEvent(ctx context.Context, event *entity.ExportCSVEvent) (err error) {
switch event.ExportScene {
case entity.ExportSceneInsightAnalysis:
err = e.exptInsightAnalysisService.GenAnalysisReport(ctx, event.SpaceID, event.ExperimentID, event.ExportID, event.CreatedAt)
err = e.exptInsightAnalysisService.GenAnalysisReport(ctx, event.SpaceID, event.ExperimentID, event.ExportID, event.CreatedAt, event.ExptStartTime, event.ExptEndTime)
if err != nil {
logs.CtxError(ctx, "ExptExportConsumer GenAnalysisReport fail, expt_id:%v, err: %v", event.ExperimentID, err)
return nil
Expand Down
2 changes: 1 addition & 1 deletion backend/modules/evaluation/infra/rpc/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewAgentAdapter() rpc.IAgentAdapter {
return &AgentAdapter{}
}

func (a AgentAdapter) CallTraceAgent(ctx context.Context, spaceID int64, url string) (int64, error) {
func (a AgentAdapter) CallTraceAgent(ctx context.Context, spaceID int64, url string, startTime, endTime int64) (int64, error) {
return 0, errorx.NewByCode(errno.CommonInternalErrorCode, errorx.WithExtraMsg("CallTraceAgent not implement"))
}

Expand Down
2 changes: 1 addition & 1 deletion backend/modules/evaluation/infra/rpc/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestAgentAdapter_CallTraceAgent(t *testing.T) {
ctx := context.Background()
adapter, ctx := tt.setup(ctx)

result, err := adapter.CallTraceAgent(ctx, 123, "http://example.com")
result, err := adapter.CallTraceAgent(ctx, 123, "http://example.com", 0, 0)

if tt.wantErr {
assert.Error(t, err)
Expand Down
Loading