Skip to content

Commit

Permalink
Merge branch 'develop' into kafka-consumer-lag-details-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarRajput-7 authored Dec 19, 2024
2 parents 3b32c27 + 67e822e commit 302b686
Show file tree
Hide file tree
Showing 104 changed files with 2,365 additions and 913 deletions.
3 changes: 2 additions & 1 deletion deploy/docker-swarm/clickhouse-setup/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ services:
command:
[
"-config=/root/config/prometheus.yml",
"--use-logs-new-schema=true"
"--use-logs-new-schema=true",
"--use-trace-new-schema=true"
]
# ports:
# - "6060:6060" # pprof port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ exporters:
clickhousetraces:
datasource: tcp://clickhouse:9000/signoz_traces
low_cardinal_exception_grouping: ${env:LOW_CARDINAL_EXCEPTION_GROUPING}
use_new_schema: true
clickhousemetricswrite:
endpoint: tcp://clickhouse:9000/signoz_metrics
resource_to_telemetry_conversion:
Expand Down
3 changes: 2 additions & 1 deletion deploy/docker/clickhouse-setup/docker-compose-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ services:
command:
[
"-config=/root/config/prometheus.yml",
"--use-logs-new-schema=true"
"--use-logs-new-schema=true",
"--use-trace-new-schema=true"
]
ports:
- "6060:6060"
Expand Down
3 changes: 2 additions & 1 deletion deploy/docker/clickhouse-setup/docker-compose-minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ services:
command:
[
"-config=/root/config/prometheus.yml",
"--use-logs-new-schema=true"
"--use-logs-new-schema=true",
"--use-trace-new-schema=true"
]
# ports:
# - "6060:6060" # pprof port
Expand Down
3 changes: 2 additions & 1 deletion deploy/docker/clickhouse-setup/docker-compose.testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ services:
[
"-config=/root/config/prometheus.yml",
"-gateway-url=https://api.staging.signoz.cloud",
"--use-logs-new-schema=true"
"--use-logs-new-schema=true",
"--use-trace-new-schema=true"
]
# ports:
# - "6060:6060" # pprof port
Expand Down
1 change: 1 addition & 0 deletions deploy/docker/clickhouse-setup/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ exporters:
clickhousetraces:
datasource: tcp://clickhouse:9000/signoz_traces
low_cardinal_exception_grouping: ${env:LOW_CARDINAL_EXCEPTION_GROUPING}
use_new_schema: true
clickhousemetricswrite:
endpoint: tcp://clickhouse:9000/signoz_metrics
resource_to_telemetry_conversion:
Expand Down
2 changes: 0 additions & 2 deletions ee/query-service/app/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type APIHandlerOptions struct {
FluxInterval time.Duration
UseLogsNewSchema bool
UseTraceNewSchema bool
UseLicensesV3 bool
}

type APIHandler struct {
Expand All @@ -68,7 +67,6 @@ func NewAPIHandler(opts APIHandlerOptions) (*APIHandler, error) {
FluxInterval: opts.FluxInterval,
UseLogsNewSchema: opts.UseLogsNewSchema,
UseTraceNewSchema: opts.UseTraceNewSchema,
UseLicensesV3: opts.UseLicensesV3,
})

if err != nil {
Expand Down
31 changes: 6 additions & 25 deletions ee/query-service/app/api/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ func (ah *APIHandler) listLicenses(w http.ResponseWriter, r *http.Request) {
}

func (ah *APIHandler) applyLicense(w http.ResponseWriter, r *http.Request) {
if ah.UseLicensesV3 {
// if the licenses v3 is toggled on then do not apply license in v2 and run the validator!
// TODO: remove after migration to v3 and deprecation from zeus
zap.L().Info("early return from apply license v2 call")
render.Success(w, http.StatusOK, nil)
return
}
var l model.License

if err := json.NewDecoder(r.Body).Decode(&l); err != nil {
Expand All @@ -102,7 +95,7 @@ func (ah *APIHandler) applyLicense(w http.ResponseWriter, r *http.Request) {
RespondError(w, model.BadRequest(fmt.Errorf("license key is required")), nil)
return
}
license, apiError := ah.LM().Activate(r.Context(), l.Key)
license, apiError := ah.LM().ActivateV3(r.Context(), l.Key)
if apiError != nil {
RespondError(w, apiError, nil)
return
Expand Down Expand Up @@ -265,24 +258,12 @@ func convertLicenseV3ToLicenseV2(licenses []*model.LicenseV3) []model.License {
}

func (ah *APIHandler) listLicensesV2(w http.ResponseWriter, r *http.Request) {

var licenses []model.License

if ah.UseLicensesV3 {
licensesV3, err := ah.LM().GetLicensesV3(r.Context())
if err != nil {
RespondError(w, err, nil)
return
}
licenses = convertLicenseV3ToLicenseV2(licensesV3)
} else {
_licenses, apiError := ah.LM().GetLicenses(r.Context())
if apiError != nil {
RespondError(w, apiError, nil)
return
}
licenses = _licenses
licensesV3, apierr := ah.LM().GetLicensesV3(r.Context())
if apierr != nil {
RespondError(w, apierr, nil)
return
}
licenses := convertLicenseV3ToLicenseV2(licensesV3)

resp := model.Licenses{
TrialStart: -1,
Expand Down
4 changes: 1 addition & 3 deletions ee/query-service/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ type ServerOptions struct {
GatewayUrl string
UseLogsNewSchema bool
UseTraceNewSchema bool
UseLicensesV3 bool
}

// Server runs HTTP api service
Expand Down Expand Up @@ -135,7 +134,7 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
}

// initiate license manager
lm, err := licensepkg.StartManager("sqlite", localDB, serverOptions.UseLicensesV3)
lm, err := licensepkg.StartManager("sqlite", localDB)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -274,7 +273,6 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
Gateway: gatewayProxy,
UseLogsNewSchema: serverOptions.UseLogsNewSchema,
UseTraceNewSchema: serverOptions.UseTraceNewSchema,
UseLicensesV3: serverOptions.UseLicensesV3,
}

apiHandler, err := api.NewAPIHandler(apiOpts)
Expand Down
12 changes: 0 additions & 12 deletions ee/query-service/integrations/signozio/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ package signozio

type status string

type ActivationResult struct {
Status status `json:"status"`
Data *ActivationResponse `json:"data,omitempty"`
ErrorType string `json:"errorType,omitempty"`
Error string `json:"error,omitempty"`
}

type ActivationResponse struct {
ActivationId string `json:"ActivationId"`
PlanDetails string `json:"PlanDetails"`
}

type ValidateLicenseResponse struct {
Status status `json:"status"`
Data map[string]interface{} `json:"data"`
Expand Down
81 changes: 0 additions & 81 deletions ee/query-service/integrations/signozio/signozio.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/pkg/errors"
"go.uber.org/zap"

"go.signoz.io/signoz/ee/query-service/constants"
"go.signoz.io/signoz/ee/query-service/model"
Expand Down Expand Up @@ -39,86 +38,6 @@ func init() {
C = New()
}

// ActivateLicense sends key to license.signoz.io and gets activation data
func ActivateLicense(key, siteId string) (*ActivationResponse, *model.ApiError) {
licenseReq := map[string]string{
"key": key,
"siteId": siteId,
}

reqString, _ := json.Marshal(licenseReq)
httpResponse, err := http.Post(C.Prefix+"/licenses/activate", APPLICATION_JSON, bytes.NewBuffer(reqString))

if err != nil {
zap.L().Error("failed to connect to license.signoz.io", zap.Error(err))
return nil, model.BadRequest(fmt.Errorf("unable to connect with license.signoz.io, please check your network connection"))
}

httpBody, err := io.ReadAll(httpResponse.Body)
if err != nil {
zap.L().Error("failed to read activation response from license.signoz.io", zap.Error(err))
return nil, model.BadRequest(fmt.Errorf("failed to read activation response from license.signoz.io"))
}

defer httpResponse.Body.Close()

// read api request result
result := ActivationResult{}
err = json.Unmarshal(httpBody, &result)
if err != nil {
zap.L().Error("failed to marshal activation response from license.signoz.io", zap.Error(err))
return nil, model.InternalError(errors.Wrap(err, "failed to marshal license activation response"))
}

switch httpResponse.StatusCode {
case 200, 201:
return result.Data, nil
case 400, 401:
return nil, model.BadRequest(fmt.Errorf(fmt.Sprintf("failed to activate: %s", result.Error)))
default:
return nil, model.InternalError(fmt.Errorf(fmt.Sprintf("failed to activate: %s", result.Error)))
}

}

// ValidateLicense validates the license key
func ValidateLicense(activationId string) (*ActivationResponse, *model.ApiError) {
validReq := map[string]string{
"activationId": activationId,
}

reqString, _ := json.Marshal(validReq)
response, err := http.Post(C.Prefix+"/licenses/validate", APPLICATION_JSON, bytes.NewBuffer(reqString))

if err != nil {
return nil, model.BadRequest(errors.Wrap(err, "unable to connect with license.signoz.io, please check your network connection"))
}

body, err := io.ReadAll(response.Body)
if err != nil {
return nil, model.BadRequest(errors.Wrap(err, "failed to read validation response from license.signoz.io"))
}

defer response.Body.Close()

switch response.StatusCode {
case 200, 201:
a := ActivationResult{}
err = json.Unmarshal(body, &a)
if err != nil {
return nil, model.BadRequest(errors.Wrap(err, "failed to marshal license validation response"))
}
return a.Data, nil
case 400, 401:
return nil, model.BadRequest(errors.Wrap(fmt.Errorf(string(body)),
"bad request error received from license.signoz.io"))
default:
return nil, model.InternalError(errors.Wrap(fmt.Errorf(string(body)),
"internal error received from license.signoz.io"))
}

}

func ValidateLicenseV3(licenseKey string) (*model.LicenseV3, *model.ApiError) {

// Creating an HTTP client with a timeout for better control
Expand Down
32 changes: 10 additions & 22 deletions ee/query-service/license/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ import (

// Repo is license repo. stores license keys in a secured DB
type Repo struct {
db *sqlx.DB
useLicensesV3 bool
db *sqlx.DB
}

// NewLicenseRepo initiates a new license repo
func NewLicenseRepo(db *sqlx.DB, useLicensesV3 bool) Repo {
func NewLicenseRepo(db *sqlx.DB) Repo {
return Repo{
db: db,
useLicensesV3: useLicensesV3,
db: db,
}
}

Expand Down Expand Up @@ -112,26 +110,16 @@ func (r *Repo) GetActiveLicenseV2(ctx context.Context) (*model.License, *basemod
// GetActiveLicense fetches the latest active license from DB.
// If the license is not present, expect a nil license and a nil error in the output.
func (r *Repo) GetActiveLicense(ctx context.Context) (*model.License, *basemodel.ApiError) {
if r.useLicensesV3 {
zap.L().Info("Using licenses v3 for GetActiveLicense")
activeLicenseV3, err := r.GetActiveLicenseV3(ctx)
if err != nil {
return nil, basemodel.InternalError(fmt.Errorf("failed to get active licenses from db: %v", err))
}

if activeLicenseV3 == nil {
return nil, nil
}
activeLicenseV2 := model.ConvertLicenseV3ToLicenseV2(activeLicenseV3)
return activeLicenseV2, nil

activeLicenseV3, err := r.GetActiveLicenseV3(ctx)
if err != nil {
return nil, basemodel.InternalError(fmt.Errorf("failed to get active licenses from db: %v", err))
}

active, err := r.GetActiveLicenseV2(ctx)
if err != nil {
return nil, err
if activeLicenseV3 == nil {
return nil, nil
}
return active, nil
activeLicenseV2 := model.ConvertLicenseV3ToLicenseV2(activeLicenseV3)
return activeLicenseV2, nil
}

func (r *Repo) GetActiveLicenseV3(ctx context.Context) (*model.LicenseV3, error) {
Expand Down
Loading

0 comments on commit 302b686

Please sign in to comment.