Skip to content

Commit b743507

Browse files
authored
Merge pull request #10 from dbazhenov/pg_init
Postgres Init DB fix
2 parents ecb19e5 + eb56041 commit b743507

File tree

6 files changed

+25
-45
lines changed

6 files changed

+25
-45
lines changed

cmd/dataset/main.go

+8-29
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func main() {
3737
checkConnectSettings()
3838

3939
// The main process of getting data from GitHub API and store it into MySQL, PostgreSQL, MongoDB databases.
40+
4041
fetchGitHubData(app.Config)
4142

4243
// Delay before the next start (Defined by the DELAY_MINUTES parameter)
@@ -88,6 +89,13 @@ func checkConnectSettings() {
8889

8990
func fetchGitHubData(envVars app.EnvVars) {
9091

92+
if envVars.Postgres.ConnectionStatus != "Connected" &&
93+
envVars.MySQL.ConnectionStatus != "Connected" &&
94+
envVars.MongoDB.ConnectionStatus != "Connected" {
95+
log.Printf("Error: No database connections are established.")
96+
return
97+
}
98+
9199
report := helperReportStart()
92100

93101
// Get all the repositories of the organization.
@@ -612,35 +620,6 @@ func MongoDBprocessPulls(envVars app.EnvVars, allRepos []*github.Repository, all
612620

613621
log.Printf("Databases: MongoDB: Start")
614622

615-
admin_db := client.Database("admin") // используем базу данных admin
616-
617-
// Check and set profiling level
618-
var profilingLevel bson.M
619-
err = admin_db.RunCommand(ctx, bson.D{{Key: "profile", Value: -1}}).Decode(&profilingLevel)
620-
if err != nil {
621-
log.Printf("MongoDB: Get Profiling Level Error: %s", err)
622-
return err
623-
}
624-
625-
if profilingLevel["was"] == int32(0) {
626-
err = admin_db.RunCommand(ctx, bson.D{{Key: "profile", Value: 1}}).Err()
627-
if err != nil {
628-
log.Printf("MongoDB: Set Profiling Level Error: %s", err)
629-
return err
630-
}
631-
}
632-
633-
// Set operation profiling
634-
err = admin_db.RunCommand(ctx, bson.D{
635-
{Key: "profile", Value: 2},
636-
{Key: "slowms", Value: 200},
637-
{Key: "sampleRate", Value: 1.0},
638-
}).Err()
639-
if err != nil {
640-
log.Printf("MongoDB: Set Operation Profiling Error: %s", err)
641-
return err
642-
}
643-
644623
db := client.Database(envVars.MongoDB.DB)
645624
dbCollectionRepos := db.Collection("repositories")
646625
dbCollectionPulls := db.Collection("pulls")

data/init/mongodb/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
db.setProfilingLevel(1);
1+
db.setProfilingLevel(2, {slowms: 0})

data/init/mongodb/mongod.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
operationProfiling:
22
mode: all
33
slowOpThresholdMs: 200
4-
rateLimit: 100
4+
rateLimit: 100 # (Only available with Percona Server for MongoDB.)

data/init/postgresql/init.sql

+7-6
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@ CREATE TABLE IF NOT EXISTS github.pulls (
2222
id BIGINT NOT NULL,
2323
repo VARCHAR(255) NOT NULL,
2424
data JSON,
25-
PRIMARY KEY (id, repo),
26-
INDEX idx_id (id),
27-
INDEX idx_repo (repo)
25+
PRIMARY KEY (id, repo)
2826
);
2927

3028
CREATE TABLE IF NOT EXISTS github.pulls_test (
3129
id BIGINT NOT NULL,
3230
repo VARCHAR(255) NOT NULL,
3331
data JSON,
34-
PRIMARY KEY (id, repo),
35-
INDEX idx_id (id),
36-
INDEX idx_repo (repo)
32+
PRIMARY KEY (id, repo)
3733
);
3834

35+
CREATE INDEX idx_id_pulls ON github.pulls (id);
36+
CREATE INDEX idx_repo_pulls ON github.pulls (repo);
37+
CREATE INDEX idx_id_pulls_test ON github.pulls_test (id);
38+
CREATE INDEX idx_repo_pulls_test ON github.pulls_test (repo);
39+
3940
CREATE TABLE IF NOT EXISTS github.reports_runs (
4041
id SERIAL PRIMARY KEY,
4142
data JSONB

internal/databases/postgres/postgres.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,13 @@ func InitDB(connection_string string) error {
291291
id BIGINT NOT NULL,
292292
repo VARCHAR(255) NOT NULL,
293293
data JSON,
294-
PRIMARY KEY (id, repo),
295-
INDEX idx_id (id),
296-
INDEX idx_repo (repo)
294+
PRIMARY KEY (id, repo)
297295
);
298296
CREATE TABLE IF NOT EXISTS github.pulls_test (
299297
id BIGINT NOT NULL,
300298
repo VARCHAR(255) NOT NULL,
301299
data JSON,
302-
PRIMARY KEY (id, repo),
303-
INDEX idx_id (id),
304-
INDEX idx_repo (repo)
300+
PRIMARY KEY (id, repo)
305301
);
306302
CREATE TABLE IF NOT EXISTS github.reports_runs (
307303
id SERIAL PRIMARY KEY,
@@ -311,6 +307,10 @@ func InitDB(connection_string string) error {
311307
id SERIAL PRIMARY KEY,
312308
data JSONB
313309
);
310+
CREATE INDEX idx_id_pulls ON github.pulls (id);
311+
CREATE INDEX idx_repo_pulls ON github.pulls (repo);
312+
CREATE INDEX idx_id_pulls_test ON github.pulls_test (id);
313+
CREATE INDEX idx_repo_pulls_test ON github.pulls_test (repo);
314314
`
315315
err = executeSQL(newDB, schemaSQL)
316316
if err != nil {

k8s/demo-app/values.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ resources:
7272
dataset:
7373
requests:
7474
memory: "4Gi"
75-
cpu: "1"
75+
cpu: "3"
7676
limits:
7777
memory: "4Gi"
78-
cpu: "1"
78+
cpu: "3"
7979
load:
8080
requests:
8181
memory: "2Gi"

0 commit comments

Comments
 (0)