mirror of https://github.com/statping/statping
cypress updates, change to SQLite database package and settings,
parent
e6a4dd3e45
commit
1d3418a9f0
|
@ -33,3 +33,4 @@ databases
|
||||||
statping
|
statping
|
||||||
docker
|
docker
|
||||||
tmp
|
tmp
|
||||||
|
/frontend/cypress/screenshots/
|
||||||
|
|
|
@ -10,14 +10,7 @@ import (
|
||||||
|
|
||||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
TIME_NANO = "2006-01-02T15:04:05Z"
|
|
||||||
TIME = "2006-01-02 15:04:05"
|
|
||||||
CHART_TIME = "2006-01-02T15:04:05.999999-07:00"
|
|
||||||
TIME_DAY = "2006-01-02"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var database Database
|
var database Database
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"projectId": "bi8mhr",
|
"projectId": "wmw54a",
|
||||||
"env": {
|
"env": {
|
||||||
"DB_HOST": "localhost",
|
"DB_HOST": "localhost",
|
||||||
"DB_USER": "root",
|
"DB_USER": "root",
|
||||||
|
@ -10,8 +10,8 @@
|
||||||
},
|
},
|
||||||
"baseUrl": "http://localhost:8888",
|
"baseUrl": "http://localhost:8888",
|
||||||
"chromeWebSecurity": false,
|
"chromeWebSecurity": false,
|
||||||
"defaultCommandTimeout": 8000,
|
"defaultCommandTimeout": 15000,
|
||||||
"requestTimeout": 8000,
|
"requestTimeout": 15000,
|
||||||
"watchForFileChanges": false,
|
"watchForFileChanges": false,
|
||||||
"failOnStatusCode": false
|
"failOnStatusCode": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,39 +2,12 @@
|
||||||
|
|
||||||
context('Setup Process', () => {
|
context('Setup Process', () => {
|
||||||
|
|
||||||
// it('should go to setup Statping with Postgres', () => {
|
|
||||||
// cy.visit('http://localhost:8080')
|
|
||||||
// cy.get('select[name=db_connection]').select('postgres')
|
|
||||||
// cy.get('input[name="db_host"]').clear().type(Cypress.env('DB_HOST'))
|
|
||||||
// cy.get('input[name="db_port"]').clear().type('5432')
|
|
||||||
// cy.get('input[name="db_user"]').clear().type(Cypress.env('DB_USER'))
|
|
||||||
// if (Cypress.env('TRAVIS')==="yes") {
|
|
||||||
// cy.get('input[name="db_password"]').clear()
|
|
||||||
// } else {
|
|
||||||
// cy.get('input[name="db_password"]').clear().type(Cypress.env('DB_PASS'))
|
|
||||||
// }
|
|
||||||
// cy.get('input[name="db_database"]').clear().type(Cypress.env('DB_DATABASE'))
|
|
||||||
// cy.get('input[name="project"]').clear().type('Demo Tester')
|
|
||||||
// cy.get('input[name="description"]').clear().type('This is a test from Crypress!')
|
|
||||||
// cy.get('input[name="domain"]').clear().type('http://localhost:8080')
|
|
||||||
// cy.get('input[name="username"]').clear().type('admin')
|
|
||||||
// cy.get('input[name="email"]').clear().type('info@domain.com')
|
|
||||||
// cy.get('input[name="password"]').clear().type('admin')
|
|
||||||
// cy.scrollTo('bottom')
|
|
||||||
// cy.get('#setup_button').click().wait(10000)
|
|
||||||
// cy.get('.header-title').should('contain', 'Demo Tester')
|
|
||||||
// cy.get('.header-desc').should('contain', 'This is a test from Crypress!')
|
|
||||||
// cy.scrollTo('bottom')
|
|
||||||
// cy.get('.service_li').should('have.length', 5)
|
|
||||||
// cy.get('.card').should('have.length', 5)
|
|
||||||
// })
|
|
||||||
|
|
||||||
it('should setup Statping with SQLite', () => {
|
it('should setup Statping with SQLite', () => {
|
||||||
cy.visit('/setup', {failOnStatusCode: false})
|
cy.visit('/setup', {failOnStatusCode: false})
|
||||||
cy.get('#db_connection').select('sqlite')
|
cy.get('#db_connection').select('sqlite')
|
||||||
cy.get('#project').clear().type('Demo Tester')
|
cy.get('#project').clear().type('Demo Tester')
|
||||||
cy.get('#description').clear().type('This is a test from Crypress!')
|
cy.get('#description').clear().type('This is a test from Crypress!')
|
||||||
cy.get('#domain').clear().type('http://localhost:8080')
|
cy.get('#domain').clear().type('http://localhost:8888')
|
||||||
cy.get('#username').clear().type('admin')
|
cy.get('#username').clear().type('admin')
|
||||||
cy.get('#password').clear().type('admin')
|
cy.get('#password').clear().type('admin')
|
||||||
cy.get('#password_confirm').clear().type('admin')
|
cy.get('#password_confirm').clear().type('admin')
|
||||||
|
@ -42,8 +15,12 @@ context('Setup Process', () => {
|
||||||
|
|
||||||
cy.get('#title').should('contain', 'Demo Tester')
|
cy.get('#title').should('contain', 'Demo Tester')
|
||||||
cy.get('#description').should('contain', 'This is a test from Crypress!')
|
cy.get('#description').should('contain', 'This is a test from Crypress!')
|
||||||
cy.get('.list-group').should('have.length', 5)
|
|
||||||
cy.get('.card').should('have.length', 5)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should have sample data', () => {
|
||||||
|
cy.visit('/')
|
||||||
|
cy.get('.card').should('have.length', 5)
|
||||||
|
cy.get('.group_header').should('have.length', 2)
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -52,10 +52,16 @@ context('Groups Tests', () => {
|
||||||
cy.visit('/dashboard/services')
|
cy.visit('/dashboard/services')
|
||||||
cy.get('.sortable_groups > tr').should('have.length', 5)
|
cy.get('.sortable_groups > tr').should('have.length', 5)
|
||||||
|
|
||||||
cy.get('.sortable_groups > tr').eq(0).contains('PRIVATE')
|
cy.get('.sortable_groups > tr').eq(0).contains('PUBLIC')
|
||||||
cy.get('.sortable_groups > tr').eq(0).contains('Test Private Group')
|
cy.get('.sortable_groups > tr').eq(0).contains('Test Group')
|
||||||
cy.get('.sortable_groups > tr').eq(1).contains('PUBLIC')
|
cy.get('.sortable_groups > tr').eq(1).contains('PRIVATE')
|
||||||
cy.get('.sortable_groups > tr').eq(1).contains('Test Group')
|
cy.get('.sortable_groups > tr').eq(1).contains('Test Private Group')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should delete new groups', () => {
|
||||||
|
cy.get('.sortable_groups > tr').eq(0).find('.btn-danger').click()
|
||||||
|
cy.get('.sortable_groups > tr').eq(1).find('.btn-danger').click()
|
||||||
|
cy.get('.sortable_groups > tr').should('have.length', 3)
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,7 +4,6 @@ import "../support/commands"
|
||||||
|
|
||||||
context('Services Tests', () => {
|
context('Services Tests', () => {
|
||||||
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.restoreLocalStorageCache();
|
cy.restoreLocalStorageCache();
|
||||||
});
|
});
|
||||||
|
@ -13,33 +12,6 @@ context('Services Tests', () => {
|
||||||
cy.saveLocalStorageCache();
|
cy.saveLocalStorageCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
// it('should go to setup Statping with Postgres', () => {
|
|
||||||
// cy.visit('http://localhost:8080')
|
|
||||||
// cy.get('select[name=db_connection]').select('postgres')
|
|
||||||
// cy.get('input[name="db_host"]').clear().type(Cypress.env('DB_HOST'))
|
|
||||||
// cy.get('input[name="db_port"]').clear().type('5432')
|
|
||||||
// cy.get('input[name="db_user"]').clear().type(Cypress.env('DB_USER'))
|
|
||||||
// if (Cypress.env('TRAVIS')==="yes") {
|
|
||||||
// cy.get('input[name="db_password"]').clear()
|
|
||||||
// } else {
|
|
||||||
// cy.get('input[name="db_password"]').clear().type(Cypress.env('DB_PASS'))
|
|
||||||
// }
|
|
||||||
// cy.get('input[name="db_database"]').clear().type(Cypress.env('DB_DATABASE'))
|
|
||||||
// cy.get('input[name="project"]').clear().type('Demo Tester')
|
|
||||||
// cy.get('input[name="description"]').clear().type('This is a test from Crypress!')
|
|
||||||
// cy.get('input[name="domain"]').clear().type('http://localhost:8080')
|
|
||||||
// cy.get('input[name="username"]').clear().type('admin')
|
|
||||||
// cy.get('input[name="email"]').clear().type('info@domain.com')
|
|
||||||
// cy.get('input[name="password"]').clear().type('admin')
|
|
||||||
// cy.scrollTo('bottom')
|
|
||||||
// cy.get('#setup_button').click().wait(10000)
|
|
||||||
// cy.get('.header-title').should('contain', 'Demo Tester')
|
|
||||||
// cy.get('.header-desc').should('contain', 'This is a test from Crypress!')
|
|
||||||
// cy.scrollTo('bottom')
|
|
||||||
// cy.get('.service_li').should('have.length', 5)
|
|
||||||
// cy.get('.card').should('have.length', 5)
|
|
||||||
// })
|
|
||||||
|
|
||||||
it('should Login', () => {
|
it('should Login', () => {
|
||||||
cy.visit('/login')
|
cy.visit('/login')
|
||||||
cy.get('#username').clear().type('admin')
|
cy.get('#username').clear().type('admin')
|
||||||
|
|
|
@ -13,33 +13,6 @@ context('Users Tests', () => {
|
||||||
cy.saveLocalStorageCache();
|
cy.saveLocalStorageCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
// it('should go to setup Statping with Postgres', () => {
|
|
||||||
// cy.visit('http://localhost:8080')
|
|
||||||
// cy.get('select[name=db_connection]').select('postgres')
|
|
||||||
// cy.get('input[name="db_host"]').clear().type(Cypress.env('DB_HOST'))
|
|
||||||
// cy.get('input[name="db_port"]').clear().type('5432')
|
|
||||||
// cy.get('input[name="db_user"]').clear().type(Cypress.env('DB_USER'))
|
|
||||||
// if (Cypress.env('TRAVIS')==="yes") {
|
|
||||||
// cy.get('input[name="db_password"]').clear()
|
|
||||||
// } else {
|
|
||||||
// cy.get('input[name="db_password"]').clear().type(Cypress.env('DB_PASS'))
|
|
||||||
// }
|
|
||||||
// cy.get('input[name="db_database"]').clear().type(Cypress.env('DB_DATABASE'))
|
|
||||||
// cy.get('input[name="project"]').clear().type('Demo Tester')
|
|
||||||
// cy.get('input[name="description"]').clear().type('This is a test from Crypress!')
|
|
||||||
// cy.get('input[name="domain"]').clear().type('http://localhost:8080')
|
|
||||||
// cy.get('input[name="username"]').clear().type('admin')
|
|
||||||
// cy.get('input[name="email"]').clear().type('info@domain.com')
|
|
||||||
// cy.get('input[name="password"]').clear().type('admin')
|
|
||||||
// cy.scrollTo('bottom')
|
|
||||||
// cy.get('#setup_button').click().wait(10000)
|
|
||||||
// cy.get('.header-title').should('contain', 'Demo Tester')
|
|
||||||
// cy.get('.header-desc').should('contain', 'This is a test from Crypress!')
|
|
||||||
// cy.scrollTo('bottom')
|
|
||||||
// cy.get('.service_li').should('have.length', 5)
|
|
||||||
// cy.get('.card').should('have.length', 5)
|
|
||||||
// })
|
|
||||||
|
|
||||||
it('should Login', () => {
|
it('should Login', () => {
|
||||||
cy.visit('/login')
|
cy.visit('/login')
|
||||||
cy.get('#username').clear().type('admin')
|
cy.get('#username').clear().type('admin')
|
||||||
|
@ -68,12 +41,11 @@ context('Users Tests', () => {
|
||||||
cy.get('button[type="submit"]').click()
|
cy.get('button[type="submit"]').click()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should confirm new user', () => {
|
// it('should confirm new user', () => {
|
||||||
cy.visit('/dashboard/users')
|
// cy.visit('/dashboard/users')
|
||||||
cy.get('#users_table > tr').should('have.length', 2)
|
// cy.get('#users_table > tr').should('have.length', 2)
|
||||||
cy.get('#users_table > tr').eq(0).contains('admin')
|
// cy.get('#users_table > tr').eq(0).contains('admin')
|
||||||
cy.get('#users_table > tr').eq(1).contains('admin2')
|
// cy.get('#users_table > tr').eq(1).contains('admin2')
|
||||||
})
|
// })
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
"lint": "vue-cli-service lint",
|
"lint": "vue-cli-service lint",
|
||||||
"test": "cross-env NODE_ENV=development mochapack --webpack-config webpack.config.js --require test/setup.js test/**/*.spec.js",
|
"test": "cross-env NODE_ENV=development mochapack --webpack-config webpack.config.js --require test/setup.js test/**/*.spec.js",
|
||||||
"backend-test": "newman run -e ../dev/postman_environment.json --delay-request 500 ../dev/postman.json",
|
"backend-test": "newman run -e ../dev/postman_environment.json --delay-request 500 ../dev/postman.json",
|
||||||
"cypress": "cypress open",
|
"cypress:open": "cypress open",
|
||||||
"e2e": "cypress run --record --key"
|
"cypress:test": "cypress run --record --key 49d99e5e-04c6-46df-beef-54b68e152a4d"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free-solid": "^5.1.0-3",
|
"@fortawesome/fontawesome-free-solid": "^5.1.0-3",
|
||||||
|
|
|
@ -182,86 +182,85 @@
|
||||||
import Api from "../API";
|
import Api from "../API";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'FormService',
|
name: 'FormService',
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
service: {
|
service: {
|
||||||
name: "",
|
name: "",
|
||||||
type: "http",
|
type: "http",
|
||||||
domain: "",
|
domain: "",
|
||||||
group_id: 0,
|
group_id: 0,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
post_data: "",
|
post_data: "",
|
||||||
headers: "",
|
headers: "",
|
||||||
expected: "",
|
expected: "",
|
||||||
expected_status: 200,
|
expected_status: 200,
|
||||||
port: 80,
|
port: 80,
|
||||||
check_interval: 60,
|
check_interval: 60,
|
||||||
timeout: 15,
|
timeout: 15,
|
||||||
permalink: "",
|
permalink: "",
|
||||||
order: 1,
|
order: 1,
|
||||||
verify_ssl: true,
|
verify_ssl: true,
|
||||||
allow_notifications: true,
|
allow_notifications: true,
|
||||||
notify_all_changes: true,
|
notify_all_changes: true,
|
||||||
notify_after: 2,
|
notify_after: 2,
|
||||||
public: true,
|
public: true,
|
||||||
|
},
|
||||||
|
groups: [],
|
||||||
|
}
|
||||||
},
|
},
|
||||||
groups: [],
|
props: {
|
||||||
}
|
in_service: {
|
||||||
},
|
type: Object
|
||||||
props: {
|
}
|
||||||
in_service: {
|
},
|
||||||
type: Object
|
watch: {
|
||||||
}
|
in_service () {
|
||||||
},
|
this.service = this.in_service
|
||||||
watch: {
|
}
|
||||||
in_service() {
|
},
|
||||||
this.service = this.in_service
|
async mounted () {
|
||||||
}
|
if (!this.$store.getters.groups) {
|
||||||
},
|
const groups = await Api.groups()
|
||||||
async mounted() {
|
this.$store.commit('setGroups', groups)
|
||||||
if (!this.$store.getters.groups) {
|
}
|
||||||
const groups = await Api.groups()
|
},
|
||||||
this.$store.commit('setGroups', groups)
|
methods: {
|
||||||
}
|
async saveService () {
|
||||||
},
|
let s = this.service
|
||||||
methods: {
|
this.loading = true
|
||||||
async saveService() {
|
delete s.failures
|
||||||
let s = this.service
|
delete s.created_at
|
||||||
this.loading = true
|
delete s.updated_at
|
||||||
delete s.failures
|
delete s.last_success
|
||||||
delete s.created_at
|
delete s.latency
|
||||||
delete s.updated_at
|
delete s.online_24_hours
|
||||||
delete s.last_success
|
s.check_interval = parseInt(s.check_interval)
|
||||||
delete s.latency
|
s.timeout = parseInt(s.timeout)
|
||||||
delete s.online_24_hours
|
s.port = parseInt(s.port)
|
||||||
s.check_interval = parseInt(s.check_interval)
|
s.notify_after = parseInt(s.notify_after)
|
||||||
s.timeout = parseInt(s.timeout)
|
s.expected_status = parseInt(s.expected_status)
|
||||||
s.port = parseInt(s.port)
|
s.order = parseInt(s.order)
|
||||||
s.notify_after = parseInt(s.notify_after)
|
|
||||||
s.expected_status = parseInt(s.expected_status)
|
|
||||||
|
|
||||||
window.console.log(s)
|
if (s.id) {
|
||||||
|
await this.updateService(s)
|
||||||
if (s.id) {
|
} else {
|
||||||
await this.updateService(s)
|
await this.createService(s)
|
||||||
} else {
|
}
|
||||||
await this.createService(s)
|
const services = await Api.services()
|
||||||
}
|
this.$store.commit('setServices', services)
|
||||||
const services = await Api.services()
|
this.loading = false
|
||||||
this.$store.commit('setServices', services)
|
this.$router.push('/dashboard/services')
|
||||||
this.loading = false
|
},
|
||||||
this.$router.push('/dashboard/services')
|
async createService (s) {
|
||||||
},
|
await Api.service_create(s)
|
||||||
async createService(s) {
|
},
|
||||||
await Api.service_create(s)
|
async updateService (s) {
|
||||||
},
|
await Api.service_update(s)
|
||||||
async updateService(s) {
|
}
|
||||||
await Api.service_update(s)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -14,6 +14,7 @@ require (
|
||||||
github.com/gorilla/mux v1.7.4
|
github.com/gorilla/mux v1.7.4
|
||||||
github.com/jinzhu/gorm v1.9.12
|
github.com/jinzhu/gorm v1.9.12
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.3.0
|
||||||
|
github.com/mattn/go-sqlite3 v2.0.1+incompatible
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/prometheus/common v0.9.1
|
github.com/prometheus/common v0.9.1
|
||||||
github.com/rendon/testcli v0.0.0-20161027181003-6283090d169f
|
github.com/rendon/testcli v0.0.0-20161027181003-6283090d169f
|
||||||
|
|
|
@ -168,9 +168,6 @@ func Router() *mux.Router {
|
||||||
api.Handle("/api/checkin/{api}", authenticated(checkinDeleteHandler, false)).Methods("DELETE")
|
api.Handle("/api/checkin/{api}", authenticated(checkinDeleteHandler, false)).Methods("DELETE")
|
||||||
r.Handle("/checkin/{api}", http.HandlerFunc(checkinHitHandler))
|
r.Handle("/checkin/{api}", http.HandlerFunc(checkinHitHandler))
|
||||||
|
|
||||||
//r.PathPrefix("/").Handler(http.HandlerFunc(indexHandler))
|
|
||||||
//r.Handle("/badge", http.HandlerFunc(badgeHandler)).Methods("GET")
|
|
||||||
|
|
||||||
// Static Files Routes
|
// Static Files Routes
|
||||||
r.PathPrefix("/files/postman.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox())))
|
r.PathPrefix("/files/postman.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox())))
|
||||||
r.PathPrefix("/files/swagger.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox())))
|
r.PathPrefix("/files/swagger.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox())))
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/statping/statping/database"
|
"github.com/statping/statping/database"
|
||||||
|
@ -209,7 +208,6 @@ func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func apiAllServicesHandler(r *http.Request) interface{} {
|
func apiAllServicesHandler(r *http.Request) interface{} {
|
||||||
user := IsUser(r)
|
user := IsUser(r)
|
||||||
fmt.Println("user: ", user)
|
|
||||||
var srvs []services.Service
|
var srvs []services.Service
|
||||||
for _, v := range services.AllInOrder() {
|
for _, v := range services.AllInOrder() {
|
||||||
if !v.Public.Bool && !user {
|
if !v.Public.Bool && !user {
|
||||||
|
|
|
@ -41,7 +41,9 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//sample, _ := strconv.ParseBool(r.PostForm.Get("sample_data"))
|
project := r.PostForm.Get("project")
|
||||||
|
description := r.PostForm.Get("description")
|
||||||
|
domain := r.PostForm.Get("domain")
|
||||||
|
|
||||||
log.WithFields(utils.ToFields(core.App, confgs)).Debugln("new configs posted")
|
log.WithFields(utils.ToFields(core.App, confgs)).Debugln("new configs posted")
|
||||||
|
|
||||||
|
@ -94,11 +96,11 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
notifiers.InitNotifiers()
|
notifiers.InitNotifiers()
|
||||||
|
|
||||||
c := &core.Core{
|
c := &core.Core{
|
||||||
Name: "Statping Sample Data",
|
Name: project,
|
||||||
Description: "This data is only used to testing",
|
Description: description,
|
||||||
//ApiKey: apiKey.(string),
|
//ApiKey: apiKey.(string),
|
||||||
//ApiSecret: apiSecret.(string),
|
//ApiSecret: apiSecret.(string),
|
||||||
Domain: "http://localhost:8080",
|
Domain: domain,
|
||||||
Version: core.App.Version,
|
Version: core.App.Version,
|
||||||
Started: utils.Now(),
|
Started: utils.Now(),
|
||||||
CreatedAt: utils.Now(),
|
CreatedAt: utils.Now(),
|
||||||
|
|
|
@ -72,15 +72,11 @@ func Connect(configs *DbConfig, retry bool) error {
|
||||||
|
|
||||||
log.WithFields(utils.ToFields(dbSession)).Debugln("connected to database")
|
log.WithFields(utils.ToFields(dbSession)).Debugln("connected to database")
|
||||||
|
|
||||||
maxOpenConn := utils.Getenv("MAX_OPEN_CONN", 5)
|
maxOpenConn := utils.Getenv("MAX_OPEN_CONN", 25)
|
||||||
maxIdleConn := utils.Getenv("MAX_IDLE_CONN", 5)
|
maxIdleConn := utils.Getenv("MAX_IDLE_CONN", 25)
|
||||||
maxLifeConn := utils.Getenv("MAX_LIFE_CONN", 2*time.Minute)
|
maxLifeConn := utils.Getenv("MAX_LIFE_CONN", 5*time.Minute)
|
||||||
|
|
||||||
if configs.DbConn == "sqlite3" {
|
dbSession.DB().SetMaxOpenConns(maxOpenConn.(int))
|
||||||
dbSession.DB().SetMaxOpenConns(2)
|
|
||||||
} else {
|
|
||||||
dbSession.DB().SetMaxOpenConns(maxOpenConn.(int))
|
|
||||||
}
|
|
||||||
dbSession.DB().SetMaxIdleConns(maxIdleConn.(int))
|
dbSession.DB().SetMaxIdleConns(maxIdleConn.(int))
|
||||||
dbSession.DB().SetConnMaxLifetime(maxLifeConn.(time.Duration))
|
dbSession.DB().SetConnMaxLifetime(maxLifeConn.(time.Duration))
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/statping/statping/source"
|
"github.com/statping/statping/source"
|
||||||
"github.com/statping/statping/types/notifications"
|
"github.com/statping/statping/types/notifications"
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
|
|
|
@ -2,25 +2,24 @@ package failures
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/prometheus/common/log"
|
|
||||||
"github.com/statping/statping/types"
|
"github.com/statping/statping/types"
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
log = utils.Log
|
||||||
)
|
)
|
||||||
|
|
||||||
func Samples() error {
|
func Samples() error {
|
||||||
tx := db.Begin()
|
|
||||||
sg := new(sync.WaitGroup)
|
|
||||||
|
|
||||||
createdAt := utils.Now().Add(-3 * types.Day)
|
createdAt := utils.Now().Add(-3 * types.Day)
|
||||||
|
|
||||||
for i := int64(1); i <= 4; i++ {
|
for i := int64(1); i <= 4; i++ {
|
||||||
sg.Add(1)
|
tx := db.Begin()
|
||||||
|
|
||||||
f1 := &Failure{
|
f1 := &Failure{
|
||||||
Service: i,
|
Service: i,
|
||||||
|
@ -38,25 +37,20 @@ func Samples() error {
|
||||||
|
|
||||||
log.Infoln(fmt.Sprintf("Adding %v Failure records to service", 400))
|
log.Infoln(fmt.Sprintf("Adding %v Failure records to service", 400))
|
||||||
|
|
||||||
go func() {
|
for fi := 0.; fi <= float64(400); fi++ {
|
||||||
defer sg.Done()
|
createdAt = createdAt.Add(35 * time.Minute)
|
||||||
for fi := 0.; fi <= float64(400); fi++ {
|
failure := &Failure{
|
||||||
createdAt = createdAt.Add(35 * time.Minute)
|
Service: i,
|
||||||
failure := &Failure{
|
Issue: "testing right here",
|
||||||
Service: i,
|
CreatedAt: createdAt.UTC(),
|
||||||
Issue: "testing right here",
|
|
||||||
CreatedAt: createdAt.UTC(),
|
|
||||||
}
|
|
||||||
|
|
||||||
tx = tx.Create(&failure)
|
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
|
||||||
sg.Wait()
|
|
||||||
|
|
||||||
if err := tx.Commit().Error(); err != nil {
|
tx = tx.Create(&failure)
|
||||||
log.Error(err)
|
}
|
||||||
return err
|
if err := tx.Commit().Error(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var SampleHits = 99900.
|
var SampleHits = 99900.
|
||||||
|
|
Loading…
Reference in New Issue