Added more statistics
This commit is contained in:
@@ -2965,6 +2965,11 @@ func handleNewHook(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = increaseStatisticsField(ctx, "total_workflow_triggers", requestdata.Workflow, 1)
|
||||
if err != nil {
|
||||
log.Printf("Failed to increase total workflows: %s", err)
|
||||
}
|
||||
|
||||
log.Println("Generating new hook")
|
||||
resp.WriteHeader(200)
|
||||
resp.Write([]byte(`{"success": true}`))
|
||||
|
||||
+37
-51
@@ -325,7 +325,7 @@ func increaseStatisticsField(ctx context.Context, fieldname, id string, amount i
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Stats: %#v", statisticsItem)
|
||||
//log.Printf("Stats: %#v", statisticsItem)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -936,6 +936,10 @@ func setNewWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
log.Printf("Saved new workflow %s with name %s", workflow.ID, workflow.Name)
|
||||
err = increaseStatisticsField(ctx, "total_workflows", workflow.ID, 1)
|
||||
if err != nil {
|
||||
log.Printf("Failed to increase total workflows: %s", err)
|
||||
}
|
||||
|
||||
if len(workflow.Actions) == 0 {
|
||||
workflow.Actions = []Action{}
|
||||
@@ -1047,6 +1051,11 @@ func deleteWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
log.Printf("Failed to delete email sub: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = increaseStatisticsField(ctx, "total_workflow_triggers", workflow.ID, -1)
|
||||
if err != nil {
|
||||
log.Printf("Failed to increase total workflows: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME - maybe delete workflow executions
|
||||
@@ -1059,6 +1068,11 @@ func deleteWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = increaseStatisticsField(ctx, "total_workflows", fileId, -1)
|
||||
if err != nil {
|
||||
log.Printf("Failed to increase total workflows: %s", err)
|
||||
}
|
||||
|
||||
//memcacheName := fmt.Sprintf("%s_%s", user.Username, fileId)
|
||||
//memcache.Delete(ctx, memcacheName)
|
||||
//memcacheName = fmt.Sprintf("%s_workflows", user.Username)
|
||||
@@ -1109,31 +1123,13 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
ctx := context.Background()
|
||||
log.Println("GetWorkflow start")
|
||||
|
||||
tmpworkflow := Workflow{}
|
||||
// memcacheName := fmt.Sprintf("%s_%s", user.Username, fileId)
|
||||
// if item, err := memcache.Get(ctx, memcacheName); err == memcache.ErrCacheMiss {
|
||||
// // Not in cache
|
||||
// log.Printf("User workflow %s not in cache.", memcacheName)
|
||||
// tmpworkflow, err = getWorkflow(ctx, fileId)
|
||||
// if err != nil {
|
||||
// log.Printf("Failed getting the workflow locally: %s", err)
|
||||
// resp.WriteHeader(401)
|
||||
// resp.Write([]byte(`{"success": false}`))
|
||||
// return
|
||||
// }
|
||||
// } else if err != nil {
|
||||
// log.Printf("Error getting item: %v", err)
|
||||
// } else {
|
||||
// log.Printf("Got workflow %s from cache", fileId)
|
||||
// // FIXME - verify if value is ok? Can unmarshal etc.
|
||||
// err = json.Unmarshal(item.Value, &tmpworkflow)
|
||||
// if err != nil {
|
||||
// log.Printf("Failed unmarshaling allworkflowapps from memcache: %s", err)
|
||||
// resp.WriteHeader(401)
|
||||
// resp.Write([]byte(`{"success": false}`))
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
tmpworkflow, err := getWorkflow(ctx, fileId)
|
||||
if err != nil {
|
||||
log.Printf("Failed getting the workflow locally: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("GetWorkflow end")
|
||||
|
||||
@@ -1145,6 +1141,8 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
//Actions []Action `json:"actions" datastore:"actions,noindex"`
|
||||
|
||||
log.Printf("Hello")
|
||||
body, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
@@ -1179,7 +1177,6 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
log.Println("Pre")
|
||||
for _, action := range workflow.Actions {
|
||||
allNodes = append(allNodes, action.ID)
|
||||
log.Printf("ENV: %s", action.Environment)
|
||||
if action.Environment == "" {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "An environment for %s is required"}`, action.Label)))
|
||||
@@ -1394,30 +1391,12 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
//newbody, err := json.Marshal(workflow)
|
||||
////newbody, err := json.Marshal(workflowapps)
|
||||
//if err != nil {
|
||||
// log.Printf("Failed unmarshalling all apps: %s", err)
|
||||
// resp.WriteHeader(401)
|
||||
// resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed unpacking workflow apps"}`)))
|
||||
// return
|
||||
//}
|
||||
|
||||
//memcacheName = fmt.Sprintf("%s_%s", user.Username, fileId)
|
||||
//item := &memcache.Item{
|
||||
// Key: memcacheName,
|
||||
// Value: newbody,
|
||||
// Expiration: time.Minute * 10,
|
||||
//}
|
||||
//if err := memcache.Add(ctx, item); err == memcache.ErrNotStored {
|
||||
// if err := memcache.Set(ctx, item); err != nil {
|
||||
// log.Printf("Error setting item: %v", err)
|
||||
// }
|
||||
//} else if err != nil {
|
||||
// log.Printf("error adding item: %v", err)
|
||||
//} else {
|
||||
// //log.Printf("Set cache for %s", item.Key)
|
||||
//}
|
||||
totalOldActions := len(tmpworkflow.Actions)
|
||||
totalNewActions := len(workflow.Actions)
|
||||
err = increaseStatisticsField(ctx, "total_workflow_actions", workflow.ID, int64(totalNewActions-totalOldActions))
|
||||
if err != nil {
|
||||
log.Printf("Failed to change total actions data: %s", err)
|
||||
}
|
||||
|
||||
log.Printf("Saved new version of workflow %s", fileId)
|
||||
resp.WriteHeader(200)
|
||||
@@ -3479,6 +3458,13 @@ func handleDeleteHook(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(hook.Workflows) > 0 {
|
||||
err = increaseStatisticsField(ctx, "total_workflow_triggers", hook.Workflows[0], -1)
|
||||
if err != nil {
|
||||
log.Printf("Failed to increase total workflows: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
hook.Status = "stopped"
|
||||
err = setHook(ctx, *hook)
|
||||
if err != nil {
|
||||
|
||||
+2
-2
@@ -38,12 +38,12 @@ import AlertTemplate from "react-alert-template-basic";
|
||||
import { positions, Provider } from "react-alert";
|
||||
|
||||
// Testing - localhost
|
||||
//const globalUrl = "http://192.168.3.6:5001"
|
||||
const globalUrl = "http://192.168.3.6:5001"
|
||||
//console.log("HOST: ", process.env)
|
||||
|
||||
|
||||
// Production - backend proxy forwarding in nginx
|
||||
const globalUrl = window.location.origin
|
||||
//const globalUrl = window.location.origin
|
||||
|
||||
const surfaceColor = "#27292D"
|
||||
const inputColor = "#383B40"
|
||||
|
||||
@@ -626,7 +626,6 @@ const Apps = (props) => {
|
||||
|
||||
const errorText = openApiError.length > 0 ? <div>Error: {openApiError}</div> : null
|
||||
const circularLoader = validation ? <CircularProgress color="primary" /> : null
|
||||
console.log(validation)
|
||||
const modalView = openApiModal ?
|
||||
<Dialog modal
|
||||
open={openApiModal}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, {useState} from 'react';
|
||||
import { useInterval } from 'react-powerhooks';
|
||||
// nodejs library that concatenates classes
|
||||
import classNames from "classnames";
|
||||
// react plugin used to create charts
|
||||
@@ -76,6 +77,7 @@ const Dashboard = (props) => {
|
||||
});
|
||||
}
|
||||
|
||||
// All these are currently tracked.
|
||||
const variables = [
|
||||
"backend_executions",
|
||||
"workflow_executions",
|
||||
@@ -86,19 +88,37 @@ const Dashboard = (props) => {
|
||||
"openapi_apps_created",
|
||||
"total_apps_deleted",
|
||||
"total_webhooks_ran",
|
||||
"total_workflows",
|
||||
"total_workflow_actions",
|
||||
"total_workflow_triggers",
|
||||
]
|
||||
|
||||
if (firstRequest) {
|
||||
setFirstRequest(false)
|
||||
|
||||
const runUpdate = () => {
|
||||
for (var key in variables) {
|
||||
fetchdata(variables[key])
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh every 60 seconds
|
||||
const autoUpdate = 60000
|
||||
const { start, stop } = useInterval({
|
||||
duration: autoUpdate,
|
||||
startImmediate: false,
|
||||
callback: () => {
|
||||
runUpdate()
|
||||
}
|
||||
});
|
||||
|
||||
if (firstRequest) {
|
||||
setFirstRequest(false)
|
||||
start()
|
||||
runUpdate()
|
||||
}
|
||||
|
||||
|
||||
const newdata = Object.getOwnPropertyNames(stats).length > 0 ?
|
||||
<div>
|
||||
Autoupdate every {autoUpdate/1000} seconds
|
||||
{variables.map(data => {
|
||||
if (stats[data] === undefined || stats[data] === null) {
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user