Skip to content

Commit

Permalink
temporarily add additional log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
petersutter committed Dec 11, 2024
1 parent 21759f6 commit 89d71ff
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions frontend/src/composables/useApi/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { useAppStore } from '@/store/app'
import { fetchWrapper } from './fetch'

async function request (method, url, data) {
console.log('#before fetchWrapper', url) // eslint-disable-line no-console
const response = await fetchWrapper(url, { method, body: data })
console.log('#after fetchWrapper', url) // eslint-disable-line no-console
const { headers } = response
if (headers.warning) {
const appStore = useAppStore()
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/composables/useApi/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export function fetchWrapper (url, { method = 'GET', cache = 'no-cache', headers
})
for (const { requestFulfilled, requestRejected } of interceptors) {
if (requestFulfilled || requestRejected) {
console.log('# fetchWrapper Request interceptor', requestFulfilled, requestRejected) // eslint-disable-line no-console
promise = promise.then(args => requestFulfilled(...args), requestRejected)
} else {
console.log('# fetchWrapper No request interceptor') // eslint-disable-line no-console
}
}
promise = promise.then(args => {
Expand All @@ -51,28 +54,40 @@ export function fetchWrapper (url, { method = 'GET', cache = 'no-cache', headers
} catch (err) {
args[0] = new URL(args[0], window.location.origin)
}
console.log('# fetchWrapper Request args:', JSON.stringify(args)) // eslint-disable-line no-console
const request = new Request(...args)
console.log('# fetchWrapper after Request args:', JSON.stringify(args)) // eslint-disable-line no-console
return fetch(request).then(fulfilledFn(request), rejectedFn(request))
})
console.log('# fetchWrapper interceptors', interceptors) // eslint-disable-line no-console
for (const { responseFulfilled, responseRejected } of interceptors) {
if (responseFulfilled || responseRejected) {
console.log('# fetchWrapper Response interceptor', responseFulfilled, responseRejected) // eslint-disable-line no-console
promise = promise.then(responseFulfilled, responseRejected)
} else {
console.log('# fetchWrapper No response interceptor') // eslint-disable-line no-console
}
}
console.log('# fetchWrapper return') // eslint-disable-line no-console
return promise
}

function rejectedFn (request) {
console.log('# rejectedFn request:', JSON.stringify(request)) // eslint-disable-line no-console
return error => {
console.log('# rejectedFn error:', error) // eslint-disable-line no-console
Object.defineProperty(error, 'request', {
value: request,
})
console.log('# rejectedFn reject promise', error) // eslint-disable-line no-console
return Promise.reject(error)
}
}

function fulfilledFn (request) {
console.log('#fulfilledFn request:', JSON.stringify(request)) // eslint-disable-line no-console
return response => {
console.log('#define properties on response:', JSON.stringify(response)) // eslint-disable-line no-console
Object.defineProperties(response, {
request: {
value: request,
Expand All @@ -90,12 +105,15 @@ function fulfilledFn (request) {
let promise
const contentType = response.headers['content-type']
if (!contentType) {
console.log('# fulfilledFn Response header content-type is missing') // eslint-disable-line no-console
promise = Promise.resolve(response)
} else {
console.log('# fulfilledFn Response header content-type:', contentType) // eslint-disable-line no-console
promise = contentType.startsWith('application/json')
? response.json()
: response.text()
promise = promise.then(data => {
console.log('# fulfilledFn Response data:', JSON.stringify(data)) // eslint-disable-line no-console
Object.defineProperty(response, 'data', {
value: data,
})
Expand All @@ -104,11 +122,15 @@ function fulfilledFn (request) {
}

const status = response.status
console.log('# fulfilledFn response status:', status) // eslint-disable-line no-console
if (status >= 200 && status < 300) {
console.log('# fulfilledFn Response status is 2xx') // eslint-disable-line no-console
return promise
}

console.log('# fulfilledFn promise.then') // eslint-disable-line no-console
return promise.then(response => {
console.log('# fulfilledFn Response status is not 2xx - error', status) // eslint-disable-line no-console
if (status < 400) {
const responseType = status < 300
? 'informational'
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/composables/useOpenMFP.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useOpenMFP = createGlobalState((options = {}) => {
isInIframe = useIsInIframe(),
route = useRoute(),
} = options
logger.debug('#Initializing useOpenMFP')

const luigiContext = ref(null)

Expand All @@ -35,6 +36,7 @@ export const useOpenMFP = createGlobalState((options = {}) => {
LuigiClient.addContextUpdateListener(context => setLuigiContext(context))
const pathname = toRef(route, 'path')
watch(pathname, value => {
logger.debug('#Navigating to %s. Updating Luigi context', value)
if (value) {
LuigiClient.linkManager().fromVirtualTreeRoot().withoutSync().navigate(value)
}
Expand All @@ -44,6 +46,7 @@ export const useOpenMFP = createGlobalState((options = {}) => {
}

function setLuigiContext (value) {
logger.debug('#Setting Luigi context')
luigiContext.value = value
}

Expand All @@ -56,19 +59,22 @@ export const useOpenMFP = createGlobalState((options = {}) => {
if (luigiContext.value !== null) {
return luigiContext.value
}
logger.debug('#Waiting for the initialization of the Luigi Client')
const timeout = 3000
try {
await until(luigiContext).toBeTruthy({
timeout,
throwOnTimeout: true,
})
logger.debug('#Luigi context has been initialized and will be returned')
return luigiContext.value
} catch (err) {
logger.error('The initialization of the Luigi Client has timed out after %d milliseconds', timeout)
return null
}
}

logger.debug('#Initialized useOpenMFP')
return {
accountId,
luigiContext,
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/router/guards.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function createGlobalBeforeGuards () {
ensureKubeconfigLoaded(kubeconfigStore),
])
} catch (err) {
logger.error('#Error while loading common data:', err)
appStore.setRouterError(err)
}
}
Expand Down Expand Up @@ -137,7 +138,9 @@ export function createGlobalResolveGuards () {
const accountId = openMFP.accountId.value ?? to.query.accountId

const namespace = to.params.namespace ?? to.query.namespace
logger.debug('#before refreshRules, namespace: %s, accountId: %s', namespace, accountId)
await refreshRules(authzStore, namespace, accountId)
logger.debug('#after refreshRules, namespace: %s, accountId: %s', namespace, accountId)

if (namespace && namespace !== '_all' && !projectStore.namespaces.includes(namespace)) {
authzStore.$reset()
Expand Down Expand Up @@ -197,6 +200,7 @@ export function createGlobalResolveGuards () {
}
}
} catch (err) {
logger.error('#Error while loading data:', err)
appStore.setRouterError(err)
}
}
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/store/authz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from 'vue'

import { useApi } from '@/composables/useApi'
import { useLogger } from '@/composables/useLogger'

import { canI } from '@/utils'

Expand All @@ -26,6 +27,7 @@ export const useAuthzStore = defineStore('authz', () => {
const authnStore = useAuthnStore()
const configStore = useConfigStore()
const projectStore = useProjectStore()
const logger = useLogger()

const spec = ref(null)
const status = ref(null)
Expand Down Expand Up @@ -148,8 +150,15 @@ export const useAuthzStore = defineStore('authz', () => {
namespace,
accountId,
}
const response = await api.getSubjectRules(body)
status.value = response.data
try {
logger.debug('#Before getSubjectRules, namespace: %s, accountId: %s', namespace, accountId)
const response = await api.getSubjectRules(body)
logger.debug('#After getSubjectRules, namespace: %s, accountId: %s', namespace, accountId)
status.value = response.data
} catch (error) {
logger.error('#Error on selfSubjectRulesReview: %s', error.message)
status.value = null
}
}

async function fetchRules (namespace, accountId) {
Expand All @@ -166,7 +175,9 @@ export const useAuthzStore = defineStore('authz', () => {
spec.value?.namespace !== namespace ||
spec.value?.accountId !== accountId
) {
logger.debug('#Before getRules, namespace: %s, accountId: %s', namespace, accountId)
await getRules(namespace, accountId)
logger.debug('#After getRules, namespace: %s, accountId: %s', namespace, accountId)
spec.value = { namespace, accountId }
}
}
Expand Down

0 comments on commit 89d71ff

Please sign in to comment.