Skip to content

Commit

Permalink
fix: url detect
Browse files Browse the repository at this point in the history
  • Loading branch information
clement2026 committed Sep 4, 2024
1 parent b6d637c commit dc3c251
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go/internal/cmd/live-pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func maybeOpenURL(conf *config.LivePprofConfig) {

_ = browser.OpenURL(u.String())
} else {
logging.Sugar.Infow("will not open the browser", "conf.OpenBrowser", conf.OpenBrowser,
logging.Sugar.Debugw("will not open the browser", "conf.OpenBrowser", conf.OpenBrowser,
"IsRunningAsGoRun", goRun)
}
}
2 changes: 1 addition & 1 deletion go/internal/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func StartServeGrpc(gs *grpc.Server, conf *config.LivePprofConfig) {

//goland:noinspection HttpUrlsUsage
httpURL := "http://" + addr
logging.Sugar.Info("click to open:", httpURL)
logging.Sugar.Info("click to open: ", httpURL)

stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM)
Expand Down
2 changes: 2 additions & 0 deletions ts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ disable-telemetry:
@echo "Disabling Next.js telemetry"
npx next telemetry --disable

analyze:
ANALYZE=true pnpm build

clean:
@echo "Cleaning ts"
Expand Down
5 changes: 3 additions & 2 deletions ts/components/client/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { graphPrefsState } from '@/components/state/pref-state'
import { useIsDev } from '@/components/hooks/use-is-dev'

const blackHole = 'http://240.0.0.0:8300'

export const useBackendURL = (): string => {
const isDev = useIsDev()
const isSSR = useIsSSR()
Expand All @@ -21,9 +22,9 @@ export const useBackendURL = (): string => {
if (isDev) {
console.info('using', process.env.NEXT_PUBLIC_BACKEND_URL, 'as backend grpc endpoint')
return process.env.NEXT_PUBLIC_BACKEND_URL!
} else {
return `${window.location.protocol}//${window.location.hostname}:${window.location.port}`
}

return `${window.location.protocol}//${window.location.hostname}:${window.location.port}`
}

export const useMetricsClient = (): MetricsClient => {
Expand Down
4 changes: 2 additions & 2 deletions ts/components/hooks/use-is-dev.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client'

import { useEffect, useState } from 'react'
import { useLayoutEffect, useState } from 'react'

export const useIsDev = (): boolean => {
const [isDev, setIsDev] = useState(false)

useEffect(() => {
useLayoutEffect(() => {
setIsDev(process.env.NODE_ENV === 'development')
}, [])

Expand Down
2 changes: 2 additions & 0 deletions ts/components/state/pref-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type GraphPrefs = {
inputURL: string
retainedSamples: number
sampleInterval: number
topN: number
}

const newGraphPrefs = (): GraphPrefs => ({
Expand All @@ -46,6 +47,7 @@ const newGraphPrefs = (): GraphPrefs => ({
inputURL: `${8300}`, // get metrics from backend by default
retainedSamples: 120,
sampleInterval: 1000,
topN: 20,
})

const IS_CLIENT = typeof window !== 'undefined'
Expand Down
5 changes: 3 additions & 2 deletions ts/components/url-detect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React, { FC, useCallback, useEffect, useState } from 'react'
import { Chip } from '@nextui-org/chip'
import { Spinner } from '@nextui-org/spinner'
import { ClientReadableStream, RpcError } from 'grpc-web'
import { Icon } from '@iconify/react'
import { Spacer } from '@nextui-org/spacer'
Expand Down Expand Up @@ -60,7 +61,7 @@ export const UrlDetect: FC<UrlDetectProps> = ({ url }) => {
stream && stream.cancel()
clearTimeout(t)
}
}, [url, setResults])
}, [url, setResults, client])

return (
<div className={'flex flex-col gap-1'}>
Expand Down Expand Up @@ -96,7 +97,7 @@ export const UrlDetect: FC<UrlDetectProps> = ({ url }) => {
</AccordionItem>
))}
</Accordion>
{status === Status.loading && <Icon className="self-center w-8 h-8" icon="line-md:loading-twotone-loop" />}
{status === Status.loading && <Spinner />}
</div>
<div />
</div>
Expand Down
7 changes: 5 additions & 2 deletions ts/next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/** @type {import("next").NextConfig} */
const nextConfig = {}

module.exports = {
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
output: 'export',
}
})

module.exports = withBundleAnalyzer(nextConfig)

// if you want to serve WEB with node, use webpack instead
// const withTM = require("next-transpile-modules")(["echarts", "zrender"]);
Expand Down
1 change: 1 addition & 0 deletions ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@grpc/grpc-js": "^1.11.1",
"@next/bundle-analyzer": "^14.2.8",
"@nextui-org/accordion": "^2.0.38",
"@nextui-org/button": "2.0.37",
"@nextui-org/card": "^2.0.33",
Expand Down

0 comments on commit dc3c251

Please sign in to comment.