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

Enhancement: Support different SLA types #2906

Merged
merged 6 commits into from
Jan 30, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/components/DeploymentServiceLevelAgreementCard.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<template>
<p-list-item class="deployment-service-level-agreement-card">
<p-key-value class="deployment-service-level-agreement-card__item" label="Name" :value="serviceLevelAgreement.name" />
<p-key-value class="deployment-service-level-agreement-card__item" label="Type" :value="serviceLevelAgreement.getSlaType()" />
<p-key-value class="deployment-service-level-agreement-card__item" label="Type" :value="serviceLevelAgreement.getDisplaySlaType()" />
<p-key-value class="deployment-service-level-agreement-card__item" label="Severity" :value="uppercase(serviceLevelAgreement.severity)" />
<p-key-value v-if="serviceLevelAgreement.description" class="deployment-service-level-agreement-card__item" label="Description" :value="serviceLevelAgreement.description" />
<p-key-value class="deployment-service-level-agreement-card__item" label="Duration" :value="secondsToString(serviceLevelAgreement.durationInSeconds())" />
<template v-for="kv in serviceLevelAgreement.getSlaDefinitionKeyValuePairs()" :key="kv.key">
<p-key-value class="deployment-service-level-agreement-card__item" :label="kv.key" :value="kv.value" />
</template>
</p-list-item>
</template>


<script lang="ts" setup>
import { ServiceLevelAgreement } from '@/models/ServiceLevelAgreement'
import { uppercase } from '@/utilities'
import { secondsToString } from '@/utilities/seconds'

defineProps<{
serviceLevelAgreement: ServiceLevelAgreement,
Expand Down
2 changes: 1 addition & 1 deletion src/maps/serviceLevelAgreements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const mapServiceLevelAgreementResponseToServiceLevelAgreement: MapFunctio
description: source.description,
enabled: source.enabled,
trigger: this.map('AutomationTriggerResponse', source.trigger, 'AutomationTrigger'),
labels: source.labels,
type: source.type,
severity: source.severity,
created: this.map('string', source.created, 'Date'),
updated: this.map('string', source.updated, 'Date'),
Expand Down
41 changes: 33 additions & 8 deletions src/models/ServiceLevelAgreement.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { AutomationTrigger } from '@/automations'
import { createTuple, secondsToString } from '@/utilities'

export type ServiceLevelAgreementSeverity = 'minor' | 'low' | 'moderate' | 'high' | 'critical'

export enum ServiceLevelAgreementType {
TimeToCompletion = 'Time to Completion'
}
export const { values: ServiceLevelAgreementType, isValue: isServiceLevelAgreementType } = createTuple(['FrequencySla', 'LatenessSla', 'TimeToCompletionSla'])

export type ServiceLevelAgreementType = typeof ServiceLevelAgreementType[number]

export type ServiceLevelAgreementDisplayType = 'Frequency' | 'Lateness' | 'Time to Completion'

export interface IServiceLevelAgreement {
id: string,
name: string,
description: string,
enabled: boolean,
trigger: AutomationTrigger,
labels: Record<string, string>[],
severity: ServiceLevelAgreementSeverity,
type: ServiceLevelAgreementType,
created: Date,
updated: Date,
account: string,
Expand All @@ -32,8 +35,8 @@ export class ServiceLevelAgreement implements IServiceLevelAgreement {
public readonly description: string
public readonly enabled: boolean
public readonly trigger: AutomationTrigger
public readonly labels: Record<string, string>[]
public readonly severity: ServiceLevelAgreementSeverity
public readonly type: ServiceLevelAgreementType
public readonly created: Date
public readonly updated: Date
public readonly account: string
Expand All @@ -51,20 +54,42 @@ export class ServiceLevelAgreement implements IServiceLevelAgreement {
this.description = serviceLevelAgreement.description
this.enabled = serviceLevelAgreement.enabled
this.trigger = serviceLevelAgreement.trigger
this.labels = serviceLevelAgreement.labels
this.created = serviceLevelAgreement.created
this.updated = serviceLevelAgreement.updated
this.account = serviceLevelAgreement.account
this.workspace = serviceLevelAgreement.workspace
this.actor = serviceLevelAgreement.actor
this.severity = serviceLevelAgreement.severity
this.type = serviceLevelAgreement.type
}

public durationInSeconds(): number {
return this.trigger.within
}

public getSlaType(): string {
return ServiceLevelAgreementType.TimeToCompletion
public getSlaDefinitionKeyValuePairs(): { key: string, value: unknown }[] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is happening because we don't preserve the full state of what a user asked for in the SLA object on the backend. We turn the SLA into an automation and stick some labels on it in the db to preserve the minimal SLA state we need (severity, type, etc) but we don't have the properties exposed in the OSS client. Example:

class FrequencySla:
    stale_after: timedelta
    
 flow.deploy(_sla=FrequencySla(severity="minor", stale_after=timedelta(hours=1)))

We store automation.labels = {"prefect.sla.severity": "minor", "prefect.sla.type": "FrequencySla"} in the db. So I'm "re-assembling" the interface we provided to the user at deploy time.

switch (this.type) {
case 'FrequencySla':
return [{ key: 'Stale After', value: secondsToString(this.trigger.within) }]
case 'LatenessSla':
return [{ key: 'Within', value: secondsToString(this.trigger.within) }]
case 'TimeToCompletionSla':
return [{ key: 'Duration', value: secondsToString(this.trigger.within) }]
default:
return []
}
}

public getDisplaySlaType(): ServiceLevelAgreementDisplayType {
switch (this.type) {
case 'FrequencySla':
return 'Frequency'
case 'LatenessSla':
return 'Lateness'
case 'TimeToCompletionSla':
return 'Time to Completion'
default:
return 'Time to Completion'
}
}
}
4 changes: 2 additions & 2 deletions src/models/api/ServiceLevelAgreementResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AutomationActionResponse } from '@/automations/types/api/actions'
import { AutomationTriggerResponse } from '@/automations/types/api/triggers'
import { ServiceLevelAgreementSeverity } from '@/models/ServiceLevelAgreement'
import { ServiceLevelAgreementSeverity, ServiceLevelAgreementType } from '@/models/ServiceLevelAgreement'


export type ServiceLevelAgreementResponse = {
Expand All @@ -9,7 +9,7 @@ export type ServiceLevelAgreementResponse = {
enabled: boolean,
trigger: AutomationTriggerResponse,
actions_on_resolve: AutomationActionResponse[],
labels: Record<string, string>[],
type: ServiceLevelAgreementType,
severity: ServiceLevelAgreementSeverity,
id: string,
created: string,
Expand Down