Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Improving Analyzer Failure State #2697

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ components:
LinterResult:
type: object
properties:
minimumScore:
type: integer
passed:
type: boolean
score:
Expand Down
42 changes: 39 additions & 3 deletions cli/openapi/model_linter_result.go

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

9 changes: 2 additions & 7 deletions server/executor/linter_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ func (e *defaultlinterRunner) onRequest(request LinterRequest) {
return
}

err = lintResource.ValidateResult(run.Linter)
if err != nil {
e.onError(ctx, request, run, err)
return
}

e.onFinish(ctx, request, run)
}

Expand Down Expand Up @@ -173,7 +167,8 @@ func (e *defaultlinterRunner) onRun(ctx context.Context, request LinterRequest,
return e.onError(ctx, request, run, err)
}

run = run.SuccessfullinterExecution(result)
result.MinimumScore = linterResource.MinimumScore
run = run.SuccessfulLinterExecution(result)
err = e.updater.Update(ctx, run)
if err != nil {
log.Printf("[linterRunner] Test %s Run %d: error updating run: %s\n", request.Test.ID, request.Run.ID, err.Error())
Expand Down
7 changes: 4 additions & 3 deletions server/http/mappings/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ func (m OpenAPI) LinterResult(in model.LinterResult) openapi.LinterResult {
}

return openapi.LinterResult{
Passed: in.Passed,
Score: int32(in.Score),
Plugins: plugins,
Passed: in.Passed,
Score: int32(in.Score),
Plugins: plugins,
MinimumScore: int32(in.MinimumScore),
}
}

Expand Down
35 changes: 0 additions & 35 deletions server/linter/resource/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package linter_resource
import (
"fmt"

"github.com/kubeshop/tracetest/server/model"
"github.com/kubeshop/tracetest/server/pkg/id"
"golang.org/x/exp/slices"
)

type (
Expand Down Expand Up @@ -45,36 +43,3 @@ func (l Linter) HasID() bool {
func (l Linter) GetID() id.ID {
return l.ID
}

func (l Linter) ValidateResult(result model.LinterResult) error {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, clients will check score vs minimum score to validate it

if l.MinimumScore != 0 && result.Score < l.MinimumScore {
return fmt.Errorf("linter score validation failed. Minimum %d, Actual: %d", l.MinimumScore, result.Score)
}

failedPlugins := make([]string, 0)
for _, plugin := range result.Plugins {
if !plugin.Passed {
failedPlugins = append(failedPlugins, plugin.Name)
}
}

if len(failedPlugins) == 0 {
return nil
}

requiredPlugins := make([]string, 0)
for _, plugin := range l.Plugins {
if plugin.Required {
requiredPlugins = append(requiredPlugins, plugin.Name)
}
}

for _, plugin := range requiredPlugins {
index := slices.IndexFunc(failedPlugins, func(failedPlugin string) bool { return failedPlugin == plugin })
if index >= 0 {
return fmt.Errorf("linter failed. Required plugin %s failed", plugin)
}
}

return nil
}
7 changes: 4 additions & 3 deletions server/model/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ type Rule interface {
}

type LinterResult struct {
Plugins []PluginResult `json:"plugins"`
Score int `json:"score"`
Passed bool `json:"passed"`
Plugins []PluginResult `json:"plugins"`
Score int `json:"score"`
MinimumScore int `json:"minimumScore"`
Passed bool `json:"passed"`
}

type BaseRule struct {
Expand Down
2 changes: 1 addition & 1 deletion server/model/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (r Run) LinterError(err error) Run {
return r.Finish()
}

func (r Run) SuccessfullinterExecution(linter LinterResult) Run {
func (r Run) SuccessfulLinterExecution(linter LinterResult) Run {
r.State = RunStateAwaitingTestResults
r.Linter = linter

Expand Down
2 changes: 2 additions & 0 deletions server/openapi/model_linter_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
package openapi

type LinterResult struct {
MinimumScore int32 `json:"minimumScore,omitempty"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are now going to persis the minimum score that was used during the execution, not using the global


Passed bool `json:"passed,omitempty"`

Score int32 `json:"score,omitempty"`
Expand Down
34 changes: 18 additions & 16 deletions web/src/components/AnalyzerResult/AnalyzerResult.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,27 @@ export const Description = styled(Typography.Paragraph).attrs({
}
`;

export const ScoreWrapper = styled.div`
position: relative;
export const GlobalResultWrapper = styled.div`
display: grid;
grid-template-columns: auto 1fr;
margin-bottom: 28px;
gap: 45px;
`;

export const ScoreTexContainer = styled.div`
position: absolute;
export const GlobalScoreWrapper = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
`;

export const Score = styled(Typography.Title)`
&& {
font-size: 12px;
margin-bottom: 0;
}
export const ScoreResultWrapper = styled(GlobalScoreWrapper)`
align-items: flex-start;
`;

export const ScoreContainer = styled.div`
margin-bottom: 24px;
text-align: center;
cursor: pointer;
export const GlobalScoreContainer = styled.div`
display: flex;
flex-direction: row;
justify-content: center;
`;

export const RuleContainer = styled.div`
Expand Down Expand Up @@ -79,6 +75,12 @@ export const Subtitle = styled(Typography.Title)`
}
`;

export const ResultText = styled(Typography.Text)<{$passed: boolean}>`
&& {
color: ${({theme, $passed}) => ($passed ? theme.color.success : theme.color.error)};
}
`;

export const ScoreProgress = styled(Progress)`
.ant-progress-inner {
height: 50px !important;
Expand Down
25 changes: 3 additions & 22 deletions web/src/components/AnalyzerResult/AnalyzerResult.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import {Link} from 'react-router-dom';
import {Col, Row, Tooltip} from 'antd';
import LinterResult from 'models/LinterResult.model';
import Trace from 'models/Trace.model';
import {DISCORD_URL, OCTOLIINT_ISSUE_URL} from 'constants/Common.constants';
import {useSettingsValues} from 'providers/SettingsValues/SettingsValues.provider';
import * as S from './AnalyzerResult.styled';
import LintScore from '../LintScore/LintScore';
import BetaBadge from '../BetaBadge/BetaBadge';
import Empty from './Empty';
import Plugins from './Plugins';
import GlobalResult from './GlobalResult';

interface IProps {
result: LinterResult;
trace: Trace;
}

const AnalyzerResult = ({result: {score, passed, plugins = []}, trace}: IProps) => {
const AnalyzerResult = ({result: {score, minimumScore, plugins = []}, trace}: IProps) => {
const {linter} = useSettingsValues();

return (
Expand All @@ -40,25 +39,7 @@ const AnalyzerResult = ({result: {score, passed, plugins = []}, trace}: IProps)

{plugins.length ? (
<>
<Row gutter={[16, 16]}>
<Col span={8} key="avg_result">
<Tooltip title="Tracetest core system supports analyzer evaluation as part of the testing capabilities.">
<S.ScoreContainer>
<S.Subtitle level={3}>Trace Analyzer Result</S.Subtitle> <LintScore score={score} passed={passed} />
</S.ScoreContainer>
</Tooltip>
</Col>
{plugins.map(plugin => (
<Col span={8} key={plugin.name}>
<Tooltip title={plugin.description}>
<S.ScoreContainer key={plugin.name}>
<S.Subtitle level={3}>{plugin.name}</S.Subtitle>
<LintScore score={plugin.score} passed={plugin.passed} />
</S.ScoreContainer>
</Tooltip>
</Col>
))}
</Row>
<GlobalResult score={score} minimumScore={minimumScore} />
<Plugins plugins={plugins} trace={trace} />
</>
) : (
Expand Down
36 changes: 36 additions & 0 deletions web/src/components/AnalyzerResult/GlobalResult.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as S from './AnalyzerResult.styled';
import PercentageScore from '../LintScore/PercentageScore';
import {TooltipQuestion} from '../TooltipQuestion/TooltipQuestion';

interface IProps {
score: number;
minimumScore: number;
}

const GlobalResult = ({score, minimumScore}: IProps) => {
const passedScore = score >= minimumScore;

return (
<S.GlobalResultWrapper>
<S.GlobalScoreWrapper>
<S.Subtitle level={3}>
Overall Trace Analyzer Score
<TooltipQuestion title="Tracetest core system supports analyzer evaluation as part of the testing capabilities." />
</S.Subtitle>
<S.GlobalScoreContainer>
<PercentageScore score={score} />
</S.GlobalScoreContainer>
</S.GlobalScoreWrapper>
{!!minimumScore && (
<S.ScoreResultWrapper>
<S.Subtitle level={3}>Minimum Acceptable Score: {minimumScore}</S.Subtitle>
<S.Subtitle level={3}>
Result: <S.ResultText $passed={passedScore}>{passedScore ? 'Passed' : 'Failed'}</S.ResultText>
</S.Subtitle>
</S.ScoreResultWrapper>
)}
</S.GlobalResultWrapper>
);
};

export default GlobalResult;
2 changes: 1 addition & 1 deletion web/src/components/AnalyzerResult/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Plugins = ({plugins, trace}: IProps) => {
<S.PluginPanel
header={
<Space>
<LintScore width="35px" height="35px" score={plugin.score} passed={plugin.passed} />
<LintScore width="35px" height="35px" score={plugin.score} />
<Typography.Text strong>{plugin.name}</Typography.Text>
<Typography.Text type="secondary">{plugin.description}</Typography.Text>
</Space>
Expand Down