mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-25 01:31:19 +00:00
Compare commits
3 Commits
perf/web-i
...
fix/antd-l
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb201f504a | ||
|
|
3a0e31c4d5 | ||
|
|
343510f0bc |
3
frontend/.gitignore
vendored
3
frontend/.gitignore
vendored
@@ -1,7 +1,4 @@
|
||||
|
||||
# Vite copies public/ unhashed, and the Go server caches /assets/ as immutable
|
||||
/public/assets/
|
||||
|
||||
# Sentry Config File
|
||||
.env.sentry-build-plugin
|
||||
.qodo
|
||||
|
||||
@@ -338,6 +338,11 @@
|
||||
"importNames": ["patchDashboardV2", "usePatchDashboardV2"],
|
||||
"message": "[dashboard-v2] Don't call patchDashboardV2/usePatchDashboardV2 directly — use useOptimisticPatch().patchAsync so spec edits update the react-query cache optimistically and reconcile on settle."
|
||||
},
|
||||
{
|
||||
"name": "antd/lib",
|
||||
"allowTypeImports": true,
|
||||
"message": "[bundle] antd/lib is the CommonJS root and bundles every antd component. Import from 'antd' instead."
|
||||
},
|
||||
{
|
||||
"name": "motion/react-client",
|
||||
"message": "[motion] motion/react-client is for React Server Components only. Use 'motion/react' instead — it provides the same exports and works correctly in client-side SPAs."
|
||||
|
||||
@@ -2,8 +2,7 @@ import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react';
|
||||
import { useAppNavigate } from 'lib/router/useAppNavigate';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { Select, Skeleton } from 'antd';
|
||||
import { SelectProps } from 'antd/lib';
|
||||
import { Select, SelectProps, Skeleton } from 'antd';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
import { useListAccounts } from 'api/generated/services/cloudintegration';
|
||||
import cx from 'classnames';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { Modal } from 'antd/lib';
|
||||
import { Modal } from 'antd';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
import { useDisconnectAccount } from 'api/generated/services/cloudintegration';
|
||||
import { CloudintegrationtypesGCPConnectionMethodDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
|
||||
@@ -7,8 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react';
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import { Form } from 'antd';
|
||||
import { FormInstance } from 'antd/lib';
|
||||
import { Form, FormInstance } from 'antd';
|
||||
import { useUpdateAccount } from 'api/generated/services/cloudintegration';
|
||||
import { CloudAccount } from 'container/Integrations/CloudIntegration/AmazonWebServices/types';
|
||||
import { INTEGRATION_TYPES } from 'container/Integrations/constants';
|
||||
|
||||
@@ -7,8 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react';
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import { Form } from 'antd';
|
||||
import { FormInstance } from 'antd/lib';
|
||||
import { Form, FormInstance } from 'antd';
|
||||
import { useUpdateAccount } from 'api/generated/services/cloudintegration';
|
||||
import { INTEGRATION_TYPES } from 'container/Integrations/constants';
|
||||
import { CloudAccount } from 'container/Integrations/types';
|
||||
|
||||
@@ -7,8 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react';
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import { Form } from 'antd';
|
||||
import { FormInstance } from 'antd/lib';
|
||||
import { Form, FormInstance } from 'antd';
|
||||
import { useUpdateAccount } from 'api/generated/services/cloudintegration';
|
||||
import { INTEGRATION_TYPES } from 'container/Integrations/constants';
|
||||
import { CloudAccount } from 'container/Integrations/types';
|
||||
|
||||
@@ -23,7 +23,10 @@ import {
|
||||
updateTaggedAccount,
|
||||
} from './CloudIntegration.stories.mocks';
|
||||
import {
|
||||
openAccountSelect,
|
||||
openAccountSettings,
|
||||
openConnectDialog,
|
||||
openDisconnectConfirm,
|
||||
openGcpRegionDropdown,
|
||||
} from './__story_mockdata__/cloudIntegration.play';
|
||||
|
||||
@@ -86,6 +89,17 @@ export const GoogleCloudPlatform: Story = {
|
||||
args: { provider: 'gcp' },
|
||||
};
|
||||
|
||||
/** The page while the account list is loading, the account picker a skeleton. */
|
||||
export const Loading: Story = {
|
||||
args: { dataState: 'loading' },
|
||||
};
|
||||
|
||||
/** The account picker open over two connected accounts. */
|
||||
export const AccountSelectOpen: Story = {
|
||||
args: { accounts: 2 },
|
||||
play: openAccountSelect,
|
||||
};
|
||||
|
||||
/** Every log attribute and metric a service collects, as the agent names them. */
|
||||
export const DataCollected: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
@@ -129,16 +143,27 @@ export const AzureConnectAccount: Story = {
|
||||
|
||||
/** The regions an already-connected account collects from. */
|
||||
export const EditAccount: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByText(
|
||||
/edit account/i,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await screen.findByRole('dialog', undefined, untilLoaded);
|
||||
},
|
||||
play: openAccountSettings,
|
||||
};
|
||||
|
||||
/** The resource groups an already-connected Azure subscription collects from. */
|
||||
export const AzureEditAccount: Story = {
|
||||
args: { provider: 'azure' },
|
||||
play: openAccountSettings,
|
||||
};
|
||||
|
||||
/** The projects an already-connected GCP account collects from. */
|
||||
export const GcpEditAccount: Story = {
|
||||
args: { provider: 'gcp' },
|
||||
play: openAccountSettings,
|
||||
};
|
||||
|
||||
/**
|
||||
* Disconnecting an account, which asks first and names what is removed from the
|
||||
* cloud account and what is left to delete by hand.
|
||||
*/
|
||||
export const DisconnectConfirm: Story = {
|
||||
play: openDisconnectConfirm,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type CloudIntegrationArgs,
|
||||
offersIntegrateNow,
|
||||
openConnectFlow,
|
||||
openEditAccount,
|
||||
untilLoaded,
|
||||
} from '../CloudIntegration.stories.mocks';
|
||||
|
||||
@@ -17,6 +18,16 @@ interface PlayContext {
|
||||
args: CloudIntegrationArgs;
|
||||
}
|
||||
|
||||
/** The hero shows the account picker and Edit Account only once accounts have answered. */
|
||||
const offersAccountActions = (args: CloudIntegrationArgs): boolean =>
|
||||
args.dataState === 'loaded' && args.accounts > 0;
|
||||
|
||||
const blurActiveElement = (): void => {
|
||||
if (document.activeElement instanceof HTMLElement) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
};
|
||||
|
||||
export const openConnectDialog = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
@@ -48,3 +59,49 @@ export const openGcpRegionDropdown = async ({
|
||||
);
|
||||
await screen.findByRole('listbox');
|
||||
};
|
||||
|
||||
export const openAccountSelect = async ({
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!offersAccountActions(args)) {
|
||||
return;
|
||||
}
|
||||
await userEvent.click(
|
||||
await screen.findByRole('combobox', { name: 'Cloud account' }, untilLoaded),
|
||||
);
|
||||
await screen.findByRole('listbox');
|
||||
};
|
||||
|
||||
export const openAccountSettings = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!offersAccountActions(args)) {
|
||||
return;
|
||||
}
|
||||
await openEditAccount(canvasElement);
|
||||
blurActiveElement();
|
||||
};
|
||||
|
||||
export const openDisconnectConfirm = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!offersAccountActions(args)) {
|
||||
return;
|
||||
}
|
||||
await openEditAccount(canvasElement);
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(
|
||||
'cloud-disconnect-account-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await screen.findByTestId(
|
||||
'cloud-remove-account-confirm',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
blurActiveElement();
|
||||
};
|
||||
|
||||
@@ -188,15 +188,6 @@ export default defineConfig(({ mode }): UserConfig => {
|
||||
sourcemap: true,
|
||||
outDir: 'build',
|
||||
cssMinify: 'esbuild',
|
||||
// The Go server caches /assets/ as immutable, so every file there must carry a content hash.
|
||||
assetsDir: 'assets',
|
||||
rolldownOptions: {
|
||||
output: {
|
||||
entryFileNames: 'assets/[name]-[hash].js',
|
||||
chunkFileNames: 'assets/[name]-[hash].js',
|
||||
assetFileNames: 'assets/[name]-[hash].[ext]',
|
||||
},
|
||||
},
|
||||
},
|
||||
server: {
|
||||
open: true,
|
||||
|
||||
@@ -6,9 +6,7 @@ import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/SigNoz/signoz/pkg/errors"
|
||||
"github.com/SigNoz/signoz/pkg/factory"
|
||||
@@ -18,11 +16,6 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const (
|
||||
assetsPathPrefix = "/assets/"
|
||||
immutableCacheControl = "public, max-age=31536000, immutable"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
config web.Config
|
||||
indexContents []byte
|
||||
@@ -85,10 +78,10 @@ func (provider *provider) AddToRouter(router *mux.Router) error {
|
||||
|
||||
func (provider *provider) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
// Join internally call path.Clean to prevent directory traversal
|
||||
filePath := filepath.Join(provider.config.Directory, req.URL.Path)
|
||||
path := filepath.Join(provider.config.Directory, req.URL.Path)
|
||||
|
||||
// check whether a file exists or is a directory at the given path
|
||||
fi, err := os.Stat(filePath)
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
// if the file doesn't exist, serve index.html
|
||||
if os.IsNotExist(err) {
|
||||
@@ -108,12 +101,6 @@ func (provider *provider) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// files under /assets/ are content-hashed, so their URL changes with their content.
|
||||
// A non-canonical URL can name a file outside /assets/ or get a redirect.
|
||||
if req.URL.Path == path.Clean(req.URL.Path) && strings.HasPrefix(req.URL.Path, assetsPathPrefix) {
|
||||
rw.Header().Set("Cache-Control", immutableCacheControl)
|
||||
}
|
||||
|
||||
// otherwise, use http.FileServer to serve the static file
|
||||
provider.fileHandler.ServeHTTP(rw, req)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -252,87 +251,3 @@ func TestServeStaticFilesUnchanged(t *testing.T) {
|
||||
|
||||
assert.Equal(t, string(expected), httpGet(t, base+"/assets/style.css"))
|
||||
}
|
||||
|
||||
func TestServeCacheControl(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
directory := t.TempDir()
|
||||
files := map[string]string{
|
||||
"index.html": "<html>index</html>",
|
||||
"assets/x.js": "console.log('x')",
|
||||
"assets/nested/y.css": "body{}",
|
||||
"assets-legacy/z.js": "console.log('z')",
|
||||
"favicon.ico": "icon",
|
||||
"css/uPlot.min.css": ".uplot{}",
|
||||
"locales/en/main.json": "{}",
|
||||
}
|
||||
for name, content := range files {
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(directory, filepath.Dir(name)), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(directory, name), []byte(content), 0o644))
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
basePath string
|
||||
path string
|
||||
expectedStatus int
|
||||
expectedBody string
|
||||
expectedCC string
|
||||
}{
|
||||
{name: "ExistingAsset_Immutable", path: "/assets/x.js", expectedBody: files["assets/x.js"], expectedCC: "public, max-age=31536000, immutable"},
|
||||
{name: "ExistingNestedAsset_Immutable", path: "/assets/nested/y.css", expectedBody: files["assets/nested/y.css"], expectedCC: "public, max-age=31536000, immutable"},
|
||||
{name: "MissingAsset_ServesIndex_NoCache", path: "/assets/missing-AAAA.js", expectedBody: files["index.html"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "AssetsDirectory_ServesIndex_NoCache", path: "/assets/nested/", expectedBody: files["index.html"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "Root_ServesIndex_NoCache", path: "/", expectedBody: files["index.html"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "UnknownRoute_ServesIndex_NoCache", path: "/does-not-exist", expectedBody: files["index.html"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "NonAssetFile_NoCache", path: "/favicon.ico", expectedBody: files["favicon.ico"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "NonAssetNestedFile_NoCache", path: "/css/uPlot.min.css", expectedBody: files["css/uPlot.min.css"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "LocaleFile_NoCache", path: "/locales/en/main.json", expectedBody: files["locales/en/main.json"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "AssetsPrefixLookalike_NoCache", path: "/assets-legacy/z.js", expectedBody: files["assets-legacy/z.js"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "BasePath_ExistingAsset_Immutable", basePath: "/signoz", path: "/assets/x.js", expectedBody: files["assets/x.js"], expectedCC: "public, max-age=31536000, immutable"},
|
||||
{name: "BasePath_MissingAsset_ServesIndex_NoCache", basePath: "/signoz", path: "/assets/missing-AAAA.js", expectedBody: files["index.html"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "BasePath_NonAssetFile_NoCache", basePath: "/signoz", path: "/favicon.ico", expectedBody: files["favicon.ico"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "AssetTrailingSlash_Redirects_NoCache", path: "/assets/x.js/", expectedStatus: http.StatusMovedPermanently, expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "EncodedDotDotOutOfAssets_NoCache", path: "/assets/%2e%2e/locales/en/main.json", expectedBody: files["locales/en/main.json"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
{name: "BasePath_Root_ServesIndex_NoCache", basePath: "/signoz", path: "/", expectedBody: files["index.html"], expectedCC: "max-age=0,no-cache,private,must-revalidate"},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
routerWeb, err := New(
|
||||
context.Background(),
|
||||
factorytest.NewSettings(),
|
||||
web.Config{Index: "index.html", Directory: directory},
|
||||
global.Config{ExternalURL: &url.URL{Path: testCase.basePath}},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
router := mux.NewRouter().UseEncodedPath()
|
||||
require.NoError(t, routerWeb.AddToRouter(router))
|
||||
|
||||
var handler http.Handler = router
|
||||
if testCase.basePath != "" {
|
||||
handler = http.StripPrefix(testCase.basePath, router)
|
||||
}
|
||||
|
||||
server := httptest.NewServer(handler)
|
||||
t.Cleanup(server.Close)
|
||||
|
||||
client := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
|
||||
res, err := client.Get(server.URL + testCase.basePath + testCase.path)
|
||||
require.NoError(t, err)
|
||||
defer func() { _ = res.Body.Close() }()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedStatus := testCase.expectedStatus
|
||||
if expectedStatus == 0 {
|
||||
expectedStatus = http.StatusOK
|
||||
}
|
||||
assert.Equal(t, expectedStatus, res.StatusCode)
|
||||
assert.Equal(t, testCase.expectedCC, res.Header.Get("Cache-Control"))
|
||||
assert.Equal(t, testCase.expectedBody, string(body))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user