From f50aaa065c5c03a35411270056fa33fb71e82ed0 Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Fri, 17 Nov 2023 22:12:29 +0530 Subject: [PATCH] peerdb takes care of external metadata store --- flow/connectors/external_metadata/store.go | 27 ++++-- ui/app/peers/create/[peerType]/helpers/s3.ts | 9 +- ui/app/peers/create/[peerType]/schema.ts | 1 - ui/components/S3Form.tsx | 94 +------------------- 4 files changed, 25 insertions(+), 106 deletions(-) diff --git a/flow/connectors/external_metadata/store.go b/flow/connectors/external_metadata/store.go index 8693dabb58..f1b8c25079 100644 --- a/flow/connectors/external_metadata/store.go +++ b/flow/connectors/external_metadata/store.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/PeerDB-io/peer-flow/connectors/utils" + cc "github.com/PeerDB-io/peer-flow/connectors/utils/catalog" "github.com/PeerDB-io/peer-flow/generated/protos" "github.com/jackc/pgx/v5/pgxpool" log "github.com/sirupsen/logrus" @@ -23,18 +24,30 @@ type PostgresMetadataStore struct { func NewPostgresMetadataStore(ctx context.Context, pgConfig *protos.PostgresConfig, schemaName string) (*PostgresMetadataStore, error) { - connectionString := utils.GetPGConnectionString(pgConfig) - pool, err := pgxpool.New(ctx, connectionString) - if err != nil { - log.Errorf("failed to create connection pool: %v", err) - return nil, err + var storePool *pgxpool.Pool + var poolErr error + if pgConfig == nil { + storePool, poolErr = cc.GetCatalogConnectionPoolFromEnv() + if poolErr != nil { + return nil, fmt.Errorf("failed to create catalog connection pool: %v", poolErr) + } + + log.Info("obtained catalog connection pool for metadata store") + } else { + connectionString := utils.GetPGConnectionString(pgConfig) + storePool, poolErr = pgxpool.New(ctx, connectionString) + if poolErr != nil { + log.Errorf("failed to create connection pool: %v", poolErr) + return nil, poolErr + } + + log.Info("created connection pool for metadata store") } - log.Info("created connection pool for metadata store") return &PostgresMetadataStore{ ctx: ctx, config: pgConfig, - pool: pool, + pool: storePool, schemaName: schemaName, }, nil } diff --git a/ui/app/peers/create/[peerType]/helpers/s3.ts b/ui/app/peers/create/[peerType]/helpers/s3.ts index 2cec9d1755..cd3ac99a38 100644 --- a/ui/app/peers/create/[peerType]/helpers/s3.ts +++ b/ui/app/peers/create/[peerType]/helpers/s3.ts @@ -52,12 +52,5 @@ export const blankS3Setting: S3Config = { roleArn: undefined, region: undefined, endpoint: '', - metadataDb: { - host: '', - port: 5432, - user: 'postgres', - password: '', - database: 'postgres', - transactionSnapshot: '', - }, + metadataDb: undefined, }; diff --git a/ui/app/peers/create/[peerType]/schema.ts b/ui/app/peers/create/[peerType]/schema.ts index ecbe5b63c3..494102b571 100644 --- a/ui/app/peers/create/[peerType]/schema.ts +++ b/ui/app/peers/create/[peerType]/schema.ts @@ -234,5 +234,4 @@ export const s3Schema = z.object({ invalid_type_error: 'Endpoint must be a string', }) .optional(), - metadataDb: pgSchema, }); diff --git a/ui/components/S3Form.tsx b/ui/components/S3Form.tsx index cbd78ff7ce..55f475c3d1 100644 --- a/ui/components/S3Form.tsx +++ b/ui/components/S3Form.tsx @@ -1,11 +1,5 @@ 'use client'; -import { PeerConfig } from '@/app/dto/PeersDTO'; -import { postgresSetting } from '@/app/peers/create/[peerType]/helpers/pg'; -import { - blankS3Setting, - s3Setting, -} from '@/app/peers/create/[peerType]/helpers/s3'; -import { PostgresConfig } from '@/grpc_generated/peers'; +import { s3Setting } from '@/app/peers/create/[peerType]/helpers/s3'; import { Label } from '@/lib/Label'; import { RowWithRadiobutton, RowWithTextField } from '@/lib/Layout'; import { RadioButton, RadioButtonGroup } from '@/lib/RadioButtonGroup'; @@ -19,9 +13,6 @@ interface S3Props { setter: PeerSetter; } const S3ConfigForm = ({ setter }: S3Props) => { - const [metadataDB, setMetadataDB] = useState( - blankS3Setting.metadataDb! - ); const [storageType, setStorageType] = useState<'S3' | 'GCS'>('S3'); const displayCondition = (label: string) => { return !( @@ -31,23 +22,15 @@ const S3ConfigForm = ({ setter }: S3Props) => { }; useEffect(() => { const endpoint = storageType === 'S3' ? '' : 'storage.googleapis.com'; + const region = storageType === 'S3' ? '' : 'auto'; setter((prev) => { return { ...prev, - metadataDb: metadataDB as PostgresConfig, endpoint, + region, }; }); - - if (storageType === 'GCS') { - setter((prev) => { - return { - ...prev, - region: 'auto', - }; - }); - } - }, [metadataDB, storageType, setter]); + }, [storageType, setter]); return (
@@ -130,75 +113,6 @@ const S3ConfigForm = ({ setter }: S3Props) => { /> ); })} - - - - {postgresSetting.map( - (pgSetting, index) => - pgSetting.label !== 'Transaction Snapshot' && ( - - {pgSetting.label}{' '} - - - - - } - action={ -
- ) => - pgSetting.stateHandler(e.target.value, setMetadataDB) - } - defaultValue={ - (metadataDB as PostgresConfig)[ - pgSetting.label.toLowerCase() as keyof PostgresConfig - ] || '' - } - /> - {pgSetting.tips && ( - - )} -
- } - /> - ) - )}
); };