Setting Stackdriver Logging log level for Docker's gcplogs log driver - google-app-engine

Docker supported the --log-driver=gcplogs option to log a Google Compute Engine instance to the Stackdriver Logging service (aka Google Cloud Logging). However, all log entries in the Logs Viewer page at https://console.cloud.google.com/logs have no severity level - the entire log line gets placed in a data field like this:
{
metadata: {
projectId: "my-project"
serviceName: "custom.googleapis.com"
labels: {
custom.googleapis.com/secondary_key: "secondary_key"
custom.googleapis.com/primary_key: "primary_key"
}
timestamp: "2016-05-10T00:07:28.700617425Z"
projectNumber: "12345"
}
insertId: "2016-05-09|17:07:28.706161-07|1.2.3.4|1234"
log: "gcplogs-docker-driver"
structPayload: {
container: {
imageName: "us.gcr.io/my-image/name"
created: "2016-05-09T15:09:15.15158629Z"
name: "/my-container"
id: "7b6f9fa1d7517e6a3004b8fa7e52asdfddd8e63d02e43afb3942681a56f4e"
imageId: "sha256:20605d3fdc700asdfa8b08a4aed1f745a0b5d9a8f08ae0db2f90af0bd093"
}
data: "2016-05-10 00:07:28,700 DEBUG [my-file:191][uWSGIWorker1Core0] Some log message here"
instance: {
zone: "us-east1-b"
name: "broker-1"
id: "12345"
}
}
}
I know that stdout and stderr of a Container get logged by Docker, but how can I configure things (Docker, Compute Engine, Stackdriver Logging) to parse my messages to have a log level?

Related

How to give solr user permissions per collection

Here is the security.json file I generated:
{
"authentication":{
"blockUnknown":true,
"class":"solr.BasicAuthPlugin",
"credentials":{
"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c=",
"project-1":"QUYURq8j9DfpPWo8X9lEhIdNzW/BZUCabISt4C9NSdo= +QBNDGAaKrzYb2tCoKw6YBvZvs40ikPiyeX7kp4foGw=",
"project-2":"LskXmhFtq0Gy2ECt2OjcNDSSAKdMXSOm6kpfGwVXGq4= 0vCTvHC7RYu3sLyEXlfy+xwdmMBRSDlqECP7UeVkFuQ="
}
},
"authorization":{
"class":"solr.RuleBasedAuthorizationPlugin",
"permissions":[
{
"collection":"project-1-collection-1",
"name": "all",
"role":"project-1"
},
{
"name":"all",
"role":"admin"
}
],
"user-role":{
"solr":["admin"],
"project-1":["project-1"]
}
}
}
I would expect that from this configuration:
solr user is the administrator and have access everywhere
project-1 user has only access to project-1-collection-1
project-2 user has no access to anything
But the actual effect is different:
solr user has access everywhere ✓
project-1 user has access to api, but does not have access to GUI of collection-1 ❌
project-2 user has access to collection-1 (it should not) ❌
I am checking the API by running
curl --user "solr:SolrRocks" "http://${HOST}:${PORT}/solr/project-1-collection-1/select?wt=json&q=*:*"
curl --user "project-1:password-1" "http://${HOST}:${PORT}/solr/project-1-collection-1/select?wt=json&q=*:*"
curl --user "project-2:password-1" "http://${HOST}:${PORT}/solr/project-1-collection-1/select?wt=json&q=*:*"
And GUI by accessing following url:
http://localhost:8906/solr/#/project-1-collection-1/query
What am I doing wrong?

AWS Amplify, Amazon Lex v2 and React Native - Error: No value provided for input HTTP label: sessionId

I have difficulties integrating a Amazon Lex v2 chatbot on a React Native app using Amazon Amplify.
I installed aws-amplify dependencies, and on my index.js file added the following lines:
import {Amplify} from 'aws-amplify';
import {AWSLexV2Provider} from '#aws-amplify/interactions';
Amplify.addPluggable(new AWSLexV2Provider());
const interactionsConfig = {
Auth: {
identityPoolId: 'XX-XXXX-X:………',
region: 'east-us-1',
},
Interactions: {
bots: {
// LexV2 Bot
MyChatbotName: {
name: 'MyChatbotName',
aliasId: '---',
botId: '---',
localeId: '---',
region: '---',
providerName: 'AWSLexV2Provider',
},
},
},
};
Amplify.configure(interactionsConfig);
I can call my chatbot using Python Boto3, so all the data I put in interactionsConfig.Interactions.bots should be okay.
But when I try to call my chatbot on App.tsx, with the following code:
async function callChatbot() {
let userInput = 'I would like to have informations about a disease';
// Provide a bot name and user input
const response = await Interactions.send('MyChatbotName', userInput);
// Log chatbot response
console.log(response.message);
}
callChatbot();
I got an error:
WARN Possible Unhandled Promise Rejection (id: 0):
Error: No value provided for input HTTP label: sessionId.
Error: No value provided for input HTTP label: sessionId.
I suppose this is an identification issue, but the identity pool I use is supposed to have full Lex, Amplify and Cognito access…
I changed many settings in identity pool, I even tried to add user pool but still the same error… I already installed react-native-url-polyfill, react-native-get-random-values and uuid to get rid of previous errors.
Do you know what I should do? Thanks! :)

Getting a timeout when i try to add data to mongodb (via mongoose)

I am new to MERN development and I have been trying to add the username, email and password of a user to database but i get this error(when i try to add user after connecting to the database from thunderclient in json format in vscode):
[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./index.js`
Example app listening on port 3000
connected to mongodb successfully
{ name: 'kashish', email: 'mail#mail.com', password: '1234' }
/home/alien/codes/webDev/react/inotebook/backend/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:151
const err = new MongooseError(message);
^
MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/home/alien/codes/webDev/react/inotebook/backend/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:151:23)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)
Node.js v18.7.0
[nodemon] app crashed - waiting for file changes before starting...
The code connects to the database successfully, but when i try to add the user (using thunder client before calling the api) it just shows me the given error here is the code which connects to the database and the one which saves data in database respectively:
const mongoose=require("mongoose")
const mongoUri="mongodb://localhost:27017"
const connectMongo=() => {
mongoose.connect(mongoUri,() => {
console.log("connected to mongodb successfully");
}).catch(error => handleError(error))
}
module.exports=connectMongo;
the code that adds user:
const express=require('express');
const User=require('../models/User');
const router=express.Router();
router.get('/',(req,res) => {
console.log(req.body);
const user=User(req.body);
user.save()
res.send(req.body);
})
module.exports=router;
I tried going through similar issues from the forum but i don't understand any of them, what am i missing?
another edit:
When i tried using async function and added await before user.save(), the response didn't occur, not sure if that is obvious but the user data shows up in console but there happens to be an error during saving data, is it possible that the timeout happens before the data can be saved? i am hosting mongodb on localhost so this is not an internet issue
here is the updated code for auth.js:
const express=require('express');
const User=require('../models/User');
const router=express.Router();
router.get('/',async (req,res) => {
console.log(req.body);
const user=User(req.body);
await user.save()
res.send(req.body);
})
module.exports=router;
updated code of db.js (connecting to database) with error handling:
const mongoose=require("mongoose")
const mongoUri="mongodb://localhost:27017"
const connectMongo=() => {
mongoose.connect(mongoUri).then(
() => console.log('connected')
).catch(e => console.log('error',e))
}
module.exports=connectMongo;
after the above update in code this shows up in a few mins:
Example app listening on port 3000
error MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at Connection.openUri (/home/alien/codes/webDev/react/inotebook/backend/node_modules/mongoose/lib/connection.js:824:32)
at /home/alien/codes/webDev/react/inotebook/backend/node_modules/mongoose/lib/index.js:380:10
at /home/alien/codes/webDev/react/inotebook/backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5
at new Promise (<anonymous>)
at promiseOrCallback (/home/alien/codes/webDev/react/inotebook/backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10)
at Mongoose._promiseOrCallback (/home/alien/codes/webDev/react/inotebook/backend/node_modules/mongoose/lib/index.js:1225:10)
at Mongoose.connect (/home/alien/codes/webDev/react/inotebook/backend/node_modules/mongoose/lib/index.js:379:20)
at connectMongo (/home/alien/codes/webDev/react/inotebook/backend/db.js:5:14)
at Object.<anonymous> (/home/alien/codes/webDev/react/inotebook/backend/index.js:3:1)
at Module._compile (node:internal/modules/cjs/loader:1120:14) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { 'localhost:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
logicalSessionTimeoutMinutes: undefined
},
code: undefined
}
and before you ask, i already ran sudo systemctl start mongodb before starting the app. here is the output of sudo systemctl status mongodb:
● mongodb.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongodb.service; disabled; preset: disabled)
Active: active (running) since Mon 2022-08-22 14:59:01 IST; 24s ago
Docs: https://docs.mongodb.org/manual
Main PID: 5840 (mongod)
Memory: 163.0M
CPU: 857ms
CGroup: /system.slice/mongodb.service
└─5840 /usr/bin/mongod --config /etc/mongodb.conf
error MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
This issue can occur when the MongoDB client is trying to connect to the MongoDB server over IPv6, but the server isn't actually listening on IPv6 (for whatever reason; I think that older versions of the server had to be told to listen on IPv6 but more recent versions should do so automatically, unless it's explicitly turned off).
To force the client to connect over IPv4, use the IPv4 localhost address:
const mongoUri="mongodb://127.0.0.1:27017"

Auth0 returns a 401 on token request. Auth0 logs show login is successful

I'm integrating auth0 from the tutorial into my own application and have encountered a couple of problems with authentication reflected in the auth0 logs.
This occurs on hitting my react login button:
Login.js
import React from "react";
import { useAuth0 } from "#auth0/auth0-react";
import '../components/App.css'
const LoginButton = () => {
const { loginWithRedirect } = useAuth0();
return <button class="btn btn-primary" onClick={() => loginWithRedirect()}>Log In</button>;
};
export default LoginButton;
However on the Auth0 Application logs I see that I am successfully authenticated and I also get a Failed Exchange, Successful Login and a Warning During Login.
Fixed Log: Warning During Login
Here's the text of the log for Warning During Login:
You are using Auth0 development keys which are only intended for use
in development and testing. This connection (google-oauth2) should be
configured with your own Development Keys to enable the consent page
to show your logo instead of Auth0's and to enable SSO for this
connection. AUTH0 DEVELOPMENT KEYS ARE NOT RECOMMENDED FOR PRODUCTION
ENVIRONMENTS. To learn more about Development Keys please refer to
https://auth0.com/docs/connections/social/devkeys.
This was fixed by following these instructions on the Auth0 website. Essentially:
Creating a google project and OAuth credentials
Adding the credentials inside my Auth0 connected apps
Broken: Login Successful
The log shows that it was a successful login. However on my application, I click the Login button and the expected auth0 modal does not appear.
{
"date": "2020-10-14T09:14:06.549Z",
"type": "s",
"connection_id": "",
"client_id": "<MyClientId>",
"client_name": "<MyClientName>",
"ip": "<MyIP>",
"user_agent": "Safari 13.1.2 / Mac OS X 10.15.6",
"details": {
"prompts": [],
"completedAt": 1602666846548,
"elapsedTime": null,
"session_id": "m0AeJer-FhZ0rb9UFPWgvDkvN7MW36h_"
},
"hostname": "<MyHost>",
"user_id": "<MyUserID>",
"user_name": "<MyUserName>",
"auth0_client": {
"name": "auth0-react",
"version": "1.1.0"
},
"log_id": "90020201014091409270008789595401783120816526823843168290",
"_id": "90020201014091409270008789595401783120816526823843168290",
"isMobile": false,
"description": "Successful login"
}
And looking at the response headers in safari, the token request has 401'd
URL: https://<testdomain>.auth0.com/oauth/token
Status: 401
Source: Network
Address: <testaddress>
Initiator:
auth0-spa-js.production.esm.js:15
Fixed Log: Failed Exchange
After ensuring that I was connecting to goole properly I saw that the issue persisted. Looking at the log I get the following under the heading of a Failed Exchange.
{
"date": "2020-10-14T09:14:07.304Z",
"type": "feacft",
"description": "Unauthorized",
"connection_id": "",
"client_id": "<MyClientId>",
"client_name": null,
"ip": "<TheIP>",
"user_agent": "Safari 13.1.2 / Mac OS X 10.15.6",
"details": {
"code": "*************Rw7"
},
"hostname": "<MyHostName>",
"user_id": "",
"user_name": "",
"log_id": "90020201014091410270002070951766882711015226887425228818",
"_id": "90020201014091410270002070951766882711015226887425228818",
"isMobile": false
}
This question fixed the Failed Exchange issue for me. Change your Auth0 Application properties settings to:
Application Type: Regular Web Application
Token Endpoint Authentication Method: None
This however, unearthed a new issue...
Broken Log: Failed Silent Auth
There's a number of fixes I did here so I'll document them in the answer.
Warning During Login
This was fixed by ensuring the my credentials provider had been properly set up. In this case google. For instructions on how to add google as a credentials provider see here.
Failed Exchange
This was fixed by going to the auth0 dashboard application settings and modifying the setting Application Type to Regular Web Application and the setting Token Endpoint Authentication Method to None.
Login Successful (but not really)
This disappeared once I fixed the Failed Exchange above.
Failed Silent Auth
This was never "fixed" and the error still appears on the log. However the comment on this question prompted me to revisit my Allowed Web Origins and Allowed Origins (CORS) on my auth0 to the below:
https://<mydomain>.eu.auth0.com, http://localhost:3000
This was the last issue in the chain and I could now use login and logout as expected.

Internal error during creation of App Engine via deployment manager

I am trying to create an App Engine service via Deployment Manager.
My deployment-manager.yaml file looks like below
imports:
- path: create-app-engine-std.py
resources:
- name: create-app-engine-std-app
type: create-app-engine-std.py
properties:
name: app-engine-std-app
appsId: projectId
zip:
sourceUrl: https://storage.googleapis.com/some-bucket/xyz.zip
filesCount: 2
version: v1
runtime: nodejs8
My create-app-engine-std.py look like below
def GenerateConfig(cxt):
deployment = {}
if cxt.properties['zip']:
deployment = {
'zip': {
'sourceUrl': cxt.properties['zip']['sourceUrl'],
'filesCount': cxt.properties['zip']['filesCount']
}
}
resources = [{
'type': 'gcp-types/appengine-v1:apps.services.versions',
'name': 'app-engine-std-app',
'properties': {
'servicesId': 'app-engine-std-test-app',
'appsId': cxt.properties['appsId'],
'deployment': deployment,
'runtime': cxt.properties['runtime'],
'threadsafe': True,
'id': cxt.properties['version']
}
}]
return {'resources': resources}
When I execute the deployment command I get following error
message: '{"ResourceType":"gcp-types/appengine-v1:apps.services.versions","ResourceErrorCode":"500","ResourceErrorMessage":"An
internal error occurred."}'
I tried using the apps.services.versions.create API but I always get following error although I am owner of the project
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
Can someone guide me why I am getting the internal error and why can't I use the API. Thanks...

Resources