Skip to content

Commit

Permalink
Merge branch 'Fer-monitorizacion' into Pablo-Arreglos
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289432 committed Apr 29, 2024
2 parents c20f613 + 658f724 commit 275f348
Show file tree
Hide file tree
Showing 39 changed files with 37,835 additions and 10,035 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
- develop
- LaraFMz
- Pablo-Arreglos
- Jota
- jota
- Fer-monitorizacion
pull_request:
types: [opened, synchronize, reopened]
jobs:
Expand Down
82 changes: 61 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# e2e-tests:
# needs: [unit-tests]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 20
# - run: npm --prefix userservice/authservice install
# - run: npm --prefix userservice/userservice install
# - run: npm --prefix gatewayservice install
# - run: npm --prefix questionservice install
# - run: npm --prefix webapp install
# - run: npm --prefix webapp run build
# - run: npm --prefix webapp run test:e2e
e2e-tests:
needs: [unit-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix userservice/authservice install
- run: npm --prefix userservice/userservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix questionservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
docker-push-webapp:
name: Push webapp Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -68,7 +68,7 @@ jobs:
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -85,7 +85,7 @@ jobs:
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -102,7 +102,7 @@ jobs:
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Update OpenAPI configuration
Expand All @@ -123,7 +123,7 @@ jobs:
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -134,6 +134,44 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: questionservice
docker-push-grafana:
name: Push grafana service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [ e2e-tests ]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es05a/grafana
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: monitoring/grafana
env:
GF_SECURITY_ADMIN_USER: ${{ secrets.GF_SECURITY_ADMIN_USER }}
GF_SECURITY_ADMIN_PASSWORD: ${{ secrets.GF_SECURITY_ADMIN_PASSWORD }}
GF_SERVER_SERVE_FROM_SUB_PATH: false
docker-push-prometheus:
name: Push prometheus service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [ e2e-tests ]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es05a/prometheus
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: monitoring/prometheus
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
Expand All @@ -143,6 +181,8 @@ jobs:
- docker-push-gatewayservice
- docker-push-questionservice
- docker-push-webapp
- docker-push-grafana
- docker-push-prometheus
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand All @@ -154,4 +194,4 @@ jobs:
wget https://raw.githubusercontent.com/arquisoft/wiq_es05a/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_es05a/master/.env -O .env
docker compose --profile prod down
docker compose --profile prod up -d --pull always
docker compose --profile prod up -d --pull always
29 changes: 16 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:

questionservice:
container_name: questionservice-${teamname:-wiq5a}
image: ghcr.io/arquisoft/wiq_es05a/questionservice:latest
image: ghcr.io/arquisoft/wiq_5a/questionservice:latest
profiles: ["dev", "prod"]
build: ./questionservice
ports:
Expand All @@ -26,7 +26,7 @@ services:

authservice:
container_name: authservice-${teamname:-wiq5a}
image: ghcr.io/arquisoft/wiq_0/authservice:latest
image: ghcr.io/arquisoft/wiq_5a/authservice:latest
profiles: ["dev", "prod"]
build: ./userservice/authservice
depends_on:
Expand All @@ -40,7 +40,7 @@ services:

userservice:
container_name: userservice-${teamname:-wiq5a}
image: ghcr.io/arquisoft/wiq_0/userservice:latest
image: ghcr.io/arquisoft/wiq_5a/userservice:latest
profiles: ["dev", "prod"]
build: ./userservice/userservice
depends_on:
Expand All @@ -54,7 +54,7 @@ services:

gatewayservice:
container_name: gatewayservice-${teamname:-wiq5a}
image: ghcr.io/arquisoft/wiq_0/gatewayservice:latest
image: ghcr.io/arquisoft/wiq_5a/gatewayservice:latest
profiles: ["dev", "prod"]
build: ./gatewayservice
depends_on:
Expand All @@ -73,7 +73,7 @@ services:

webapp:
container_name: webapp-${teamname:-wiq5a}
image: ghcr.io/arquisoft/wiq_es05a/webapp:latest
image: ghcr.io/arquisoft/wiq_5a/webapp:latest
profiles: ["dev", "prod"]
build: ./webapp
depends_on:
Expand All @@ -82,30 +82,33 @@ services:
- "3000:3000"

prometheus:
image: prom/prometheus
image: ghcr.io/arquisoft/wiq_5a/prometheus:latest
container_name: prometheus-${teamname:-wiq5a}
profiles: ["dev"]
build: ./monitoring/prometheus
profiles: ["dev", "prod"]
networks:
- mynetwork
volumes:
- prometheus_data:/prometheus
ports:
- "9090:9090"
depends_on:
- gatewayservice

grafana:
image: grafana/grafana
image: ghcr.io/arquisoft/wiq_5a/grafana:latest
container_name: grafana-${teamname:-wiq5a}
profiles: ["dev"]
build: ./monitoring/grafana
profiles: ["dev", "prod"]
networks:
- mynetwork
volumes:
- grafana_data:/var/lib/grafana
- ./gatewayservice/monitoring/grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_SERVER_HTTP_PORT=9091
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_SECURITY_ADMIN_USER=${GF_SECURITY_ADMIN_USER:-admin}
- GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD:-changeme}
- GF_SERVER_SERVE_FROM_SUB_PATH=${GF_SERVER_SERVE_FROM_SUB_PATH:-true}
ports:
- "9091:9091"
depends_on:
Expand Down
36 changes: 17 additions & 19 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,16 @@ app.post('/login', async (req, res) => {
}
});


function validateCredentials(username, password) {
// Verifica si la contraseña es erronea
if (password.length < 8) {
return false;
}

return true;
}

app.post('/adduser', async (req, res) => {

const isValidUser = validateCredentials(req.body.username, req.body.password);
try {
const { valido, mensajeError } = req.body;

if (!isValidUser) {
// Si las credenciales son inválidas, devuelve un error 401
res.status(401).json({ error: 'Credenciales incorrectas. La contraseña debe contener al menos 8 caracteres' });
return; // Termina la ejecución de la función para evitar ejecutar el código restante
}
if (!valido) {
// Si las credenciales son inválidas, devuelve un error 401
res.status(401).json({ error: mensajeError });
return; // Termina la ejecución de la función para evitar ejecutar el código restante
}

try {
// Forward the add user request to the user service
const userResponse = await axios.post(userServiceUrl+'/adduser', req.body);
res.json(userResponse.data);
Expand Down Expand Up @@ -104,7 +93,16 @@ app.get('/getUserData', async (req, res) => {
const { username } = req.query;
try{
const getUserDataResponse = await axios.get(userServiceUrl+ `/getUserData?username=${username}`)
res.json(getUserDataResponse.data);
res.status(200).json(getUserDataResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
});

app.get('/getUsernames', async (req, res) => {
try{
const getUserDataResponse = await axios.get(userServiceUrl+ `/getUsernames`)
res.status(200).json(getUserDataResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
Expand Down
35 changes: 7 additions & 28 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ describe('Gateway Service', () => {
expect(response.status).toBe(500);
expect(response.body).toEqual({ error: errorMessage });
});

// Test /adduser endpoint
it('deberia añadir usuario correctamente', async () => {
const response = await request(app)
.post('/adduser')
.send({ username: 'newuser', password: 'newpassword' });

// Verificamos que la respuesta tenga un código de estado 200 y un ID de usuario
expect(response.statusCode).toBe(200);
expect(response.body.userId).toBe('mockedUserId');
});

// Probamos con una pregunta errónea
it('debería devolver error con esa pregunta', async () => {
Expand Down Expand Up @@ -205,23 +194,7 @@ describe('Gateway Service', () => {
expect(response.status).toBe(401); // Esperamos un error de solicitud incorrecta
});

/*
it('debería manejar correctamente la carga excesiva', async () => {
// Realizar múltiples solicitudes simultáneas a endpoints diferentes
const promises = [];
for (let i = 0; i < 100; i++) {
promises.push(request(app).post('/login').send({ username: `user${i}`, password: 'password' }));
}
// Esperar a que se completen todas las solicitudes
const responses = await Promise.all(promises);
// Verificar que todas las respuestas tengan el código de estado esperado (200)
responses.forEach(response => {
expect(response.status).toBe(200);
});
});
*/


it('debería devolver un estado de salud "OK"', async () => {
const response = await request(app).get('/health');
Expand All @@ -230,4 +203,10 @@ describe('Gateway Service', () => {
expect(response.status).toBe(200);
expect(response.body).toEqual({ status: 'OK' });
});

it('Debería devolver una lista de nombres de usuario cuando hay usuarios en la base de datos', async () => {
const response = await request(app).get('/getUsernames');
expect(response.status).toBe(200);
});

});
Loading

0 comments on commit 275f348

Please sign in to comment.