2024-03-02 10:11:51 +05:30
|
|
|
package integrations
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/agentConf"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/model"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/sqlstore"
|
2025-06-02 22:41:38 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/types/dashboardtypes"
|
2025-03-24 10:17:12 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/types/pipelinetypes"
|
2025-06-02 22:41:38 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
2024-03-02 10:11:51 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Controller struct {
|
|
|
|
|
mgr *Manager
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func NewController(sqlStore sqlstore.SQLStore) (*Controller, error) {
|
2025-04-15 21:05:36 +05:30
|
|
|
mgr, err := NewManager(sqlStore)
|
2024-03-02 10:11:51 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("couldn't create integrations manager: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &Controller{
|
|
|
|
|
mgr: mgr,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type IntegrationsListResponse struct {
|
|
|
|
|
Integrations []IntegrationsListItem `json:"integrations"`
|
|
|
|
|
|
|
|
|
|
// Pagination details to come later
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) ListIntegrations(ctx context.Context, orgId string, params map[string]string) (*IntegrationsListResponse, *model.ApiError) {
|
2024-03-02 10:11:51 +05:30
|
|
|
var filters *IntegrationsFilter
|
|
|
|
|
if isInstalledFilter, exists := params["is_installed"]; exists {
|
|
|
|
|
isInstalled := !(isInstalledFilter == "false")
|
|
|
|
|
filters = &IntegrationsFilter{
|
|
|
|
|
IsInstalled: &isInstalled,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-15 21:05:36 +05:30
|
|
|
integrations, apiErr := c.mgr.ListIntegrations(ctx, orgId, filters)
|
2024-03-02 10:11:51 +05:30
|
|
|
if apiErr != nil {
|
|
|
|
|
return nil, apiErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &IntegrationsListResponse{
|
|
|
|
|
Integrations: integrations,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) GetIntegration(ctx context.Context, orgId string, integrationId string) (*Integration, *model.ApiError) {
|
2025-04-15 21:05:36 +05:30
|
|
|
return c.mgr.GetIntegration(ctx, orgId, integrationId)
|
2024-03-02 10:11:51 +05:30
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) IsIntegrationInstalled(ctx context.Context, orgId string, integrationId string) (bool, *model.ApiError) {
|
2025-04-15 21:05:36 +05:30
|
|
|
installation, apiErr := c.mgr.getInstalledIntegration(ctx, orgId, integrationId)
|
2024-03-18 10:01:53 +05:30
|
|
|
if apiErr != nil {
|
|
|
|
|
return false, apiErr
|
|
|
|
|
}
|
|
|
|
|
isInstalled := installation != nil
|
|
|
|
|
return isInstalled, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) GetIntegrationConnectionTests(ctx context.Context, orgId string, integrationId string) (*IntegrationConnectionTests, *model.ApiError) {
|
2025-04-15 21:05:36 +05:30
|
|
|
return c.mgr.GetIntegrationConnectionTests(ctx, orgId, integrationId)
|
2024-03-05 15:23:56 +05:30
|
|
|
}
|
|
|
|
|
|
2024-03-02 10:11:51 +05:30
|
|
|
type InstallIntegrationRequest struct {
|
|
|
|
|
IntegrationId string `json:"integration_id"`
|
|
|
|
|
Config map[string]interface{} `json:"config"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) Install(ctx context.Context, orgId string, req *InstallIntegrationRequest) (*IntegrationsListItem, *model.ApiError) {
|
2024-03-11 14:15:11 +05:30
|
|
|
res, apiErr := c.mgr.InstallIntegration(
|
2025-04-15 21:05:36 +05:30
|
|
|
ctx, orgId, req.IntegrationId, req.Config,
|
2024-03-02 10:11:51 +05:30
|
|
|
)
|
2024-03-11 14:15:11 +05:30
|
|
|
if apiErr != nil {
|
|
|
|
|
return nil, apiErr
|
|
|
|
|
}
|
|
|
|
|
agentConf.NotifyConfigUpdate(ctx)
|
|
|
|
|
return res, nil
|
2024-03-02 10:11:51 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UninstallIntegrationRequest struct {
|
|
|
|
|
IntegrationId string `json:"integration_id"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) Uninstall(ctx context.Context, orgId string, req *UninstallIntegrationRequest) *model.ApiError {
|
2024-03-07 19:26:20 +05:30
|
|
|
if len(req.IntegrationId) < 1 {
|
|
|
|
|
return model.BadRequest(fmt.Errorf(
|
2024-06-11 20:10:38 +05:30
|
|
|
"integration_id is required",
|
2024-03-07 19:26:20 +05:30
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-11 14:15:11 +05:30
|
|
|
apiErr := c.mgr.UninstallIntegration(
|
2025-04-15 21:05:36 +05:30
|
|
|
ctx, orgId, req.IntegrationId,
|
2024-03-02 10:11:51 +05:30
|
|
|
)
|
2024-03-11 14:15:11 +05:30
|
|
|
if apiErr != nil {
|
|
|
|
|
return apiErr
|
|
|
|
|
}
|
|
|
|
|
agentConf.NotifyConfigUpdate(ctx)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) GetPipelinesForInstalledIntegrations(ctx context.Context, orgId string) ([]pipelinetypes.GettablePipeline, *model.ApiError) {
|
2025-04-15 21:05:36 +05:30
|
|
|
return c.mgr.GetPipelinesForInstalledIntegrations(ctx, orgId)
|
2024-03-02 10:11:51 +05:30
|
|
|
}
|
2024-03-11 20:06:59 +05:30
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) GetDashboardsForInstalledIntegrations(ctx context.Context, orgId valuer.UUID) ([]*dashboardtypes.Dashboard, *model.ApiError) {
|
2025-04-15 21:05:36 +05:30
|
|
|
return c.mgr.GetDashboardsForInstalledIntegrations(ctx, orgId)
|
2024-03-11 20:06:59 +05:30
|
|
|
}
|
|
|
|
|
|
2025-06-02 22:41:38 +05:30
|
|
|
func (c *Controller) GetInstalledIntegrationDashboardById(ctx context.Context, orgId valuer.UUID, dashboardUuid string) (*dashboardtypes.Dashboard, *model.ApiError) {
|
2025-04-15 21:05:36 +05:30
|
|
|
return c.mgr.GetInstalledIntegrationDashboardById(ctx, orgId, dashboardUuid)
|
2024-03-11 20:06:59 +05:30
|
|
|
}
|
2025-06-02 22:41:38 +05:30
|
|
|
|
|
|
|
|
func (c *Controller) IsInstalledIntegrationDashboardID(dashboardUuid string) bool {
|
|
|
|
|
return c.mgr.IsInstalledIntegrationDashboardUuid(dashboardUuid)
|
|
|
|
|
}
|