Skip to content

Commit

Permalink
merging main
Browse files Browse the repository at this point in the history
  • Loading branch information
mboudreau committed Dec 15, 2021
2 parents 747f037 + 3ec82bc commit 51922a3
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 224 deletions.
71 changes: 64 additions & 7 deletions github-for-jira.sd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ links:
source:
url: git@bitbucket.org:atlassian/github-jira-integration.git

cleanup: true
cleanup: false

#serviceProxy:
# enabled: true
Expand Down Expand Up @@ -203,8 +203,55 @@ workers:
instance: t2.small
min: 1
max: 5
#TODO Replace with queue size metrics when we switch to SQS
metrics: *CpuMemScalingRules
metrics: &CpuMemAndQueuesScalingRules
complexScalingRule:
EvaluationPeriods: 3
Threshold:
Lower: 30
Upper: 80
Metrics:
- Expression: "MAX([cpuUsage, memoryUsage, (pushQueueMessages/250)*100, (backfillQueueMessages/80)*100])"
Id: "combinedCpuRamAndQueues"
Label: "Scaling based on Queue Sizes and CPU and Memory consumption"
- MetricStat:
Metric:
# Dimensions can be ignored here due to defaulting
MetricName: CPUUtilization
Namespace: AWS/EC2
Period: 60
Stat: Maximum
Id: cpuUsage
ReturnData: false
- MetricStat:
Metric:
# Dimensions can be ignored here due to defaulting
MetricName: MemoryUtilization
Namespace: System/Linux
Period: 60
Stat: Maximum
Id: memoryUsage
ReturnData: false
- MetricStat:
Metric:
MetricName: ApproximateNumberOfMessagesVisible
Namespace: AWS/SQS
Dimensions:
- LogicalQueueName: 'push'
Period: 60
Stat: Maximum
Id: pushQueueMessages
ReturnData: false
- MetricStat:
Metric:
MetricName: ApproximateNumberOfMessagesVisible
Namespace: AWS/SQS
Dimensions:
- LogicalQueueName: 'backfill'
Period: 60
Stat: Maximum
Id: backfillQueueMessages
ReturnData: false


environmentOverrides:
ddev:
Expand All @@ -218,7 +265,6 @@ environmentOverrides:
# - 5005:5005 # remote debugging port (has to be 5005 because that is hard coded into Micros)
# links:
# remoteDebug: true

config:
environmentVariables:
APP_URL: https://github-for-jira.dev.services.atlassian.com
Expand All @@ -240,7 +286,7 @@ environmentOverrides:
instance: t2.small
min: 1
max: 5
metrics: *CpuMemScalingRules
metrics: *CpuMemAndQueuesScalingRules
alarms:
overrides:
LatencyHigh: null
Expand Down Expand Up @@ -331,7 +377,7 @@ environmentOverrides:
instance: t3.medium
min: 1
max: 5
metrics: *CpuMemScalingRules
metrics: *CpuMemAndQueuesScalingRules
resources:
- name: rds
type: dedicated-rds
Expand Down Expand Up @@ -376,7 +422,7 @@ environmentOverrides:
instance: c5.2xlarge
min: 3
max: 4 # keep in sync with PGBOUNCER_DEFAULT_POOL_SIZE
metrics: *CpuMemScalingRules
metrics: *CpuMemAndQueuesScalingRules
alarms:
overrides:
LatencyHigh: null
Expand Down Expand Up @@ -410,6 +456,17 @@ environmentOverrides:
name: cache
attributes:
size: 5000
alarms:
AlarmOnNumConnections:
MetricName: CurrConnections
Description: "The number of client connections is too high. Please follow the runbook: https://hello.atlassian.net/wiki/spaces/PF/pages/1453195358/HOWTO+Investigate+Redis+Issues"
Threshold: 10000
EvaluationPeriods: 3
Period: 120
Priority: Low
ComparisonOperator: GreaterThanThreshold
Statistic: Maximum
Unit: Count

- name: database
type: postgres-db
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

9 changes: 3 additions & 6 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,9 @@ router.use(
}
);

router.get(
"/",
(_: Request, res: Response): void => {
res.send({});
}
);
router.get("/", (_: Request, res: Response): void => {
res.send({});
});

router.get(
"/:installationId/:jiraHost/repoSyncState.json",
Expand Down
6 changes: 0 additions & 6 deletions src/config/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ const launchdarklyClient = LaunchDarkly.init(envVars.LAUNCHDARKLY_KEY || "", {

export enum BooleanFlags {
MAINTENANCE_MODE = "maintenance-mode",
EXPOSE_QUEUE_METRICS = "expose-queue-metrics",
PROCESS_PUSHES_IMMEDIATELY = "process-pushes-immediately",
SIMPLER_PROCESSOR = "simpler-processor",
NEW_GITHUB_ERROR_PAGE = "new-git-hub-error-page",
NEW_BACKFILL_PROCESS_ENABLED = "new-backfill-process-enabled",
// When cleaning up the SEND_PUSH_TO_SQS feature flag, please also clean up the PRIORITIZE_PUSHES
// feature flag, because it doesn't make sense with SQS any more.
SEND_PUSH_TO_SQS = "send-push-events-to-sqs",
PRIORITIZE_PUSHES = "prioritize-pushes",
USE_NEW_GITHUB_CLIENT__FOR_PR = "git-hub-client-for-pullrequests",
NEW_REPO_SYNC_STATE = "new-repo-sync-state",
SUPPORT_BRANCH_AND_MERGE_WORKFLOWS_FOR_DEPLOYMENTS = "support-branch-and-merge-workflows-for-deployments",
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/get-github-setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response } from "express";
import { getGitHubConfigurationUrl, getJiraMarketplaceUrl } from "../util/getUrl";
import { getJiraAppUrl, getJiraMarketplaceUrl } from "../util/get-url";

/*
Handles redirects for both the installation flow from Jira and
Expand All @@ -13,7 +13,7 @@ export default async (req: Request, res: Response): Promise<void> => {
req.log.info("Received get github setup page request");
const { jiraHost } = res.locals;
if (req.headers.referer && jiraHost) {
return res.redirect(getGitHubConfigurationUrl(jiraHost));
return res.redirect(getJiraAppUrl(jiraHost));
}
const marketplaceUrl = jiraHost ? getJiraMarketplaceUrl(jiraHost) : undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/post-github-setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import { validJiraDomains } from "./validations";
import { Request, Response } from "express";
import { getJiraMarketplaceUrl } from "../util/getUrl";
import { getJiraMarketplaceUrl } from "../util/get-url";

interface SetupPagePayload {
error: string;
Expand Down
30 changes: 4 additions & 26 deletions src/github/push.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { createJobData, enqueuePush, processPush } from "../transforms/push";
import { enqueuePush } from "../transforms/push";
import issueKeyParser from "jira-issue-key-parser";
import { Context } from "probot/lib/context";
import { booleanFlag, BooleanFlags } from "../config/feature-flags";
import { getCurrentTime } from '../util/webhooks';
import { getCurrentTime } from "../util/webhooks";
import _ from "lodash";
import GitHubClient from "./client/github-client";

export default async (context: Context, jiraClient): Promise<void> => {
const webhookReceived = getCurrentTime();
Expand Down Expand Up @@ -36,27 +34,7 @@ export default async (context: Context, jiraClient): Promise<void> => {
return;
}

// If there's less than 20 commits (the number of commits the github API returns per call), just process it immediately
if(payload.commits?.length < 20 && await booleanFlag(BooleanFlags.PROCESS_PUSHES_IMMEDIATELY, true, jiraClient.baseURL)) {
context.log.info("Processing push straight away");
// TODO: this path is not used, opportunistically adding this line to make TypeScript happy without much testing
const githubNew = new GitHubClient(payload.installation?.id, context.log);
await processPush(context.github, githubNew, createJobData(payload, jiraClient.baseURL), context.log);
return;
}
context.log("Enqueueing push event");
await enqueuePush(payload, jiraClient.baseURL);

// Since a push event can have any number of commits
// and we have to process each one individually to get the
// data we need for Jira, send this to a background job
// so we can close the http connection as soon as the jobs
// are in the queue. Set as priority 1 to get this done before any other sync.
const prioritize = await booleanFlag(BooleanFlags.PRIORITIZE_PUSHES, true);

if (prioritize) {
context.log("Enqueueing push event (prioritized)");
await enqueuePush(payload, jiraClient.baseURL, { priority: 1 });
} else {
context.log("Enqueueing push event (not prioritized)");
await enqueuePush(payload, jiraClient.baseURL);
}
};
3 changes: 1 addition & 2 deletions src/models/reposyncstate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Sequelize, { CountOptions, Op } from "sequelize";
import Sequelize, { CountOptions, DestroyOptions, FindOptions, Op } from "sequelize";
import Subscription, { Repositories, RepositoryData, RepoSyncStateObject, TaskStatus } from "./subscription";
import { DestroyOptions, FindOptions } from "sequelize/types/lib/model";
import _ from "lodash";

export default class RepoSyncState extends Sequelize.Model {
Expand Down
12 changes: 3 additions & 9 deletions src/transforms/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import getJiraClient from "../jira/client";
import issueKeyParser from "jira-issue-key-parser";
import enhanceOctokit from "../config/enhance-octokit";
import {Application, GitHubAPI} from "probot";
import {Job, JobOptions} from "bull";
import {Job} from "bull";
import {getJiraAuthor} from "../util/jira";
import {emitWebhookProcessedMetrics} from "../util/webhooks";
import {JiraCommit} from "../interfaces/jira";
import _ from "lodash";
import {queues} from "../worker/queues";
import {LoggerWithTarget} from "probot/lib/wrap-logger";
import {booleanFlag, BooleanFlags, isBlocked} from "../config/feature-flags";
import sqsQueues from "../sqs/queues";
Expand Down Expand Up @@ -82,14 +81,9 @@ export const createJobData = (payload, jiraHost: string) : PushQueueMessagePaylo

export async function enqueuePush(
payload: unknown,
jiraHost: string,
options?: JobOptions
jiraHost: string
) {
if(await booleanFlag(BooleanFlags.SEND_PUSH_TO_SQS, false, jiraHost)) {
return sqsQueues.push.sendMessage(createJobData(payload, jiraHost));
} else {
return queues.push.add(createJobData(payload, jiraHost), options);
}
return sqsQueues.push.sendMessage(createJobData(payload, jiraHost));
}

export function processPushJob(app: Application) {
Expand Down
7 changes: 7 additions & 0 deletions src/util/get-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import envVars from "../config/env";

export const getJiraAppUrl = (jiraHost: string): string =>
jiraHost?.length ? `${jiraHost}/plugins/servlet/ac/com.github.integration.${envVars.INSTANCE_NAME}/github-post-install-page` : "";

export const getJiraMarketplaceUrl = (jiraHost: string): string =>
jiraHost?.length ? `${jiraHost}/plugins/servlet/ac/com.atlassian.jira.emcee/discover#!/discover/app/com.github.integration.production` : "";
9 changes: 0 additions & 9 deletions src/util/getUrl.ts

This file was deleted.

Loading

0 comments on commit 51922a3

Please sign in to comment.