Merge branch 'develop' into 1249-service-tab

This commit is contained in:
Palash 2022-06-13 18:39:52 +05:30 committed by GitHub
commit c6d57a7a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 259 additions and 197 deletions

View File

@ -28,7 +28,7 @@ services:
volumes: volumes:
- ./data/alertmanager:/data - ./data/alertmanager:/data
command: command:
- --queryService.url=http://query-service:8080 - --queryService.url=http://query-service:8085
- --storage.path=/data - --storage.path=/data
depends_on: depends_on:
- query-service - query-service
@ -37,7 +37,7 @@ services:
condition: on-failure condition: on-failure
query-service: query-service:
image: signoz/query-service:0.8.0 image: signoz/query-service:0.8.1
command: ["-config=/root/config/prometheus.yml"] command: ["-config=/root/config/prometheus.yml"]
# ports: # ports:
# - "6060:6060" # pprof port # - "6060:6060" # pprof port
@ -65,7 +65,7 @@ services:
- clickhouse - clickhouse
frontend: frontend:
image: signoz/frontend:0.8.0 image: signoz/frontend:0.8.1
deploy: deploy:
restart_policy: restart_policy:
condition: on-failure condition: on-failure
@ -78,7 +78,7 @@ services:
- ../common/nginx-config.conf:/etc/nginx/conf.d/default.conf - ../common/nginx-config.conf:/etc/nginx/conf.d/default.conf
otel-collector: otel-collector:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-config.yaml"] command: ["--config=/etc/otel-collector-config.yaml"]
volumes: volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
@ -104,7 +104,7 @@ services:
- clickhouse - clickhouse
otel-collector-metrics: otel-collector-metrics:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-metrics-config.yaml"] command: ["--config=/etc/otel-collector-metrics-config.yaml"]
volumes: volumes:
- ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml - ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml

View File

@ -52,7 +52,7 @@ extensions:
health_check: {} health_check: {}
zpages: {} zpages: {}
exporters: exporters:
clickhouse: clickhousetraces:
datasource: tcp://clickhouse:9000/?database=signoz_traces datasource: tcp://clickhouse:9000/?database=signoz_traces
clickhousemetricswrite: clickhousemetricswrite:
endpoint: tcp://clickhouse:9000/?database=signoz_metrics endpoint: tcp://clickhouse:9000/?database=signoz_metrics
@ -66,7 +66,7 @@ service:
traces: traces:
receivers: [jaeger, otlp] receivers: [jaeger, otlp]
processors: [signozspanmetrics/prometheus, batch] processors: [signozspanmetrics/prometheus, batch]
exporters: [clickhouse] exporters: [clickhousetraces]
metrics: metrics:
receivers: [otlp, hostmetrics] receivers: [otlp, hostmetrics]
processors: [batch] processors: [batch]

View File

@ -30,14 +30,14 @@ services:
condition: service_healthy condition: service_healthy
restart: on-failure restart: on-failure
command: command:
- --queryService.url=http://query-service:8080 - --queryService.url=http://query-service:8085
- --storage.path=/data - --storage.path=/data
# Notes for Maintainers/Contributors who will change Line Numbers of Frontend & Query-Section. Please Update Line Numbers in `./scripts/commentLinesForSetup.sh` & `./CONTRIBUTING.md` # Notes for Maintainers/Contributors who will change Line Numbers of Frontend & Query-Section. Please Update Line Numbers in `./scripts/commentLinesForSetup.sh` & `./CONTRIBUTING.md`
query-service: query-service:
image: signoz/query-service:0.8.0 image: signoz/query-service:0.8.1
container_name: query-service container_name: query-service
command: ["-config=/root/config/prometheus.yml"] command: ["-config=/root/config/prometheus.yml"]
# ports: # ports:
@ -53,7 +53,6 @@ services:
- GODEBUG=netdns=go - GODEBUG=netdns=go
- TELEMETRY_ENABLED=true - TELEMETRY_ENABLED=true
- DEPLOYMENT_TYPE=docker-standalone-arm - DEPLOYMENT_TYPE=docker-standalone-arm
restart: on-failure restart: on-failure
healthcheck: healthcheck:
test: ["CMD", "wget", "--spider", "-q", "localhost:8080/api/v1/version"] test: ["CMD", "wget", "--spider", "-q", "localhost:8080/api/v1/version"]
@ -65,7 +64,7 @@ services:
condition: service_healthy condition: service_healthy
frontend: frontend:
image: signoz/frontend:0.8.0 image: signoz/frontend:0.8.1
container_name: frontend container_name: frontend
restart: on-failure restart: on-failure
depends_on: depends_on:
@ -77,7 +76,7 @@ services:
- ../common/nginx-config.conf:/etc/nginx/conf.d/default.conf - ../common/nginx-config.conf:/etc/nginx/conf.d/default.conf
otel-collector: otel-collector:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-config.yaml"] command: ["--config=/etc/otel-collector-config.yaml"]
volumes: volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
@ -98,7 +97,7 @@ services:
condition: service_healthy condition: service_healthy
otel-collector-metrics: otel-collector-metrics:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-metrics-config.yaml"] command: ["--config=/etc/otel-collector-metrics-config.yaml"]
volumes: volumes:
- ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml - ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml

View File

@ -30,13 +30,13 @@ services:
condition: service_healthy condition: service_healthy
restart: on-failure restart: on-failure
command: command:
- --queryService.url=http://query-service:8080 - --queryService.url=http://query-service:8085
- --storage.path=/data - --storage.path=/data
# Notes for Maintainers/Contributors who will change Line Numbers of Frontend & Query-Section. Please Update Line Numbers in `./scripts/commentLinesForSetup.sh` & `./CONTRIBUTING.md` # Notes for Maintainers/Contributors who will change Line Numbers of Frontend & Query-Section. Please Update Line Numbers in `./scripts/commentLinesForSetup.sh` & `./CONTRIBUTING.md`
query-service: query-service:
image: signoz/query-service:0.8.0 image: signoz/query-service:0.8.1
container_name: query-service container_name: query-service
command: ["-config=/root/config/prometheus.yml"] command: ["-config=/root/config/prometheus.yml"]
# ports: # ports:
@ -63,7 +63,7 @@ services:
condition: service_healthy condition: service_healthy
frontend: frontend:
image: signoz/frontend:0.8.0 image: signoz/frontend:0.8.1
container_name: frontend container_name: frontend
restart: on-failure restart: on-failure
depends_on: depends_on:
@ -75,7 +75,7 @@ services:
- ../common/nginx-config.conf:/etc/nginx/conf.d/default.conf - ../common/nginx-config.conf:/etc/nginx/conf.d/default.conf
otel-collector: otel-collector:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-config.yaml"] command: ["--config=/etc/otel-collector-config.yaml"]
volumes: volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
@ -96,7 +96,7 @@ services:
condition: service_healthy condition: service_healthy
otel-collector-metrics: otel-collector-metrics:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-metrics-config.yaml"] command: ["--config=/etc/otel-collector-metrics-config.yaml"]
volumes: volumes:
- ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml - ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml

View File

@ -52,7 +52,7 @@ extensions:
health_check: {} health_check: {}
zpages: {} zpages: {}
exporters: exporters:
clickhouse: clickhousetraces:
datasource: tcp://clickhouse:9000/?database=signoz_traces datasource: tcp://clickhouse:9000/?database=signoz_traces
clickhousemetricswrite: clickhousemetricswrite:
endpoint: tcp://clickhouse:9000/?database=signoz_metrics endpoint: tcp://clickhouse:9000/?database=signoz_metrics
@ -66,7 +66,7 @@ service:
traces: traces:
receivers: [jaeger, otlp] receivers: [jaeger, otlp]
processors: [signozspanmetrics/prometheus, batch] processors: [signozspanmetrics/prometheus, batch]
exporters: [clickhouse] exporters: [clickhousetraces]
metrics: metrics:
receivers: [otlp, hostmetrics] receivers: [otlp, hostmetrics]
processors: [batch] processors: [batch]

View File

@ -29,12 +29,15 @@ function GraphLayout({
const { role } = useSelector<AppState, AppReducer>((state) => state.app); const { role } = useSelector<AppState, AppReducer>((state) => state.app);
const { isDarkMode } = useSelector<AppState, AppReducer>((state) => state.app); const { isDarkMode } = useSelector<AppState, AppReducer>((state) => state.app);
const [saveLayout] = useComponentPermission(['save_layout'], role); const [saveLayoutPermission, addPanelPermission] = useComponentPermission(
['save_layout', 'add_panel'],
role,
);
return ( return (
<> <>
<ButtonContainer> <ButtonContainer>
{saveLayout && ( {saveLayoutPermission && (
<Button <Button
loading={saveLayoutState.loading} loading={saveLayoutState.loading}
onClick={(): Promise<void> => onLayoutSaveHandler(layouts)} onClick={(): Promise<void> => onLayoutSaveHandler(layouts)}
@ -45,24 +48,26 @@ function GraphLayout({
</Button> </Button>
)} )}
<Button {addPanelPermission && (
loading={addPanelLoading} <Button
disabled={addPanelLoading} loading={addPanelLoading}
onClick={onAddPanelHandler} disabled={addPanelLoading}
icon={<PlusOutlined />} onClick={onAddPanelHandler}
> icon={<PlusOutlined />}
Add Panel >
</Button> Add Panel
</Button>
)}
</ButtonContainer> </ButtonContainer>
<ReactGridLayout <ReactGridLayout
isResizable
cols={12} cols={12}
rowHeight={100} rowHeight={100}
autoSize autoSize
width={100} width={100}
isDraggable isDraggable={addPanelPermission}
isDroppable isDroppable={addPanelPermission}
isResizable={addPanelPermission}
useCSSTransforms useCSSTransforms
allowOverlap={false} allowOverlap={false}
onLayoutChange={onLayoutChangeHandler} onLayoutChange={onLayoutChangeHandler}

View File

@ -1,6 +1,7 @@
/* eslint-disable react/no-unstable-nested-components */ /* eslint-disable react/no-unstable-nested-components */
import { notification } from 'antd'; import { notification } from 'antd';
import updateDashboardApi from 'api/dashboard/update'; import updateDashboardApi from 'api/dashboard/update';
import useComponentPermission from 'hooks/useComponentPermission';
import React, { useCallback, useEffect, useState } from 'react'; import React, { useCallback, useEffect, useState } from 'react';
import { Layout } from 'react-grid-layout'; import { Layout } from 'react-grid-layout';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -15,6 +16,7 @@ import { AppState } from 'store/reducers';
import AppActions from 'types/actions'; import AppActions from 'types/actions';
import { UPDATE_DASHBOARD } from 'types/actions/dashboard'; import { UPDATE_DASHBOARD } from 'types/actions/dashboard';
import { Dashboard, Widgets } from 'types/api/dashboard/getAll'; import { Dashboard, Widgets } from 'types/api/dashboard/getAll';
import AppReducer from 'types/reducer/app';
import DashboardReducer from 'types/reducer/dashboards'; import DashboardReducer from 'types/reducer/dashboards';
import Graph from './Graph'; import Graph from './Graph';
@ -49,6 +51,9 @@ function GridGraph(props: Props): JSX.Element {
const { dashboards, isAddWidget } = useSelector<AppState, DashboardReducer>( const { dashboards, isAddWidget } = useSelector<AppState, DashboardReducer>(
(state) => state.dashboards, (state) => state.dashboards,
); );
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
const [saveLayoutPermission] = useComponentPermission(['save_layout'], role);
const [saveLayoutState, setSaveLayoutState] = useState<State>({ const [saveLayoutState, setSaveLayoutState] = useState<State>({
loading: false, loading: false,
error: false, error: false,
@ -109,31 +114,34 @@ function GridGraph(props: Props): JSX.Element {
loading: true, loading: true,
})); }));
const response = await updateDashboardApi({ // Save layout only when users has the has the permission to do so.
data: { if (saveLayoutPermission) {
title: data.title, const response = await updateDashboardApi({
description: data.description, data: {
name: data.name, title: data.title,
tags: data.tags, description: data.description,
widgets: data.widgets, name: data.name,
layout, tags: data.tags,
}, widgets: data.widgets,
uuid: selectedDashboard.uuid, layout,
}); },
if (response.statusCode === 200) { uuid: selectedDashboard.uuid,
setSaveLayoutState((state) => ({ });
...state, if (response.statusCode === 200) {
error: false, setSaveLayoutState((state) => ({
errorMessage: '', ...state,
loading: false, error: false,
})); errorMessage: '',
} else { loading: false,
setSaveLayoutState((state) => ({ }));
...state, } else {
error: true, setSaveLayoutState((state) => ({
errorMessage: response.error || 'Something went wrong', ...state,
loading: false, error: true,
})); errorMessage: response.error || 'Something went wrong',
loading: false,
}));
}
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -145,6 +153,7 @@ function GridGraph(props: Props): JSX.Element {
data.tags, data.tags,
data.title, data.title,
data.widgets, data.widgets,
saveLayoutPermission,
selectedDashboard.uuid, selectedDashboard.uuid,
], ],
); );

View File

@ -15,11 +15,19 @@ import ROUTES from 'constants/routes';
import SearchFilter from 'container/ListOfDashboard/SearchFilter'; import SearchFilter from 'container/ListOfDashboard/SearchFilter';
import useComponentPermission from 'hooks/useComponentPermission'; import useComponentPermission from 'hooks/useComponentPermission';
import history from 'lib/history'; import history from 'lib/history';
import React, { useCallback, useEffect, useMemo, useState } from 'react'; import React, {
Dispatch,
useCallback,
useEffect,
useMemo,
useState,
} from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { generatePath } from 'react-router-dom'; import { generatePath } from 'react-router-dom';
import { AppState } from 'store/reducers'; import { AppState } from 'store/reducers';
import AppActions from 'types/actions';
import { GET_ALL_DASHBOARD_SUCCESS } from 'types/actions/dashboard';
import { Dashboard } from 'types/api/dashboard/getAll'; import { Dashboard } from 'types/api/dashboard/getAll';
import AppReducer from 'types/reducer/app'; import AppReducer from 'types/reducer/app';
import DashboardReducer from 'types/reducer/dashboards'; import DashboardReducer from 'types/reducer/dashboards';
@ -36,6 +44,7 @@ function ListOfAllDashboard(): JSX.Element {
const { dashboards, loading } = useSelector<AppState, DashboardReducer>( const { dashboards, loading } = useSelector<AppState, DashboardReducer>(
(state) => state.dashboards, (state) => state.dashboards,
); );
const dispatch = useDispatch<Dispatch<AppActions>>();
const { role } = useSelector<AppState, AppReducer>((state) => state.app); const { role } = useSelector<AppState, AppReducer>((state) => state.app);
const [action, createNewDashboard, newDashboard] = useComponentPermission( const [action, createNewDashboard, newDashboard] = useComponentPermission(
@ -131,6 +140,10 @@ function ListOfAllDashboard(): JSX.Element {
}); });
if (response.statusCode === 200) { if (response.statusCode === 200) {
dispatch({
type: GET_ALL_DASHBOARD_SUCCESS,
payload: [],
});
history.push( history.push(
generatePath(ROUTES.DASHBOARD, { generatePath(ROUTES.DASHBOARD, {
dashboardId: response.payload.uuid, dashboardId: response.payload.uuid,
@ -151,7 +164,7 @@ function ListOfAllDashboard(): JSX.Element {
errorMessage: (error as AxiosError).toString() || 'Something went Wrong', errorMessage: (error as AxiosError).toString() || 'Something went Wrong',
}); });
} }
}, [newDashboardState, t]); }, [newDashboardState, t, dispatch]);
const getText = useCallback(() => { const getText = useCallback(() => {
if (!newDashboardState.error && !newDashboardState.loading) { if (!newDashboardState.error && !newDashboardState.loading) {

View File

@ -66,7 +66,7 @@ export const RedDot = styled.div`
background: #d32029; background: #d32029;
border-radius: 50%; border-radius: 50%;
margin-left: 1rem; margin-left: 0.5rem;
margin-top: 0.5rem; margin-top: 0.5rem;
`; `;

View File

@ -16,7 +16,8 @@ export type ComponentTypes =
| 'delete_widget' | 'delete_widget'
| 'new_dashboard' | 'new_dashboard'
| 'new_alert_action' | 'new_alert_action'
| 'edit_widget'; | 'edit_widget'
| 'add_panel';
export const componentPermission: Record<ComponentTypes, ROLES[]> = { export const componentPermission: Record<ComponentTypes, ROLES[]> = {
current_org_settings: ['ADMIN'], current_org_settings: ['ADMIN'],
@ -34,6 +35,7 @@ export const componentPermission: Record<ComponentTypes, ROLES[]> = {
new_dashboard: ['ADMIN', 'EDITOR'], new_dashboard: ['ADMIN', 'EDITOR'],
new_alert_action: ['ADMIN'], new_alert_action: ['ADMIN'],
edit_widget: ['ADMIN', 'EDITOR'], edit_widget: ['ADMIN', 'EDITOR'],
add_panel: ['ADMIN', 'EDITOR'],
}; };
export const routePermission: Record<keyof typeof ROUTES, ROLES[]> = { export const routePermission: Record<keyof typeof ROUTES, ROLES[]> = {
@ -47,7 +49,7 @@ export const routePermission: Record<keyof typeof ROUTES, ROLES[]> = {
APPLICATION: ['ADMIN', 'EDITOR', 'VIEWER'], APPLICATION: ['ADMIN', 'EDITOR', 'VIEWER'],
CHANNELS_EDIT: ['ADMIN'], CHANNELS_EDIT: ['ADMIN'],
CHANNELS_NEW: ['ADMIN'], CHANNELS_NEW: ['ADMIN'],
DASHBOARD: ['ADMIN', 'EDITOR', 'EDITOR'], DASHBOARD: ['ADMIN', 'EDITOR', 'VIEWER'],
DASHBOARD_WIDGET: ['ADMIN', 'EDITOR', 'VIEWER'], DASHBOARD_WIDGET: ['ADMIN', 'EDITOR', 'VIEWER'],
EDIT_ALERTS: ['ADMIN'], EDIT_ALERTS: ['ADMIN'],
ERROR_DETAIL: ['ADMIN', 'EDITOR', 'VIEWER'], ERROR_DETAIL: ['ADMIN', 'EDITOR', 'VIEWER'],

View File

@ -277,6 +277,11 @@ func AdminAccess(f func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
} }
} }
// RegisterPrivateRoutes registers routes for this handler on the given router
func (aH *APIHandler) RegisterPrivateRoutes(router *mux.Router) {
router.HandleFunc("/api/v1/channels", aH.listChannels).Methods(http.MethodGet)
}
// RegisterRoutes registers routes for this handler on the given router // RegisterRoutes registers routes for this handler on the given router
func (aH *APIHandler) RegisterRoutes(router *mux.Router) { func (aH *APIHandler) RegisterRoutes(router *mux.Router) {
router.HandleFunc("/api/v1/query_range", ViewAccess(aH.queryRangeMetrics)).Methods(http.MethodGet) router.HandleFunc("/api/v1/query_range", ViewAccess(aH.queryRangeMetrics)).Methods(http.MethodGet)

View File

@ -25,23 +25,24 @@ import (
) )
type ServerOptions struct { type ServerOptions struct {
HTTPHostPort string HTTPHostPort string
PrivateHostPort string
} }
// Server runs HTTP, Mux and a grpc server // Server runs HTTP, Mux and a grpc server
type Server struct { type Server struct {
// logger *zap.Logger // logger *zap.Logger
// querySvc *querysvc.QueryService
// queryOptions *QueryOptions
// tracer opentracing.Tracer // TODO make part of flags.Service // tracer opentracing.Tracer // TODO make part of flags.Service
serverOptions *ServerOptions serverOptions *ServerOptions
conn net.Listener
// grpcConn net.Listener // public http router
httpConn net.Listener httpConn net.Listener
// grpcServer *grpc.Server httpServer *http.Server
httpServer *http.Server
separatePorts bool // private http
privateConn net.Listener
privateHTTP *http.Server
unavailableChannel chan healthcheck.Status unavailableChannel chan healthcheck.Status
} }
@ -51,59 +52,20 @@ func (s Server) HealthCheckStatus() chan healthcheck.Status {
} }
// NewServer creates and initializes Server // NewServer creates and initializes Server
// func NewServer(logger *zap.Logger, querySvc *querysvc.QueryService, options *QueryOptions, tracer opentracing.Tracer) (*Server, error) {
func NewServer(serverOptions *ServerOptions) (*Server, error) { func NewServer(serverOptions *ServerOptions) (*Server, error) {
// _, httpPort, err := net.SplitHostPort(serverOptions.HTTPHostPort)
// if err != nil {
// return nil, err
// }
// _, grpcPort, err := net.SplitHostPort(options.GRPCHostPort)
// if err != nil {
// return nil, err
// }
// grpcServer, err := createGRPCServer(querySvc, options, logger, tracer)
// if err != nil {
// return nil, err
// }
if err := dao.InitDao("sqlite", constants.RELATIONAL_DATASOURCE_PATH); err != nil { if err := dao.InitDao("sqlite", constants.RELATIONAL_DATASOURCE_PATH); err != nil {
return nil, err return nil, err
} }
s := &Server{
// logger: logger,
// querySvc: querySvc,
// queryOptions: options,
// tracer: tracer,
// grpcServer: grpcServer,
serverOptions: serverOptions,
separatePorts: true,
// separatePorts: grpcPort != httpPort,
unavailableChannel: make(chan healthcheck.Status),
}
httpServer, err := s.createHTTPServer()
if err != nil {
return nil, err
}
s.httpServer = httpServer
return s, nil
}
func (s *Server) createHTTPServer() (*http.Server, error) {
localDB, err := dashboards.InitDB(constants.RELATIONAL_DATASOURCE_PATH) localDB, err := dashboards.InitDB(constants.RELATIONAL_DATASOURCE_PATH)
if err != nil { if err != nil {
return nil, err return nil, err
} }
localDB.SetMaxOpenConns(10) localDB.SetMaxOpenConns(10)
var reader Reader var reader Reader
storage := os.Getenv("STORAGE") storage := os.Getenv("STORAGE")
if storage == "clickhouse" { if storage == "clickhouse" {
zap.S().Info("Using ClickHouse as datastore ...") zap.S().Info("Using ClickHouse as datastore ...")
@ -119,24 +81,75 @@ func (s *Server) createHTTPServer() (*http.Server, error) {
return nil, err return nil, err
} }
s := &Server{
// logger: logger,
// tracer: tracer,
serverOptions: serverOptions,
unavailableChannel: make(chan healthcheck.Status),
}
httpServer, err := s.createPublicServer(apiHandler)
if err != nil {
return nil, err
}
s.httpServer = httpServer
privateServer, err := s.createPrivateServer(apiHandler)
if err != nil {
return nil, err
}
s.privateHTTP = privateServer
return s, nil
}
func (s *Server) createPrivateServer(api *APIHandler) (*http.Server, error) {
r := NewRouter()
r.Use(setTimeoutMiddleware)
r.Use(s.analyticsMiddleware)
r.Use(loggingMiddlewarePrivate)
api.RegisterPrivateRoutes(r)
c := cors.New(cors.Options{
//todo(amol): find out a way to add exact domain or
// ip here for alert manager
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "DELETE", "POST", "PUT"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"},
})
handler := c.Handler(r)
handler = handlers.CompressHandler(handler)
return &http.Server{
Handler: handler,
}, nil
}
func (s *Server) createPublicServer(api *APIHandler) (*http.Server, error) {
r := NewRouter() r := NewRouter()
r.Use(setTimeoutMiddleware) r.Use(setTimeoutMiddleware)
r.Use(s.analyticsMiddleware) r.Use(s.analyticsMiddleware)
r.Use(loggingMiddleware) r.Use(loggingMiddleware)
apiHandler.RegisterRoutes(r) api.RegisterRoutes(r)
apiHandler.RegisterMetricsRoutes(r) api.RegisterMetricsRoutes(r)
c := cors.New(cors.Options{ c := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, AllowedOrigins: []string{"*"},
// AllowCredentials: true,
AllowedMethods: []string{"GET", "DELETE", "POST", "PUT"}, AllowedMethods: []string{"GET", "DELETE", "POST", "PUT"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"},
}) })
handler := c.Handler(r) handler := c.Handler(r)
// var handler http.Handler = r
handler = handlers.CompressHandler(handler) handler = handlers.CompressHandler(handler)
@ -145,6 +158,7 @@ func (s *Server) createHTTPServer() (*http.Server, error) {
}, nil }, nil
} }
// loggingMiddleware is used for logging public api calls
func loggingMiddleware(next http.Handler) http.Handler { func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
route := mux.CurrentRoute(r) route := mux.CurrentRoute(r)
@ -155,6 +169,18 @@ func loggingMiddleware(next http.Handler) http.Handler {
}) })
} }
// loggingMiddlewarePrivate is used for logging private api calls
// from internal services like alert manager
func loggingMiddlewarePrivate(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
route := mux.CurrentRoute(r)
path, _ := route.GetPathTemplate()
startTime := time.Now()
next.ServeHTTP(w, r)
zap.S().Info(path, "\tprivatePort: true", "\ttimeTaken: ", time.Now().Sub(startTime))
})
}
type loggingResponseWriter struct { type loggingResponseWriter struct {
http.ResponseWriter http.ResponseWriter
statusCode int statusCode int
@ -198,61 +224,42 @@ func setTimeoutMiddleware(next http.Handler) http.Handler {
}) })
} }
// initListener initialises listeners of the server // initListeners initialises listeners of the server
func (s *Server) initListener() (cmux.CMux, error) { func (s *Server) initListeners() error {
if s.separatePorts { // use separate ports and listeners each for gRPC and HTTP requests // listen on public port
var err error var err error
// s.grpcConn, err = net.Listen("tcp", s.queryOptions.GRPCHostPort) publicHostPort := s.serverOptions.HTTPHostPort
// if err != nil { if publicHostPort == "" {
// return nil, err return fmt.Errorf("constants.HTTPHostPort is required")
// }
s.httpConn, err = net.Listen("tcp", s.serverOptions.HTTPHostPort)
if err != nil {
return nil, err
}
zap.S().Info("Query server started ...")
return nil, nil
} }
// // old behavior using cmux s.httpConn, err = net.Listen("tcp", publicHostPort)
// conn, err := net.Listen("tcp", s.queryOptions.HostPort) if err != nil {
// if err != nil { return err
// return nil, err }
// }
// s.conn = conn
// var tcpPort int zap.S().Info(fmt.Sprintf("Query server started listening on %s...", s.serverOptions.HTTPHostPort))
// if port, err := netutils
// utils.GetPort(s.conn.Addr()); err == nil { // listen on private port to support internal services
// tcpPort = port privateHostPort := s.serverOptions.PrivateHostPort
// }
// zap.S().Info( if privateHostPort == "" {
// "Query server started", return fmt.Errorf("constants.PrivateHostPort is required")
// zap.Int("port", tcpPort), }
// zap.String("addr", s.queryOptions.HostPort))
// // cmux server acts as a reverse-proxy between HTTP and GRPC backends. s.privateConn, err = net.Listen("tcp", privateHostPort)
// cmuxServer := cmux.New(s.conn) if err != nil {
return err
// s.grpcConn = cmuxServer.MatchWithWriters( }
// cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"), zap.S().Info(fmt.Sprintf("Query server started listening on private port %s...", s.serverOptions.PrivateHostPort))
// cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc+proto"),
// )
// s.httpConn = cmuxServer.Match(cmux.Any())
// s.queryOptions.HTTPHostPort = s.queryOptions.HostPort
// s.queryOptions.GRPCHostPort = s.queryOptions.HostPort
return nil, nil
return nil
} }
// Start http, GRPC and cmux servers concurrently // Start listening on http and private http port concurrently
func (s *Server) Start() error { func (s *Server) Start() error {
_, err := s.initListener() err := s.initListeners()
if err != nil { if err != nil {
return err return err
} }
@ -283,5 +290,25 @@ func (s *Server) Start() error {
} }
}() }()
var privatePort int
if port, err := utils.GetPort(s.privateConn.Addr()); err == nil {
privatePort = port
}
fmt.Println("starting private http")
go func() {
zap.S().Info("Starting Private HTTP server", zap.Int("port", privatePort), zap.String("addr", s.serverOptions.PrivateHostPort))
switch err := s.privateHTTP.Serve(s.privateConn); err {
case nil, http.ErrServerClosed, cmux.ErrListenerClosed:
// normal exit, nothing to do
zap.S().Info("private http server closed")
default:
zap.S().Error("Could not start private HTTP server", zap.Error(err))
}
s.unavailableChannel <- healthcheck.Unavailable
}()
return nil return nil
} }

View File

@ -6,8 +6,9 @@ import (
) )
const ( const (
HTTPHostPort = "0.0.0.0:8080" // Address to serve http (query service) HTTPHostPort = "0.0.0.0:8080" // Address to serve http (query service)
DebugHttpPort = "0.0.0.0:6060" // Address to serve http (pprof) PrivateHostPort = "0.0.0.0:8085" // Address to server internal services like alert manager
DebugHttpPort = "0.0.0.0:6060" // Address to serve http (pprof)
) )
var DEFAULT_TELEMETRY_ANONYMOUS = false var DEFAULT_TELEMETRY_ANONYMOUS = false
@ -37,29 +38,29 @@ var AmChannelApiPath = GetOrDefaultEnv("ALERTMANAGER_API_CHANNEL_PATH", "v1/rout
var RELATIONAL_DATASOURCE_PATH = GetOrDefaultEnv("SIGNOZ_LOCAL_DB_PATH", "/var/lib/signoz/signoz.db") var RELATIONAL_DATASOURCE_PATH = GetOrDefaultEnv("SIGNOZ_LOCAL_DB_PATH", "/var/lib/signoz/signoz.db")
const ( const (
ServiceName = "serviceName" ServiceName = "serviceName"
HttpRoute = "httpRoute" HttpRoute = "httpRoute"
HttpCode = "httpCode" HttpCode = "httpCode"
HttpHost = "httpHost" HttpHost = "httpHost"
HttpUrl = "httpUrl" HttpUrl = "httpUrl"
HttpMethod = "httpMethod" HttpMethod = "httpMethod"
Component = "component" Component = "component"
OperationDB = "name" OperationDB = "name"
OperationRequest = "operation" OperationRequest = "operation"
Status = "status" Status = "status"
Duration = "duration" Duration = "duration"
DBName = "dbName" DBName = "dbName"
DBOperation = "dbOperation" DBOperation = "dbOperation"
DBSystem = "dbSystem" DBSystem = "dbSystem"
MsgSystem = "msgSystem" MsgSystem = "msgSystem"
MsgOperation = "msgOperation" MsgOperation = "msgOperation"
Timestamp = "timestamp" Timestamp = "timestamp"
Descending = "descending" Descending = "descending"
Ascending = "ascending" Ascending = "ascending"
ContextTimeout = 60 // seconds ContextTimeout = 60 // seconds
StatusPending = "pending" StatusPending = "pending"
StatusFailed = "failed" StatusFailed = "failed"
StatusSuccess = "success" StatusSuccess = "success"
) )
func GetOrDefaultEnv(key string, fallback string) string { func GetOrDefaultEnv(key string, fallback string) string {

View File

@ -34,7 +34,8 @@ func main() {
version.PrintVersion() version.PrintVersion()
serverOptions := &app.ServerOptions{ serverOptions := &app.ServerOptions{
HTTPHostPort: constants.HTTPHostPort, HTTPHostPort: constants.HTTPHostPort,
PrivateHostPort: constants.PrivateHostPort,
} }
// Read the jwt secret key // Read the jwt secret key

View File

@ -23,7 +23,7 @@ services:
- query-service - query-service
restart: on-failure restart: on-failure
command: command:
- --queryService.url=http://query-service:8080 - --queryService.url=http://query-service:8085
- --storage.path=/data - --storage.path=/data
query-service: query-service:
@ -51,7 +51,7 @@ services:
condition: service_healthy condition: service_healthy
otel-collector: otel-collector:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-config.yaml"] command: ["--config=/etc/otel-collector-config.yaml"]
volumes: volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
@ -64,7 +64,7 @@ services:
condition: service_healthy condition: service_healthy
otel-collector-metrics: otel-collector-metrics:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-metrics-config.yaml"] command: ["--config=/etc/otel-collector-metrics-config.yaml"]
volumes: volumes:
- ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml - ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml

View File

@ -26,7 +26,7 @@ services:
- query-service - query-service
restart: on-failure restart: on-failure
command: command:
- --queryService.url=http://query-service:8080 - --queryService.url=http://query-service:8085
- --storage.path=/data - --storage.path=/data
# Notes for Maintainers/Contributors who will change Line Numbers of Frontend & Query-Section. Please Update Line Numbers in `./scripts/commentLinesForSetup.sh` & `./CONTRIBUTING.md` # Notes for Maintainers/Contributors who will change Line Numbers of Frontend & Query-Section. Please Update Line Numbers in `./scripts/commentLinesForSetup.sh` & `./CONTRIBUTING.md`
@ -56,7 +56,7 @@ services:
condition: service_healthy condition: service_healthy
otel-collector: otel-collector:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-config.yaml"] command: ["--config=/etc/otel-collector-config.yaml"]
volumes: volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
@ -69,7 +69,7 @@ services:
condition: service_healthy condition: service_healthy
otel-collector-metrics: otel-collector-metrics:
image: signoz/otelcontribcol:0.43.0-0.1 image: signoz/otelcontribcol:0.45.1-0.2
command: ["--config=/etc/otel-collector-metrics-config.yaml"] command: ["--config=/etc/otel-collector-metrics-config.yaml"]
volumes: volumes:
- ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml - ./otel-collector-metrics-config.yaml:/etc/otel-collector-metrics-config.yaml

View File

@ -49,7 +49,7 @@ extensions:
health_check: {} health_check: {}
zpages: {} zpages: {}
exporters: exporters:
clickhouse: clickhousetraces:
datasource: tcp://clickhouse:9000/?database=signoz_traces datasource: tcp://clickhouse:9000/?database=signoz_traces
clickhousemetricswrite: clickhousemetricswrite:
endpoint: tcp://clickhouse:9000/?database=signoz_metrics endpoint: tcp://clickhouse:9000/?database=signoz_metrics
@ -63,7 +63,7 @@ service:
traces: traces:
receivers: [jaeger, otlp] receivers: [jaeger, otlp]
processors: [signozspanmetrics/prometheus, batch] processors: [signozspanmetrics/prometheus, batch]
exporters: [clickhouse] exporters: [clickhousetraces]
metrics: metrics:
receivers: [otlp, hostmetrics] receivers: [otlp, hostmetrics]
processors: [batch] processors: [batch]