Skip to content

Commit

Permalink
Merge branch 'main' into chore-remove-delete-tracing-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Dec 20, 2023
2 parents 4c8e619 + a1d45f5 commit 264c3a1
Show file tree
Hide file tree
Showing 37 changed files with 121 additions and 270 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ jobs:
- tracetest-jaeger
- tracetest-opensearch
- tracetest-tempo
- tracetest-no-tracing
- tracetest-provisioning-env
- tracetest-signoz
steps:
Expand Down
1 change: 0 additions & 1 deletion api/dataStores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ components:
type: string
enum:
[
agent,
jaeger,
opensearch,
tempo,
Expand Down
1 change: 0 additions & 1 deletion cli/cmd/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ var (
return nil
},
}),
resourcemanager.WithDeleteSuccessMessage("DataStore removed. Defaulting back to no-tracing mode"),
resourcemanager.WithResourceType("DataStore"),
),
).
Expand Down
36 changes: 0 additions & 36 deletions examples/tracetest-no-tracing/docker-compose.yml

This file was deleted.

17 changes: 0 additions & 17 deletions examples/tracetest-no-tracing/tests/list-tests.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions examples/tracetest-no-tracing/tracetest-config.yaml

This file was deleted.

1 change: 1 addition & 0 deletions server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ func registerDataStoreResource(repository *datastore.Repository, router *mux.Rou
repository,
resourcemanager.DisableDelete(),
resourcemanager.WithTracer(tracer),
resourcemanager.DisableDelete(),
)
manager.RegisterRoutes(router)
provisioner.AddResourceProvisioner(manager)
Expand Down
35 changes: 11 additions & 24 deletions server/datastore/datastore_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func (r *Repository) SetID(dataStore DataStore, id id.ID) DataStore {

const DataStoreSingleID id.ID = "current"

var defaultDataStore = DataStore{
ID: DataStoreSingleID,
Name: "OTLP",
Type: DataStoreTypeOTLP,
Default: true,
Values: DataStoreValues{},
}

const insertQuery = `
INSERT INTO data_stores (
"id",
Expand Down Expand Up @@ -123,27 +131,6 @@ func (r *Repository) Update(ctx context.Context, dataStore DataStore) (DataStore
return dataStore, nil
}

func (r *Repository) Delete(ctx context.Context, id id.ID) error {
tx, err := r.db.BeginTx(ctx, nil)
if err != nil {
return err
}
defer tx.Rollback()

query, params := sqlutil.Tenant(ctx, deleteQuery, id)
_, err = tx.ExecContext(ctx, query, params...)
if err != nil {
return fmt.Errorf("datastore repository sql exec delete: %w", err)
}

err = tx.Commit()
if err != nil {
return fmt.Errorf("commit: %w", err)
}

return nil
}

const getQuery = `
SELECT
"id",
Expand All @@ -170,9 +157,9 @@ func (r *Repository) Get(ctx context.Context, id id.ID) (DataStore, error) {

dataStore, err := r.readRow(row)
if err != nil && errors.Is(err, sql.ErrNoRows) {
return DataStore{
CreatedAt: newCreateAtDateString(),
}, nil // Assumes an empty datastore
dataStore := defaultDataStore
dataStore.CreatedAt = newCreateAtDateString()
return dataStore, nil // Assumes default datastore
}
if err != nil {
return DataStore{}, fmt.Errorf("datastore repository get sql query: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion server/datastore/datastore_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var (
excludedOperations = rmtests.ExcludeOperations(
rmtests.OperationUpdateNotFound,
rmtests.OperationGetNotFound,
rmtests.OperationDeleteNotFound,
rmtests.OperationListSortSuccess,
rmtests.OperationListNoResults,
)
Expand Down Expand Up @@ -45,6 +44,7 @@ func registerManagerFn(router *mux.Router, db *sql.DB) resourcemanager.Manager {
datastore.ResourceNamePlural,
dataStoreRepository,
resourcemanager.WithIDGen(id.GenerateID),
resourcemanager.DisableDelete(),
)
manager.RegisterRoutes(router)

Expand Down
22 changes: 22 additions & 0 deletions server/migrations/36_migrate_users_to_opentelemetry.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- We are going to deprecate "no tracing mode" and "agent" tracing backends
-- So we need to migrate all users to a valid trace backend.
--
-- This means that all users using "no tracing mode" and "agent" tracing backends will become
-- "otlp" tracing backends

-- If there's an "agent" tracing backend, replace it with an "otlp" tracing backend instead
UPDATE data_stores
SET "name" = 'otlp', "type" = 'otlp', "values" = '{}'::jsonb
from (
SELECT id, "type" FROM data_stores WHERE "type" = 'agent'
) migration_target
WHERE data_stores.id = migration_target.id;

-- If there's no "current" tracing backend, add one for otlp. This ensures that if user is on
-- "No tracing mode", it will be migrated to "OpenTelemetry".
INSERT INTO
data_stores (id, "name", "type", is_default, "values", created_at, tenant_id)
VALUES ('current', 'otlp', 'otlp', true, '{}'::jsonb, now(), '')
ON CONFLICT DO NOTHING;


1 change: 1 addition & 0 deletions server/provisioning/provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func setup(db *sql.DB) provisioningFixture {
datastore.ResourceName,
datastore.ResourceNamePlural,
f.dataStores,
resourcemanager.DisableDelete(),
)

f.provisioner = provisioning.New(provisioning.WithResourceProvisioners(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package datastore

import (
"fmt"
"testing"

"github.com/kubeshop/tracetest/testing/cli-e2etest/environment"
"github.com/kubeshop/tracetest/testing/cli-e2etest/helpers"
"github.com/kubeshop/tracetest/testing/cli-e2etest/testscenarios/types"
"github.com/kubeshop/tracetest/testing/cli-e2etest/tracetestcli"
"github.com/stretchr/testify/require"
)

func TestDeleteDatastore(t *testing.T) {
// instantiate require with testing helper
require := require.New(t)

// setup isolated e2e environment
env := environment.CreateAndStart(t)
defer env.Close(t)

cliConfig := env.GetCLIConfigPath(t)

// Given I am a Tracetest CLI user
// And I have my server recently created

// When I try to set up a new datastore
// Then it should be applied with success
dataStorePath := env.GetEnvironmentResourcePath(t, "data-store")

result := tracetestcli.Exec(t, fmt.Sprintf("apply datastore --file %s", dataStorePath), tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)

// When I try to get a datastore
// Then it should return the datastore applied on the last step
result = tracetestcli.Exec(t, "get datastore --id current", tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)

dataStore := helpers.UnmarshalYAML[types.DataStoreResource](t, result.StdOut)
require.Equal("DataStore", dataStore.Type)
require.Equal("current", dataStore.Spec.ID)
require.True(dataStore.Spec.Default)

// When I try to delete the datastore
// Then it should return a error message, showing that we cannot delete a datastore
result = tracetestcli.Exec(t, "delete datastore --id current", tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 1)
require.Contains(result.StdErr, "resource DataStore does not support the action")
}
13 changes: 10 additions & 3 deletions testing/cli-e2etest/testscenarios/datastore/list_datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ func TestListDatastore(t *testing.T) {
// And I have my server recently created

// When I try to list datastore on pretty mode and there is no datastore
// Then it should print an empty table
// Then it should list the default datastore
result := tracetestcli.Exec(t, "list datastore --output pretty", tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
require.NotContains(result.StdOut, "current")

parsedTable := helpers.UnmarshalTable(t, result.StdOut)
require.Len(parsedTable, 1)

singleLine := parsedTable[0]

require.Equal("current", singleLine["ID"])
require.Equal("OTLP", singleLine["NAME"])
require.Equal("*", singleLine["DEFAULT"])
})

addListDatastorePreReqs(t, env)
Expand Down
2 changes: 0 additions & 2 deletions web/src/components/DataStoreIcon/DataStoreIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {useTheme} from 'styled-components';
import {SupportedDataStores} from 'types/DataStore.types';
import Agent from './Icons/Agent';
import Elastic from './Icons/Elastic';
import Jaeger from './Icons/Jaeger';
import Lightstep from './Icons/Lightstep';
Expand All @@ -18,7 +17,6 @@ import Dynatrace from './Icons/Dynatrace';
import SumoLogic from './Icons/SumoLogic';

const iconMap = {
[SupportedDataStores.Agent]: Agent,
[SupportedDataStores.JAEGER]: Jaeger,
[SupportedDataStores.SignalFX]: SignalFx,
[SupportedDataStores.ElasticApm]: Elastic,
Expand Down
14 changes: 0 additions & 14 deletions web/src/components/DataStoreIcon/Icons/Agent.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CheckCircleOutlined} from '@ant-design/icons';
import {Tabs, Typography} from 'antd';
import styled, {css} from 'styled-components';
import styled from 'styled-components';

const defaultHeight = '100vh - 106px - 60px - 40px';

Expand All @@ -23,19 +23,12 @@ export const DataStoreListContainer = styled(Tabs)`
}
`;

export const DataStoreItemContainer = styled.div<{$isDisabled: boolean; $isSelected: boolean}>`
export const DataStoreItemContainer = styled.div<{$isSelected: boolean}>`
display: flex;
align-items: center;
gap: 10px;
padding: 12px 22px;
cursor: pointer;
${({$isDisabled}) =>
$isDisabled &&
css`
cursor: not-allowed;
opacity: 0.5;
`}
`;

export const DataStoreName = styled(Typography.Text)<{$isSelected: boolean}>`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {Popover, Tabs} from 'antd';
import {useCallback} from 'react';
import {noop} from 'lodash';
import {useTheme} from 'styled-components';
import {ConfigMode, SupportedDataStores} from 'types/DataStore.types';
import {SupportedDataStoresToName} from 'constants/DataStore.constants';
import {Flag, useCustomization} from 'providers/Customization';
import {useSettingsValues} from 'providers/SettingsValues/SettingsValues.provider';

import DataStoreIcon from '../../DataStoreIcon/DataStoreIcon';
Expand All @@ -18,57 +16,25 @@ interface IProps {
const supportedDataStoreList = Object.values(SupportedDataStores);

const DataStoreSelection = ({onChange = noop, value = SupportedDataStores.JAEGER}: IProps) => {
const {getFlag} = useCustomization();
const isLocalModeEnabled = getFlag(Flag.IsLocalModeEnabled);
const {
color: {text, primary},
} = useTheme();
const {dataStoreConfig} = useSettingsValues();
const configuredDataStoreType = dataStoreConfig.defaultDataStore.type;

const handleChange = useCallback(
dataStore => {
const isDisabled = isLocalModeEnabled && dataStore !== SupportedDataStores.Agent;

if (!isDisabled) onChange(dataStore);
},
[isLocalModeEnabled, onChange]
);

return (
<S.DataStoreListContainer tabPosition="left" onChange={handleChange}>
<S.DataStoreListContainer tabPosition="left" onChange={dataStore => onChange(dataStore as SupportedDataStores)}>
{supportedDataStoreList.map(dataStore => {
if (dataStore === SupportedDataStores.Agent && !getFlag(Flag.IsAgentDataStoreEnabled)) {
return null;
}

const isSelected = value === dataStore;
const isConfigured = configuredDataStoreType === dataStore && dataStoreConfig.mode === ConfigMode.READY;
const isDisabled = isLocalModeEnabled && dataStore !== SupportedDataStores.Agent;

return (
<Tabs.TabPane
key={dataStore}
tab={
<S.DataStoreItemContainer $isDisabled={isDisabled} $isSelected={isSelected} key={dataStore}>
<S.DataStoreItemContainer $isSelected={isSelected} key={dataStore}>
<DataStoreIcon dataStoreType={dataStore} color={isSelected ? primary : text} width="22" height="22" />

{isDisabled ? (
<Popover
content={
<div>
In localMode only the Agent data store can be used. <br /> If you want to connect to a different
data store <br /> please create a new environment
</div>
}
placement="right"
>
<S.DataStoreName $isSelected={isSelected}>{SupportedDataStoresToName[dataStore]}</S.DataStoreName>
</Popover>
) : (
<S.DataStoreName $isSelected={isSelected}>{SupportedDataStoresToName[dataStore]}</S.DataStoreName>
)}

<S.DataStoreName $isSelected={isSelected}>{SupportedDataStoresToName[dataStore]}</S.DataStoreName>
{isConfigured && (
<Popover content="This data source is currently configured" placement="right">
<S.InfoIcon />
Expand Down
Loading

0 comments on commit 264c3a1

Please sign in to comment.