diff --git a/toolchain/arangoproxy/cmd/configs/local.yaml b/toolchain/arangoproxy/cmd/configs/local.yaml index 451bd39560..d4b28fe6aa 100644 --- a/toolchain/arangoproxy/cmd/configs/local.yaml +++ b/toolchain/arangoproxy/cmd/configs/local.yaml @@ -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 +repositories: [] \ No newline at end of file diff --git a/toolchain/arangoproxy/cmd/main.go b/toolchain/arangoproxy/cmd/main.go index 8036c0ec92..35df82f7eb 100644 --- a/toolchain/arangoproxy/cmd/main.go +++ b/toolchain/arangoproxy/cmd/main.go @@ -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") diff --git a/toolchain/arangoproxy/internal/arangosh/arangosh.go b/toolchain/arangoproxy/internal/arangosh/arangosh.go index 5cf5ff6772..6e97556eba 100644 --- a/toolchain/arangoproxy/internal/arangosh/arangosh.go +++ b/toolchain/arangoproxy/internal/arangosh/arangosh.go @@ -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) diff --git a/toolchain/arangoproxy/internal/cache.go b/toolchain/arangoproxy/internal/cache.go index 5ec423fb3a..a6f944688a 100644 --- a/toolchain/arangoproxy/internal/cache.go +++ b/toolchain/arangoproxy/internal/cache.go @@ -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 @@ -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("
  • %s ERROR Saving Cache: %s", exampleResponse.Options.Name, err.Error()) + } else { + models.Logger.Debug("[%s] Cache Saved", err) + } } } } diff --git a/toolchain/arangoproxy/internal/init.go b/toolchain/arangoproxy/internal/init.go index bf7223505b..b3bf51f36e 100644 --- a/toolchain/arangoproxy/internal/init.go +++ b/toolchain/arangoproxy/internal/init.go @@ -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 { @@ -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) } diff --git a/toolchain/arangoproxy/internal/models/config.go b/toolchain/arangoproxy/internal/models/config.go index a3695da42d..64be621956 100644 --- a/toolchain/arangoproxy/internal/models/config.go +++ b/toolchain/arangoproxy/internal/models/config.go @@ -1,6 +1,7 @@ package models import ( + "fmt" "os" "gopkg.in/yaml.v3" @@ -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:"-"` } @@ -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) +} diff --git a/toolchain/arangoproxy/internal/models/example.go b/toolchain/arangoproxy/internal/models/example.go index b53994dfff..346d032f7a 100644 --- a/toolchain/arangoproxy/internal/models/example.go +++ b/toolchain/arangoproxy/internal/models/example.go @@ -16,14 +16,9 @@ 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" @@ -31,7 +26,6 @@ const ( // @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:"-"` @@ -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 { @@ -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 { diff --git a/toolchain/arangoproxy/internal/models/logger.go b/toolchain/arangoproxy/internal/models/logger.go index 2a43363c8b..38cdb82696 100644 --- a/toolchain/arangoproxy/internal/models/logger.go +++ b/toolchain/arangoproxy/internal/models/logger.go @@ -19,7 +19,7 @@ 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) } @@ -27,6 +27,12 @@ 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
    ") l.summary.Printf(s+"
    ", args...) diff --git a/toolchain/arangoproxy/internal/models/repository.go b/toolchain/arangoproxy/internal/models/repository.go index 56ede4df44..507c919af5 100644 --- a/toolchain/arangoproxy/internal/models/repository.go +++ b/toolchain/arangoproxy/internal/models/repository.go @@ -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 } diff --git a/toolchain/arangoproxy/internal/service/service.go b/toolchain/arangoproxy/internal/service/service.go index 95df939b49..efef119996 100644 --- a/toolchain/arangoproxy/internal/service/service.go +++ b/toolchain/arangoproxy/internal/service/service.go @@ -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) @@ -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) @@ -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 @@ -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