How to log with Serilog to a remote server? - kubernetes

I'm writing a .NET Core 6 Web API and decided to use Serilog for logging.
This is how I configured it in appsettings.json:
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3}] {Username} {Message:lj}{NewLine}{Exception}"
}
}
]
}
This is working fine, it's logging inside a logs folder in the root.
Now I've deployed my API to a Staging K8s cluster and don't want my logs to be stored on the pod but rather on the Staging server. Is it possible? I can't find many useful posts about it, so I assume there is a better way to achieve it.

Based on Panagiotis' 2nd suggestion I spent like a week to try to set up Elasticsearch with Fluentd and Kibana with no success.
Turned out, that the simplest and easiest solution was his 1st one: all I needed was a PersistentVolume and a PersistentVolumeClaim. This post helped me with the setup: How to store my pod logs in a persistent storage?

Related

Swagger-ui on GKE 1.9

I am running a kubernetes cluster on GKE. I have been told that Kubernetes API server comes integrated with the Swagger UI and the UI is a friendly way to explore the apis. However, I am not sure how to enable this on my cluster. Any guidance is highly appreciated. Thanks!
I've researched a bit regarding your question, and I will share with you what I discovered.
This feature is not enabled by default on every Kubernetes installation and you would need to enable the swagger-ui through the flag enable-swagger-ui and I believe this was what you where looking for.
--enable-swagger-ui Enables swagger ui on the apiserver at /swagger-ui.
The issue is that I believe it is not enabled for Google Kubernetes engine and the master node in Google Kubernates Engine does not serve any request for this resource and the port appears to be close and since it is managed I believe it cannot be enabled.
However according to documentation the master should expose a series of resources giving you the possibility to access the API documentation and render them with the tool you prefer. This is the case and the following files are available:
https://master-ip/swagger.json (you can get the master IP running $ kubectl cluster-info)
{"swagger": "2.0",
"info": {
"title": "Kubernetes",
"version": "v1.9.3"
},
"paths": {
"/api/": {
"get": {
...
https://master-ip/swaggerapi
{"swaggerVersion": "1.2",
"apis": [
{
"path": "/version",
"description": "git code version from which this is built"
},
{
"path": "/apis",
"description": "get available API versions"
},
...
According to this blog post from Kuberntes you could make use of this file:
From kuber-apiserver/swagger.json. This file will have all enabled GroupVersions routes and models and would be most up-to-date file with an specific kube-apiserver. [...] There are numerous tools that works with this spec. For example, you can use the swagger editor to open the spec file and render documentation, as well as generate clients; or you can directly use swagger codegen to generate documentation and clients. The clients this generates will mostly work out of the box--but you will need some support for authorisation and some Kubernetes specific utilities. Use python client as a template to create your own client.

Extending S/4HANA OData service to SCP

I want to extend a custom OData service created in a S/4HANA system. I added a Cloud Connector to my machine, but I don't know how to go from there. The idea is that I want people to access the service from SCP and that I don't need multiple accounts accessing the service on the S/4 system, but just the one coming from SCP. Any ideas?
Ok I feel silly doing this but it seems to work. My test is actually inconclusive because I don't have a cloud connector handy, but it works proxy-ing google.
I'm still thinking about how to make it publicly accessible. There might be people with better answers than this.
create the cloud connector destination.
make a new folder in webide
create file neo-app.json.
content:
{
"routes": [{
"path": "/google",
"target": {
"type": "destination",
"name": "google"
},
"description": "google"
}],
"sendWelcomeFileRedirect": false
}
path is the proxy in your app, so myapp.scp-account/google here. the target name is your destination. I called it just google, you'll put your cloud connector destination.
Deploy.
My test app with destination google going to https://www.google.com came out looking like this. Paths are relative so it doesn't work but google seems proxied.
You'll still have to authenticate etc.

dataDisk.image parameter in Azure Resource Template

Is there any Azure Resource Template documentation? I am trying to recreate a VM using Resource Template and the only thing I am missing is creating a data disk from image the same way the OS disk is created. I edited the JSON template:
"dataDisks": [
{
"lun": 0,
"name": "[concat(parameters('virtualMachines_testVM_name'),'-disk-1')]",
"createOption": "FromImage",
"vhd": {
"uri": "[concat('https', '://', parameters('storageAccounts_rmtemplatetest6221copy_name'), '.blob.core.windows.net', concat('/vhds/', parameters('virtualMachines_testVM_name'),'-disk-1-201649102835.vhd'))]"
},
"caching": "ReadWrite"
}
]
But I get following error in Azure when deploying the template
Required parameter 'dataDisk.image' is missing
So far the only way I got to recreate the data disk was to delete above code from the JSON template and then use Powershell after the machine is created without the data disk, but I would like to automate deployment with resource template only.
In the Azure quick start templates you can find JSON template for creating VM using custom images, including Data disks:
https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-user-image-data-disks
Just one very important note - the targed storage account should be same account where your VHDs reside.
There is no standing documentation on the JSON Schema. The best source is to check out the Schema itself, so:
https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json
http://schema.management.azure.com/schemas/2015-08-01/Microsoft.Compute.json#/resourceDefinitions/virtualMachine
UPDATE
When you create VM based on custom image, including data disks, you must create the entire VM in the same storage account where your custom data disks reside. There is no option, as of today (2016-05-10) to instruct ARM to copy VHDs across storage accounts.
This all was, if you want to create a VM from custom image with Data Disks.
If you just want to create the VM with new, empty data disks, then you can use the following quick start template:
https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-multiple-data-disk
where you only define the desired size of the data disks and where they should be stored.
The problem you are having is that you have the template configured to make a copy of an image, and you have no image specified.
You need to either set the createOption to fromImage, and specify an image
"dataDisks": [
{
"name": "[concat(variables('vmName'),'-dataDisk')]",
"lun": 0,
"createOption": "FromImage",
"image": {
"uri": "[variables('dataDiskUrl')]"
},
"vhd": {
"uri": "[variables('dataDiskVhdName')]"
}
}
],
or, if you just want to use an existing disk, you can use attach, (you can also use empty in this configuration, and it will create an empty disk)
"dataDisks": [
{
"name": "[concat(variables('vmName'),'-dataDisk')]",
"lun": 0,
"createOption": "attach",
"vhd": {
"uri": "[variables('dataDiskVhdName')]"
}
}
],

Telescope / Meteor deployment using meteor UP on MongoDB url mup.json configuration

I am new developing Meteor apps and I just set up a Telescope blog which is based in Meteor.
I want to deploy it in my own hosting (a droplet at Digital ocean) using "Meteor Up" but I dont know how to configure the "MONGO_URL" and "MAIL_URL" in the mup.json file.
Everything was set up transparently in local so I have no clue where is the DB and who is the user or the password... Any help or orientation where I should look up?
Here a snippet of my mup.json file:
{
"env": {
"PORT": 80,
"ROOT_URL": "",
"MONGO_URL": "mongodb://:#:/App",
"MAIL_URL": "smtp://postmaster%40myapp.mailgun.org:adj87sjhd7s#smtp.mailgun.org:587/"
},
Remove the mongo_url and it will use an internal mongo server. (I am sure of this)
You will need to apply for a free account at mailgun and use your api key here.
(guessing here) To get started, try eliminating that key as well and you may be fine.
{ "env": { "PORT": 80, "ROOT_URL": "" },

How to upload user picture in moodle from other system using web service

I have Moodle & Drupal integrated system, Drupal is primary, user is created in drupal first then it will create in moodle via web services, but I am not able to carry user picture from drupal to moodle, I don't want core fixes, need clean and systematically solution for it.
Can anyone help me?
Unfortunately there isn't an appropriate web service in core which supports this at the moment. You can see web services documented in your Moodle install in Home ▶ Site administration ▶ Plugins ▶ Web services ▶ API Documentation.
There are many ways to support this with plugins, but since you do not seem keen to go down this route, have your considered using Gravatar as a solution? There are docs on how to set this up: http://docs.moodle.org/25/en/Roles_settings#Enable_Gravatar
the first step upload the picture
localhost/moodle/webservice/upload.phptoken=9f47591ed3f6cc53720f0dc4e81&filearea=draft
Params:-
token=9f47591ed3f6cc53720f0dc4e81
filearea=draft
then you will get a response like
[
{
"component": "user",
"contextid": 5,
"userid": "2",
"filearea": "draft",
"filename": "Ali Hasans Resume.pdf",
"filepath": "/",
"itemid": 560134043,
"license": "unknown",
"author": "Admin User",
"source": "O:8:\"stdClass\":1:{s:6:\"source\";s:21:\"Ali Hasans Resume.pdf\";}"
}
]
second step
update the profile picture
localhost/moodle/webservice/rest/server.php?moodlewsrestformat=json&draftitemid=560134043&wsfunction=core_user_update_picture&wstoken=9f47591ed3f6cc53720f0dc4e81
params
moodlewsrestformat=json
draftitemid=560134043 this "draftitemid" comes from upload.php response
wsfunction=core_user_update_picture
wstoken=9f47591ed3f6cc53720f0dc4e81
if it's a success then the response will like
{
"success": true,
"profileimageurl": "http://localhost/moodle/theme/image.php/alpha/core/1609845491/u/f1",
"warnings": []
}
here I get this idea https://tracker.moodle.org/browse/MDL-56070