Is there a way to know whether Tracer is success fully connected to jaeger backend server in jaegerclientcpp? - c++

In jaeger-client-cpp when I connect my Tracer variable to jaeger backend (I m using jaeger-all-in-one server) then upon successful connection LOG INFO message is shown telling me the connection is successful, but when connection is unsuccessful is just shows LOG ERROR message telling me that connection with server not successful.
So is there any way to check this programatically about the status of connection of Tracer with server.
OS-ubuntu 18.04
jaeger-client-cpp-v0.5.0

#include <jaegertracing/net/IPAddress.h>
#include <jaegertracing/net/Socket.h>
void check(){
try{
jaegertracing::net::Socket socket;
socket.open(AF_INET, SOCK_STREAM);
const std::string serverURL = configuration.sampler().kDefaultSamplingServerURL;
socket.connect(serverURL);
}catch(...){}
}
if it throws error then it is unable to reach host, this method is costly I agree but this is the only viable solution I find

Related

Azure event hub error when debugging with Visual Studio

I have created a azure function with event hub trigger and keep getting this error "The listener for function 'Transfers.OrdersFunction was unable to start. System.Private.CoreLib: One or more errors occurred. (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)." when I run debugger. I've followed this code: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=in-process%2Cfunctionsv2%2Cextensionv5&pivots=programming-language-csharp and I am using Visual Studio 2022
Usually, this problem is related to your dev machine firewall blocking ports 5671 and 5672. Check this out:
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-protocol-guide
If you can’t open those tpc ports, there is a trick for that. Add this to the end of your connection string: TransportType=AmqpWebSockets
But could be how you added the connection string to the code. You must make sure you get the connection string for a specific event hub in a namespace:
https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-get-connection-string#connection-string-for-a-specific-event-hub-in-a-namespace
When you apply that to the code, make sure you remove the "EntityPath=" part.
For example , consider the connections string is :
"Endpoint=sb://myhub.servicebus.windows.net/;SharedAccessKeyName=mypolicy;SharedAccessKey=bc34534534543l+4wyWi5jbrQ=;EntityPath=myhub;"
remove the entity path and add it to the "local.settings.json" as you connection string setting
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"MyConnSetting": "Endpoint=sb://myhub.servicebus.windows.net/;SharedAccessKeyName=mypolicy;SharedAccessKey=bc34534534543l+4wyWi5jbrQ=;TransportType=AmqpWebSockets"
}
}
than add the connection string setting and entity path value like this:
[Function("Function1")]
public void Run([EventHubTrigger("myhub", Connection = "MyConnSetting")] string[] input)
{
_logger.LogInformation($"First Event Hubs triggered message: {input[0]}");
}
Remember this is just a way to force the trigger to use websockets. once you deploy you can set it to use AMQP.
Hope this help!

How to tell gRPC client tells whether gRPC server has cancelled?

I'm using a synchronous bidirectional streaming grpc service, and I've let Server-side to close connection when timeout detected.
// server-side code
if (timeout-detected) {
server_context_->TryCancel();
}
My question is: how do I detect whether the connection still valid on client-side? If so, I could reestablish connection. I've tryed
// client-side code
if (client_reader_writer_->Write(&request)) {
// I consider it connection is still valid
} else {
// connection decided cancelled. Re-establish connection and do something.
}
But client_reader_writer_->Write(&request) return true, even after the server's log has shown cancelled.
If someone could give me some hints on this, I would be much grateful!
If your concern is about link, Keepalive can be used a mechanism to check if the channel is fine by transmitting HTTP2 pings at regular intervals and if there is no response, it is considered as broken.
Other approach is you can also come up with your own "heartbeat" mechanism where you can have the heartbeat sent periodically to check on server/network failure while trying to write to socket.
For server timeout in a typical scenario, indication to client can be done using context.abort(grpc.StatusCode.DEADLINE_EXCEEDED, 'RPC Time Out!')
Here is a reference for the same.

Connection reset by peer error while using celery stats()

I'm trying to get stats for my celery Que (rabbitmq). I'm using celery.app.control.Inspect().stats() API. I'm doing this on a web server, I can get the stats only one time. If I refresh the page I'm getting "[Errno 104] Connection reset by peer" Error. how can I deal with this.
/init.py
celtasks = Celery(app.name,"rabbit mq url")
/helpers.py
get_stats():
stats = celtasks.control.Inspect().stats()
return stats
whenever there is a request "get_stats" function is hit. It is only working for the first request after this, it says connection reset by peer error.
If I go by connection has been reset and try to create the connection again, I get error
updated /helpers.py
get_stats():
celtasks = Celery(app.name,"rabbit mq url")
stats = celtasks.control.Inspect().stats()
return stats
Rabbitmq logs
=WARNING REPORT==== 10-Jul-2017::14:11:54 ===
closing AMQP connection <0.29185.6> (10.246.170.70:48618 -> 10.24.83.115:5672):
connection_closed_abruptly
=WARNING REPORT==== 10-Jul-2017::14:11:54 ===
closing AMQP connection <0.29197.6> (10.246.170.70:48620 -> 10.24.83.115:5672):
connection_closed_abruptly
"rabbit#oser000300.log-20170625" 9054L, 361662C
AT most times , CONNECTION RESET BY PEER is because the server close the connection itself, however the client does not know . When client want to communicate to sever through this broke connection, it receive this ERROR. In your case , maybe the hang time (time interval between two stats()) is too long, and server think this connection is useless and close it .

Redirect std:cout to std::ofstream , getting an error

I am redirecting my standard output data to a std::ofstream buffer, to write the data in a file. The following code implement this,
if ( isActive ){
try{
std::string traceFileName = "traceLog"+getTime()+".log";
std::ofstream out(traceFileName.c_str());
std::streambuf *countbuf = std::cout.rdbuf();
std::cout.rdbuf ( out.rdbuf() ) ;
std::cout<<"buffer pointed\n"<<std::endl;
}
when i am implementing the above code in a single .cpp, itgeting executed and dada is geting write in the file.But for the following scenarion,
A( bool isActive){
if ( isActive ){
try{
std::string traceFileName = "traceLog"+getTime()+".log";
std::ofstream out(traceFileName.c_str());
std::streambuf *countbuf = std::cout.rdbuf();
std::cout.rdbuf ( out.rdbuf() ) ;
std::cout<<"buffer pointed\n"<<std::endl;
}
And from a different .cpp the function A( true ) is getting called, and I want that after A() called then in my whole c++ project when ever std::cout<"printing data\n"; is there the data will be printed into the file.
But my code is compiling fine, during RUN time throwing the following error,
(process:10365): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
(process:10365): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
(process:10365): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
QGtkStyle was unable to detect the current GTK+ theme.
Qt: Session management error: None of the authentication protocols specified are supported
But if I am placing the following code at main,
std::string traceFileName = "traceLog"+getTime()+".log";
std::ofstream out(traceFileName.c_str());
std::streambuf *countbuf = std::cout.rdbuf();
std::cout.rdbuf ( out.rdbuf() ) ;
the run time all the std::cout data is geting write in the file. ut throwing the following error. How can I solve this error.
enter code here(process:10777): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
(process:10777): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
(process:10777): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
QGtkStyle was unable to detect the current GTK+ theme.
Qt: Session management error: None of the authentication protocols specified are supported
The problem is that your buffer is not being restored before leaving the scope in which the file stream was created. std::cout will still hold a pointer to the buffer that it eventually tries to write to.
I believe one option is to make out static, and the other is to create a class which reassigns the original buffer to std::cout when the scope is being left:
class buffer_restore
{
public:
buffer_restore(std::ios& _ios)
: ios(_ios)
, sbuf(_ios.rdbuf())
{ }
~buffer_restore()
{
ios.rdbuf(sbuf);
}
private:
std::ios& ios;
std::streambuf* sbuf;
};
Here's an example of how it would be used:
{
buffer_restore br(std::cout);
std::ofstream out(traceFileName.c_str());
std::streambuf* countbuf = std::cout.rdbuf(out.rdbuf());
} // std::cout's buffer is restored to the original when br was constructed

How do I set timeout for TIdHTTPProxyServer (not connection timout)

I am using TIdHTTPProxyServer and now I want to terminate connection when it is success to connect to the target HTTP server but receive no response for a long time(i.g. 3 mins)
Currently I find no related property or event about it. And even if the client terminate the connection before the proxy server receive the response from the HTTP server. OnException Event will not be fired until the proxy server receive the response. (That is, if the proxy server still receive no response from HTTP Server, I even do not know the client has already terminate the connection...)
Any help will be appreciated.
Thanks!
Willy
Indy uses infinite timeouts by default. To do what you are asking for, you need to set the ReadTimeout property of the outbound connection to the target server. You can access that connection via the TIdHTTPProxyServerContext.OutboundClient property. Use the OnHTTPBeforeCommand event, which is triggered just before the OutboundClient connects to the target server, eg:
#include "IdTCPClient.hpp"
void __fastcall TForm1::IdHTTPProxyServer1HTTPBeforeCommand(TIdHTTPProxyServerContext *AContext)
{
static_cast<TIdTCPClient*>(AContext->OutboundClient)->ReadTimeout = ...;
}