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

feat: remove webhook exp flag #3168

Merged
merged 1 commit into from
Jul 13, 2023
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
4 changes: 1 addition & 3 deletions app/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ func (app *App) startup(ctx context.Context) error {
app.initStartup(ctx, "Startup.Slack", app.initSlack)
app.notificationManager.RegisterSender(notification.DestTypeUserEmail, "smtp", email.NewSender(ctx))
app.notificationManager.RegisterSender(notification.DestTypeUserWebhook, "webhook-user", webhook.NewSender(ctx))
if expflag.ContextHas(ctx, expflag.ChanWebhook) {
app.notificationManager.RegisterSender(notification.DestTypeChanWebhook, "webhook-channel", webhook.NewSender(ctx))
}
app.notificationManager.RegisterSender(notification.DestTypeChanWebhook, "webhook-channel", webhook.NewSender(ctx))

app.initStartup(ctx, "Startup.Engine", app.initEngine)
app.initStartup(ctx, "Startup.Auth", app.initAuth)
Expand Down
5 changes: 0 additions & 5 deletions escalation/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import (

"github.com/target/goalert/alert/alertlog"
"github.com/target/goalert/assignment"
"github.com/target/goalert/expflag"
"github.com/target/goalert/notification/slack"
"github.com/target/goalert/notificationchannel"
"github.com/target/goalert/permission"
"github.com/target/goalert/util"
"github.com/target/goalert/util/log"
"github.com/target/goalert/util/sqlutil"
"github.com/target/goalert/validation"
"github.com/target/goalert/validation/validate"

"github.com/google/uuid"
Expand Down Expand Up @@ -343,9 +341,6 @@ func (s *Store) AddStepTargetTx(ctx context.Context, tx *sql.Tx, stepID string,
}
}
if tgt.TargetType() == assignment.TargetTypeChanWebhook {
if !expflag.ContextHas(ctx, expflag.ChanWebhook) {
return validation.NewFieldError("type", "Webhook notification channels are not enabled")
}
var err error
tgt, err = s.chanWebhook(ctx, tx, tgt)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions expflag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import "sort"
type Flag string

const (
Example Flag = "example"
ChanWebhook Flag = "chan-webhook"
Example Flag = "example"
)

var desc = map[Flag]string{
Example: "An example experimental flag to demonstrate usage.",
ChanWebhook: "Enables webhooks as a notification channel type",
Example: "An example experimental flag to demonstrate usage.",
}

// AllFlags returns a slice of all experimental flags sorted by name.
Expand Down
5 changes: 0 additions & 5 deletions graphql2/graphqlapp/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/target/goalert/assignment"
"github.com/target/goalert/config"
"github.com/target/goalert/expflag"
"github.com/target/goalert/graphql2"
"github.com/target/goalert/notification/webhook"
"github.com/target/goalert/notificationchannel"
Expand Down Expand Up @@ -92,10 +91,6 @@ func (a *Mutation) SetScheduleOnCallNotificationRules(ctx context.Context, input
Value: ch.ID,
}
case assignment.TargetTypeChanWebhook:
if !expflag.ContextHas(ctx, expflag.ChanWebhook) {
return validation.NewFieldError(fmt.Sprintf("Rules[%d].Target.Type", i), "Webhook channels are not enabled.")
}

url, err := url.Parse(r.Target.ID)
if err != nil {
return validation.NewFieldError("Rules[%d].Target.ID", "Invalid URL format")
Expand Down
3 changes: 1 addition & 2 deletions test/smoke/webhookoncall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/target/goalert/expflag"
"github.com/target/goalert/test/smoke/harness"
)

Expand Down Expand Up @@ -74,7 +73,7 @@ func TestWebhookOnCallNotification(t *testing.T) {
({{uuid "sid"}}, '{"V1":{"OnCallNotificationRules": [{"ChannelID": {{uuidJSON "webhook"}}, "Time": "00:00" }]}}');
`

h := harness.NewHarnessWithFlags(t, sql, "webhook-notification-channel-type", expflag.FlagSet{expflag.ChanWebhook})
h := harness.NewHarness(t, sql, "webhook-notification-channel-type")
defer h.Close()

h.Trigger()
Expand Down
4 changes: 1 addition & 3 deletions web/src/app/escalation-policies/PolicyStepForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import { SlackBW as SlackIcon } from '../icons/components/Icons'
import { Config } from '../util/RequireConfig'
import NumberField from '../util/NumberField'
import { useExpFlag } from '../util/useExpFlag'

const useStyles = makeStyles({
badge: {
Expand All @@ -46,7 +45,6 @@ function PolicyStepForm(props) {
const [step, setStep] = useState(0)
const { disabled, value } = props
const classes = useStyles()
const hasChanWebhook = useExpFlag('chan-webhook')

function handleStepChange(stepChange) {
if (stepChange === step) {
Expand Down Expand Up @@ -225,7 +223,7 @@ function PolicyStepForm(props) {
/>
</StepContent>
</Step>
{cfg['Webhook.Enable'] && hasChanWebhook && (
{cfg['Webhook.Enable'] && (
<Step>
<StepButton
aria-expanded={(
Expand Down
4 changes: 1 addition & 3 deletions web/src/app/schedules/ScheduleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ScheduleOverrideDialog from './ScheduleOverrideDialog'
import { useIsWidthDown } from '../util/useWidth'
import { TempSchedValue, defaultTempSchedValue } from './temp-sched/sharedUtils'
import { Redirect } from 'wouter'
import { useExpFlag } from '../util/useExpFlag'
import { useScheduleTZ } from './useScheduleTZ'

const query = gql`
Expand Down Expand Up @@ -77,7 +76,6 @@ export default function ScheduleDetails({

const [slackEnabled] = useConfigValue('Slack.Enable')
const [webhookEnabled] = useConfigValue('Webhook.Enable')
const chanWebhookEnabled = useExpFlag('chan-webhook')

const [configTempSchedule, setConfigTempSchedule] =
useState<TempSchedValue | null>(null)
Expand Down Expand Up @@ -216,7 +214,7 @@ export default function ScheduleDetails({
},
].concat(
// only slack/webhook supported atm, so hide the link if disabled
slackEnabled || (webhookEnabled && chanWebhookEnabled)
slackEnabled || webhookEnabled
? [
{
label: 'On-Call Notifications',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import { ISOTimePicker } from '../../util/ISOPickers'
import { useConfigValue } from '../../util/RequireConfig'
import { Time } from '../../util/Time'
import { useExpFlag } from '../../util/useExpFlag'
import { useScheduleTZ } from '../useScheduleTZ'
import { EVERY_DAY, NO_DAY, RuleFieldError, Value } from './util'

Expand All @@ -46,7 +45,6 @@ export default function ScheduleOnCallNotificationsForm(
const classes = useStyles()
const [slackEnabled] = useConfigValue('Slack.Enable')
const [webhookEnabled] = useConfigValue('Webhook.Enable')
const webhookChannelEnabled = useExpFlag('chan-webhook')
const { zone } = useScheduleTZ(scheduleID)

const handleRuleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
Expand Down Expand Up @@ -88,18 +86,15 @@ export default function ScheduleOnCallNotificationsForm(
disabledMessage: 'Slack must be configured by an administrator',
disabled: !slackEnabled,
},
...(webhookChannelEnabled
? [
{
value: 'chanWebhook',
label: 'WEBHOOK',
disabledMessage: 'Webhooks must be enabled by an administrator',
disabled: !webhookEnabled,
},
]
: []),

{
value: 'chanWebhook',
label: 'WEBHOOK',
disabledMessage: 'Webhooks must be enabled by an administrator',
disabled: !webhookEnabled,
},
].sort(sortDisableableMenuItems),
[slackEnabled, webhookEnabled, webhookChannelEnabled],
[slackEnabled, webhookEnabled],
)

function renderTypeFields(type: TargetType): JSX.Element {
Expand Down
106 changes: 51 additions & 55 deletions web/src/cypress/e2e/escalationPolicySteps.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chance } from 'chance'
import { testScreen, testScreenWithFlags } from '../support/e2e'
import { testScreen } from '../support/e2e'
import { Schedule } from '../../schema'
import users from '../fixtures/users.json'

Expand Down Expand Up @@ -256,69 +256,65 @@ function testSteps(screen: ScreenFormat): void {

testScreen('Escalation Policy Steps', testSteps)

testScreenWithFlags(
'Webhook Support',
(screen: ScreenFormat) => {
let ep: EP
beforeEach(() => {
cy.createEP().then((e: EP) => {
ep = e
cy.visit(`/escalation-policies/${ep.id}`)
})
testScreen('Webhook Support', (screen: ScreenFormat) => {
let ep: EP
beforeEach(() => {
cy.createEP().then((e: EP) => {
ep = e
cy.visit(`/escalation-policies/${ep.id}`)
})
})

it('should add, click, and remove a webhook', () => {
cy.updateConfig({ Webhook: { Enable: true } })
cy.reload()
it('should add, click, and remove a webhook', () => {
cy.updateConfig({ Webhook: { Enable: true } })
cy.reload()

if (screen === 'mobile') {
cy.pageFab()
} else {
cy.get('button').contains('Create Step').click()
}
cy.dialogTitle('Create Step')
if (screen === 'mobile') {
cy.pageFab()
} else {
cy.get('button').contains('Create Step').click()
}
cy.dialogTitle('Create Step')

// expand webhook section
cy.get('button[data-cy="webhook-step"]').click()
// expand webhook section
cy.get('button[data-cy="webhook-step"]').click()

// add webhooks
cy.dialogForm({
webhooks: 'https://webhook.site',
})
cy.get('button[data-cy="add-webhook"]').click()
cy.dialogForm({
webhooks: 'https://example.com',
})
cy.get('button[data-cy="add-webhook"]').click()
cy.dialogFinish('Submit')
// add webhooks
cy.dialogForm({
webhooks: 'https://webhook.site',
})
cy.get('button[data-cy="add-webhook"]').click()
cy.dialogForm({
webhooks: 'https://example.com',
})
cy.get('button[data-cy="add-webhook"]').click()
cy.dialogFinish('Submit')

// verify data integrity
cy.get('body').should('contain', 'Notify the following:')
cy.get('body').should('contain', 'Step #1:')
cy.get('div[data-cy=webhook-chip]').should('contain', 'webhook.site')
cy.get('div[data-cy=webhook-chip]').should('contain', 'example.com')
// verify data integrity
cy.get('body').should('contain', 'Notify the following:')
cy.get('body').should('contain', 'Step #1:')
cy.get('div[data-cy=webhook-chip]').should('contain', 'webhook.site')
cy.get('div[data-cy=webhook-chip]').should('contain', 'example.com')

// open edit step dialog
cy.get('ul[data-cy=steps-list] :nth-child(1) li')
.find('button[data-cy=other-actions]')
.menu('Edit')
// open edit step dialog
cy.get('ul[data-cy=steps-list] :nth-child(1) li')
.find('button[data-cy=other-actions]')
.menu('Edit')

cy.dialogTitle('Edit Step')
cy.dialogTitle('Edit Step')

// expand webhook section
cy.get('button[data-cy="webhook-step"]').click()
// expand webhook section
cy.get('button[data-cy="webhook-step"]').click()

// delete webhook.site webhook
cy.get('[data-testid=CancelIcon]').first().click()
// delete webhook.site webhook
cy.get('[data-testid=CancelIcon]').first().click()

cy.dialogFinish('Submit')
cy.dialogFinish('Submit')

// verify data integrity
cy.get('body').should('contain', 'Notify the following:')
cy.get('body').should('contain', 'Step #1:')
cy.get('div[data-cy=webhook-chip]').should('contain', 'example.com')
cy.get('div[data-cy=webhook-chip]').should('not.contain', 'webhook.site')
})
},
['chan-webhook'],
)
// verify data integrity
cy.get('body').should('contain', 'Notify the following:')
cy.get('body').should('contain', 'Step #1:')
cy.get('div[data-cy=webhook-chip]').should('contain', 'example.com')
cy.get('div[data-cy=webhook-chip]').should('not.contain', 'webhook.site')
})
})
2 changes: 1 addition & 1 deletion web/src/expflag.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Code generated by expflag/cmd/tsgen DO NOT EDIT.

type ExpFlag = 'chan-webhook' | 'example'
type ExpFlag = 'example'