Skip to content

Commit

Permalink
use dedicated bucket for status reports
Browse files Browse the repository at this point in the history
  • Loading branch information
nl0 committed Sep 5, 2022
1 parent c7fe9b0 commit 5f5b19d
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 8 deletions.
7 changes: 3 additions & 4 deletions catalog/app/components/Preview/loaders/Html.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import * as AWS from 'utils/AWS'
import AsyncResult from 'utils/AsyncResult'
import { useIsInStack } from 'utils/BucketConfig'
import * as Config from 'utils/Config'
import { useStatusReportsBucket } from 'utils/StatusReportsBucket'
import useMemoEq from 'utils/useMemoEq'

import { PreviewData } from '../types'
Expand All @@ -23,9 +23,8 @@ function IFrameLoader({ handle, children }) {

export const Loader = function HtmlLoader({ handle, children }) {
const isInStack = useIsInStack()
const cfg = Config.useConfig()
const inStackOrSpecial = isInStack(handle.bucket) || handle.bucket === cfg.serviceBucket
return inStackOrSpecial ? (
const statusReportsBucket = useStatusReportsBucket()
return isInStack(handle.bucket) || handle.bucket === statusReportsBucket ? (
<IFrameLoader {...{ handle, children }} />
) : (
<Text.Loader {...{ handle, children }} />
Expand Down
12 changes: 12 additions & 0 deletions catalog/app/model/graphql/schema.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3136,6 +3136,18 @@ export default {
},
],
},
{
name: 'reportsBucket',
type: {
kind: 'NON_NULL',
ofType: {
kind: 'SCALAR',
name: 'String',
ofType: null,
},
},
args: [],
},
],
interfaces: [],
},
Expand Down
1 change: 1 addition & 0 deletions catalog/app/model/graphql/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ export interface Status {
readonly latestStats: TestStats
readonly stats: TestStatsTimeSeries
readonly reports: StatusReportList
readonly reportsBucket: Scalars['String']
}

export interface StatusstatsArgs {
Expand Down
6 changes: 4 additions & 2 deletions catalog/app/utils/AWS/S3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as redux from 'react-redux'
import * as authSelectors from 'containers/Auth/selectors'
import * as BucketConfig from 'utils/BucketConfig'
import { useConfig } from 'utils/Config'
import { useStatusReportsBucket } from 'utils/StatusReportsBucket'
import useConstant from 'utils/useConstant'
import useMemoEqLazy from 'utils/useMemoEqLazy'

Expand Down Expand Up @@ -39,6 +40,7 @@ function useSmartS3() {
const selectEndpoint = `${cfg.binaryApiGatewayEndpoint}/s3select/`
const isAuthenticated = useTracking(redux.useSelector(authSelectors.authenticated))
const isInStack = useTrackingFn(BucketConfig.useIsInStack())
const statusReportsBucket = useStatusReportsBucket()

return useConstant(() => {
class SmartS3 extends S3 {
Expand All @@ -52,8 +54,8 @@ function useSmartS3() {
// sign if operation is not bucket-specific
// (not sure if there are any such operations that can be used from the browser)
!bucket ||
(cfg.analyticsBucket && cfg.analyticsBucket === bucket) ||
(cfg.serviceBucket && cfg.serviceBucket === bucket) ||
cfg.analyticsBucket === bucket ||
statusReportsBucket === bucket ||
(cfg.mode !== 'OPEN' && isInStack(bucket))
) {
return 'signed'
Expand Down
6 changes: 4 additions & 2 deletions catalog/app/utils/AWS/Signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as redux from 'react-redux'
import * as authSelectors from 'containers/Auth/selectors'
import * as BucketConfig from 'utils/BucketConfig'
import * as Config from 'utils/Config'
import { useStatusReportsBucket } from 'utils/StatusReportsBucket'
import { handleToHttpsUri } from 'utils/s3paths'

import * as Credentials from './Credentials'
Expand All @@ -22,10 +23,11 @@ export function useS3Signer({ urlExpiration: exp, forceProxy = false } = {}) {
const authenticated = redux.useSelector(authSelectors.authenticated)
const cfg = Config.useConfig()
const isInStack = BucketConfig.useIsInStack()
const statusReportsBucket = useStatusReportsBucket()
const s3 = S3.use()
const inStackOrSpecial = React.useCallback(
(b) => isInStack(b) || cfg.analyticsBucket === b || cfg.serviceBucket === b,
[isInStack, cfg.analyticsBucket, cfg.serviceBucket],
(b) => isInStack(b) || cfg.analyticsBucket === b || statusReportsBucket === b,
[isInStack, cfg.analyticsBucket, statusReportsBucket],
)
return React.useCallback(
({ bucket, key, version }, opts) =>
Expand Down
57 changes: 57 additions & 0 deletions catalog/app/utils/StatusReportsBucket.generated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'
import * as Types from '../model/graphql/types.generated'

export type utils_StatusReportsBucketQueryVariables = Types.Exact<{
[key: string]: never
}>

export type utils_StatusReportsBucketQuery = { readonly __typename: 'Query' } & {
readonly status:
| ({ readonly __typename: 'Status' } & Pick<Types.Status, 'reportsBucket'>)
| { readonly __typename: 'Unavailable' }
}

export const utils_StatusReportsBucketDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: { kind: 'Name', value: 'utils_StatusReportsBucket' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'status' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'InlineFragment',
typeCondition: {
kind: 'NamedType',
name: { kind: 'Name', value: 'Status' },
},
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'reportsBucket' } },
],
},
},
],
},
},
],
},
},
],
} as unknown as DocumentNode<
utils_StatusReportsBucketQuery,
utils_StatusReportsBucketQueryVariables
>

export { utils_StatusReportsBucketDocument as default }
8 changes: 8 additions & 0 deletions catalog/app/utils/StatusReportsBucket.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query {
status {
__typename
... on Status {
reportsBucket
}
}
}
15 changes: 15 additions & 0 deletions catalog/app/utils/StatusReportsBucket.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import invariant from 'invariant'

import useQuery from 'utils/useQuery'

import STATUS_REPORTS_BUCKET_QUERY from './StatusReportsBucket.generated'

export function useStatusReportsBucket() {
const result = useQuery({
query: STATUS_REPORTS_BUCKET_QUERY,
suspend: true,
})
invariant(result.data, 'No data')
const { status } = result.data
return status.__typename === 'Status' ? status.reportsBucket : null
}
1 change: 1 addition & 0 deletions shared/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type Status {
latestStats: TestStats!
stats(window: Int = 30): TestStatsTimeSeries!
reports(filter: StatusReportListFilter): StatusReportList!
reportsBucket: String!
}

union StatusResult = Status | Unavailable
Expand Down

0 comments on commit 5f5b19d

Please sign in to comment.