Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions toolchain/arangoproxy/cmd/configs/local.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
webserver: ':8080'
logFile: log.txt
datasetsFile: '../internal/utils/datasets.json'
cache: '/home/site/data/'
repositories:
- name: stable
type: single
version: "3.12"
url: http://192.168.129.2:8529
- name: stable
type: cluster
version: "3.12"
url: http://192.168.129.3:8529
debug: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setting this option to true enable more logging than before and leaving it to false log the same amount of information as before, or does false log less information than before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set to false will log the same info we see now. True will add more info on top of what we have now

repositories: []
13 changes: 1 addition & 12 deletions toolchain/arangoproxy/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,12 @@ func init() {
models.Conf.Override = strings.ReplaceAll(override, ",", "|")

models.Logger.Printf(startupBanner)
models.Logger.Printf("./arangoproxy -help for help usage\n\n")
models.Logger.Printf("Init Setup\n")

if help {
models.Logger.Printf("Usage: ...\n")
os.Exit(0)
}
models.Logger.Printf("Configuration:\n%v\n", models.Conf)

models.Logger.Printf("Setup Done\n---------\n")
models.Logger.Printf("Configuration:\n%s\n", models.Conf.String())

}

func main() {
models.Logger.Printf("Available endpoints:\n - /js\n - /aql\n - /curl\n - /openapi\n")
models.Logger.Printf("Starting Server at :8080\n")

if useServers {
internal.InitRepositories()
models.Logger.Printf("[INIT] Repositories Init Done")
Expand Down
1 change: 1 addition & 0 deletions toolchain/arangoproxy/internal/arangosh/arangosh.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func ExecRoutine(example chan map[string]interface{}, outChannel chan string) {

func Exec(exampleName string, code, filepath string, repository models.Repository) (output string) {
code = format.AdjustCodeForArangosh(code)
models.Logger.Debug("[%s] [arangosh.Exec] Injecting Code:\n%s", exampleName, code)

cmd := []byte(code)
_, err := repository.StdinPipe.Write(cmd)
Expand Down
9 changes: 8 additions & 1 deletion toolchain/arangoproxy/internal/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func SaveCachedExampleResponse(chnl chan map[string]interface{}) error {
entryName := fmt.Sprintf("%s_%s", exampleResponse.Options.Name, exampleResponse.Options.Type)
responseHash, err := utils.EncodeToBase64(exampleResponse)

models.Logger.Debug("[%s] Saving To Cache:\nInput Hash: %s\nOutput Hash:%s", entryName, requestHash, responseHash)

newCacheEntry := make(map[string]map[string]string)
newCacheEntry[entryName] = make(map[string]string)
newCacheEntry[entryName]["request"] = requestHash
Expand All @@ -34,7 +36,12 @@ func SaveCachedExampleResponse(chnl chan map[string]interface{}) error {
cache[entryName] = newCacheEntry[entryName]
cacheJson, _ := json.MarshalIndent(cache, "", "\t")
err = os.WriteFile(cacheFilepath, cacheJson, 0644)

if err != nil {
models.Logger.Printf("[%s] [ERROR] Error saving cache: %s", err.Error())
models.Logger.Summary("<li><error code=9><strong>%s</strong><strong> ERROR Saving Cache: %s</strong></error>", exampleResponse.Options.Name, err.Error())
} else {
models.Logger.Debug("[%s] Cache Saved", err)
}
}
}
}
3 changes: 1 addition & 2 deletions toolchain/arangoproxy/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

func InitRepositories() {
models.Repositories = make(map[string]models.Repository)
fmt.Printf("Repositories found in config file %s\n", models.Conf.Repositories)
var wg sync.WaitGroup

for _, repo := range models.Conf.Repositories {
Expand Down Expand Up @@ -55,5 +54,5 @@ func openRepoStream(repository *models.Repository) {

repository.StdinPipe = stdin
repository.StdoutPipe = stdout
models.Logger.Printf("[openRepoStream] Done - Streams: \n%s\n%s", repository.StdinPipe, repository.StdoutPipe)
models.Logger.Printf("[openRepoStream] Opened Stream for %s succesfully", repository.Version)
}
6 changes: 6 additions & 0 deletions toolchain/arangoproxy/internal/models/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"fmt"
"os"

"gopkg.in/yaml.v3"
Expand All @@ -10,6 +11,7 @@ type Config struct {
Repositories []Repository `yaml:"repositories"` // ArangoDB instances
Cache string `yaml:"cache"` // Cache configuration
Datasets string `yaml:"datasetsFile"`
Debug bool `yaml:"debug"`
Override string `yaml:"-"`
}

Expand All @@ -24,3 +26,7 @@ func LoadConfig(file string) error {
err = yaml.Unmarshal(fileStream, &Conf)
return err
}

func (c Config) String() string {
return fmt.Sprintf(" Cache: %s\n Datasets: %s\n Debug: %t\n Override: %s\n Repositories: %s", c.Cache, c.Datasets, c.Debug, c.Override, c.Repositories)
}
17 changes: 4 additions & 13 deletions toolchain/arangoproxy/internal/models/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@ import (
"gopkg.in/yaml.v3"
)

type ExampleType string
type RenderType string

const (
JS ExampleType = "js"
AQL ExampleType = "aql"
HTTP ExampleType = "http"

INPUT RenderType = "input"
OUTPUT RenderType = "output"
INPUT_OUTPUT RenderType = "input/output"
)

// @Example represents an example request to be supplied to an arango instance
type Example struct {
Type ExampleType `json:"type"`
Options ExampleOptions `json:"options"` // The codeblock yaml part
Code string `json:"code"`
Repository Repository `json:"-"`
Expand Down Expand Up @@ -99,7 +93,9 @@ func ParseExample(request io.Reader, headers http.Header) (Example, error) {

code := strings.Replace(string(decodedRequest), string(options), "", -1)

return Example{Type: "", Options: optionsYaml, Code: code, Base64Request: string(req)}, nil
Logger.Debug("[%s] Example Information:\n%s", optionsYaml.Name, optionsYaml.String())

return Example{Options: optionsYaml, Code: code, Base64Request: string(req)}, nil
}

func (r Example) String() string {
Expand All @@ -112,12 +108,7 @@ func (r Example) String() string {
}

func (r ExampleOptions) String() string {
j, err := json.Marshal(r)
if err != nil {
return ""
}

return string(j)
return fmt.Sprintf("Type: %s\nVersion: %s\nSaveCache: %s\nPosition: %s\n", r.Type, r.Version, r.SaveCache, r.Position)
}

type ExampleResponse struct {
Expand Down
8 changes: 7 additions & 1 deletion toolchain/arangoproxy/internal/models/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ func init() {
summaryWriter := io.Writer(logFile)

Logger = new(ArangoproxyLogger)
Logger.logger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
Logger.logger = log.New(os.Stdout, "", 0)
Logger.summary = log.New(summaryWriter, "", 0)
}

func (l *ArangoproxyLogger) Printf(s string, args ...any) {
l.logger.Printf(s, args...)
}

func (l *ArangoproxyLogger) Debug(s string, args ...any) {
if Conf.Debug {
l.logger.Printf("[DEBUG] "+s+"\n", args...)
}
}

func (l *ArangoproxyLogger) Summary(s string, args ...any) {
s = strings.ReplaceAll(s, "\n", "\n<br>")
l.summary.Printf(s+"<br>", args...)
Expand Down
1 change: 0 additions & 1 deletion toolchain/arangoproxy/internal/models/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type Repository struct {
var Repositories map[string]Repository

func GetRepository(typ, version string) (Repository, error) {
Logger.Printf("Executing on server %s %s", typ, version)
if repository, exists := Repositories[fmt.Sprintf("%s_%s", typ, version)]; exists {
return repository, nil
}
Expand Down
8 changes: 8 additions & 0 deletions toolchain/arangoproxy/internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type JSService struct{}

func (service JSService) Execute(request models.Example, cacheChannel chan map[string]interface{}, exampleChannel chan map[string]interface{}, outputChannel chan string) (res models.ExampleResponse) {
repository, err := models.GetRepository(request.Options.Type, request.Options.Version)
models.Logger.Debug("[%s] Choosen Repository: %s", request.Options.Name, repository.Version)
if err != nil {
responseMsg := fmt.Sprintf("A server for version %s has not been used during generation", request.Options.Version)
res = *models.NewExampleResponse(request.Code, responseMsg, request.Options)
Expand All @@ -69,7 +70,9 @@ var curlFormatter = format.CurlFormatter{}

func (service CurlService) Execute(request models.Example, cacheChannel chan map[string]interface{}, exampleChannel chan map[string]interface{}, outputChannel chan string) (res models.ExampleResponse, err error) {
commands := curlFormatter.FormatCommand(request.Code)

repository, err := models.GetRepository(request.Options.Type, request.Options.Version)
models.Logger.Debug("[%s] Choosen Repository: %s", request.Options.Name, repository.Version)
if err != nil {
responseMsg := fmt.Sprintf("A server for version %s has not been used during generation", request.Options.Version)
res = *models.NewExampleResponse(request.Code, responseMsg, request.Options)
Expand Down Expand Up @@ -98,7 +101,9 @@ var AQLFormatter = format.AQLFormatter{}

func (service AQLService) Execute(request models.Example, cacheChannel chan map[string]interface{}, exampleChannel chan map[string]interface{}, outputChannel chan string) (res models.AQLResponse) {
commands := AQLFormatter.FormatRequestCode(request.Code, request.Options.BindVars)

repository, err := models.GetRepository(request.Options.Type, request.Options.Version)
models.Logger.Debug("[%s] Choosen Repository: %s", request.Options.Name, repository.Version)
if err != nil {
responseMsg := fmt.Sprintf("A server for version %s has not been used during generation", request.Options.Version)
res.ExampleResponse.Input, res.ExampleResponse.Options, res.ExampleResponse.Output = request.Code, request.Options, responseMsg
Expand Down Expand Up @@ -167,6 +172,9 @@ func (service OpenapiService) ProcessOpenapiSpec(spec map[string]interface{}, he

spec["version"] = version

specDebug, _ := json.Marshal(spec)
models.Logger.Debug("[ProcessOpenapiSpec] Processing Spec %s", specDebug)

path := reflect.ValueOf(spec["paths"].(map[string]interface{})).MapKeys()[0].String()
method := reflect.ValueOf(spec["paths"].(map[string]interface{})[path].(map[string]interface{})).MapKeys()[0].String()
spec["paths"].(map[string]interface{})[path].(map[string]interface{})[method].(map[string]interface{})["summary"] = summary
Expand Down