GithubHelp home page GithubHelp logo

Comments (2)

breaker-of-stone avatar breaker-of-stone commented on June 18, 2024

Re [1], [2] it's not the lack of a database.

mysql> select * from user;
+-------+-------------------+-----------+
| id    | email             | password  |
+-------+-------------------+-----------+
| auser | [email protected] | apassword |
+-------+-------------------+-----------+

$ curl -u auser:apassword -iX "POST" "http://localhost:8080/v1/user" -H 'Content-Type: application/json'  -H 'Accept: application/json' -d $'{  "email": "[email protected]",  "first_name": "Ozzy",  "last_name": "Osbourne",  "password": "bateater666"}'
HTTP/1.1 500 Internal Server Error
Access-Control-Allow-Headers: Accept, Authorization, Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Fri, 11 Feb 2022 03:47:41 GMT
Content-Length: 17

Error adding user%

--- and ---
2022/02/11 11:47:41 Error 1045: Access denied for user 'clean_architecture_go_v2'@'localhost' (using password: YES)
[negroni] 2022-02-11T11:47:41+08:00 | 500 | 	 81.754036ms | localhost:8080 | POST /v1/user

=:-o

from clean-architecture-go-v2.

breaker-of-stone avatar breaker-of-stone commented on June 18, 2024

Answers:

[1] & [2] The database connection has been hijacked by an unrelated MySQL instance.
Improvement Suggestions below.

Details:

API authentication errors continue, despite using the (config sourced) credentials which work interactively in the Docker console shell.

ps aux |grep mysql  
    # reveals an obsolete mysqld instance, which is stealing the queries to port 3306.
    # Note that mysql container in Docker indicates in Docker UI that it has attached to port 3306, yet ...
    # Docker log reports (amongst a mass of irrelevant entries):  [Note] Aborted connection 8 to db: 'clean_architecture_go_v2' user: 'clean_architecture_go_v2' host: 'localhost' (Got timeout reading communication packets) - not exactly a definitive error :(

brew services stop mysql
    # confirm with ps, brew services lis,  lanchctl list

In Docker UI restart mysql container.

[6] Next issue: List Users Curl query returns a 500, however the SQL error is more diagnostic:

2022/02/12 11:03:57 In api/handler.user.go/listUsers:26
2022/02/12 11:03:57 ListUsers error:  sql: Scan error on column index 0, name "id": Scan: invalid UUID length: 5
[negroni] 2022-02-12T11:03:57+08:00 | 500 | 	 10.367251ms | localhost:8080 | GET /v1/user

It turns out that the id is not simply varchar(50) as specified in the initdb.sql script. It contains a UUID that is generated at user creation time. So ...

Curl to create a user.
Curl to list users again. Success!

Improvement Suggestions

  1. 'make test' clearly does no database write/read tests. Add some, even if as a new Make target.
  2. the /ping route could be upgraded to a /smoketest function that does an ephemeral database connection test.
  3. MySQL errors are not identified as such - prefix 'Error 1045: Access denied' with a token to indicate message originates from database driver, so it is not mis-perceived as an HTTP auth issue.
  4. Provide a single paragraph description of the engineering architecture - API code, database, Prometheus, Grafana - what feeds what to what, and where to find the logs!

Onward and Downward ! 😧

from clean-architecture-go-v2.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.