RPC using JSON but not JSONRPC in Substrate - substrate

I want to write an RPC service which can uses JSON as RPC payload but it does not follow JSONRPC standards. Also I want to execute pallet's extrinsic function based on JSON DATA received on RPC How to achieve these goals?
I tried to read Moonbeam's code but that seems too complicated to achieve above goals.

Related

How to parse Rop commands in EcDoRpcExt2 functions?

I have been researching the Exchange protocol to see how email is sent and received through the Exchange protocol. But the Rop commands used during Rpc calls can be a pain to parse. This makes it impossible for me to get the complete information of the mailbox through the hook.
The function called by Rpc is EcDoRpcExt2
Here's what Microsoft said about it:
https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcrpc/1842194b-c530-4b64-a778-0e663029785c
The Rop command is in parameter rgbIn
I wonder how it is parsed internally/by the server. I can barely get what I want from the document. It's too complicated

How to decode different types with Golang gob package

I need to write a client and a server. Client can send different request types as a GoLang struct, and server should recognize the type, and invoke a corresponding handler function. How would you achieve that? I tried to look into gob package, but I don`t see that it can recognize the type it receives from the stream?
One more quest - is gob package the most efficient way to pass messages between client, and server from the low-latency low-memory utilization perspective?

How does the serverless datadog forwarder encrypt/encode their logs?

I am having trouble figuring out how the datadog forward encodes/encrypts its messages from the datadog forwarder. We are utilizing the forwarder on datadog using the following documentation: https://docs.datadoghq.com/serverless/forwarder/ . On that page there, Datadog has an option to send the same event to another lambda that it invokes via the AdditionalTargetLambdaARNs flag. We are doing this and having the other lambda invoke but the event input that we are getting is long string that looks like it is base64 encoded but when I put it into a base64 decoder, I get gibberish back. I was wondering if anyone knew how datadog is compressing/encoding/encrypting their data/logs that they send so that I can read the logs in my lambda and be able to preform actions off of the data being forwarded? I have been searching google and the datadog site for documentation on this but I can't find any.
It looks like Datadog uses zstd compression in order to compress its data before sending it: https://github.com/DataDog/datadog-agent/blob/972c4caf3e6bc7fa877c4a761122aef88e748b48/pkg/util/compression/zlib.go

How to define a Pact contract between a persistent service and a synchronous serverless function?

I have a persistent service which synchronously calls a serverless function (on AWS lambda, via the serverless framework) with some input, the serverless (and stateless) lambda function performs some transformation of the input and synchronously returns the output back to the calling service.
I want to write a Pact contract where the serverless function is the provider and the persistent service is the consumer. How can I do this for a synchronous (i.e. RequestResponse) serverless function?
I have found a few resources on pacts for serverless functions, but they all seem to only tackle the asynchronous use case, unless I'm misunderstanding something.
To be clear, the use case in my case is not asynchronous, event-driven message passing, but synchronous calling of a serverless function, blocking while waiting for the response.
From the Pact documentation, I can find references only to support for HTTP-based APIs and Message-based asynchronous APIs. This use case fits neither of these patterns, as we use the serverless framework, which performs the actual HTTP request behind the scenes.
In my case, the persistent service (consumer) is in Java and the serverless function in Kotlin, i.e. both on the JVM.
As mentioned by Matthew Fellows you can configure the AWS Lambda Client to invoke your custom URL since it does regular HTTP request under the hood. Use AWSLambdaClientBuilder and do:
withEndpointConfiguration(
AwsClientBuilder.EndpointConfiguration(pactMockServerEndpoint, Regions.EU_CENTRAL_1.name)
)
You need to set Content-Type: application/json in request headers or else Pact fails to parse header (since it is empty string by default for some reason). Use withRequestHandlers for that and create consumer contracts by calling lambda functions through this client (it should request Pact mock-server instead of AWS).
However, on the producer side you need to:
Create a proxy server (use something like MockServer)
Use Pact JUnit provider when running Pact tests so you can start the proxy server
Use HTTP target when playing Pact contracts as you normally would do and set proxy as target
The idea is that you have a proxy HTTP server that uses your serverless handler function for returning responses:
mockServer.`when`(
HttpRequest.request().withPath(".*")
).respond { httpRequest ->
HttpResponse.response(
// Invoke handler and return response
OBJECT_MAPPER.writeValueAsString(invokeLambdaWithRequest(httpRequest))
).let { httpResponse ->
httpResponse.withHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8")
}
}
This is something that is not yet directly supported by Pact.
Option 1
At the moment you would need to write two separate sets of tests to cover both request and response aspects of the interaction, one initiated by the consumer and another from the provider.
option 2 (untested)
Invoke lambda is just an HTTP POST request via the AWS lambda service, so it could in theory be tested via a regular HTTP request/response.
See https://gist.github.com/bethesque/c858e5c15649ae525ef0cc5264b8477c for somethinking on a req/res style interaction (and join us at slack.pact.io to chat on it)

How to push cpu info to OpenTSDB server using golang

I need to push cpu info to OpenTSDB server using golang.
What is the procedure to send data in golang?
In which package should use the sent Data? (websocket or http)
In which format should I send the data?
What method should I use for pushing the data? (POST OR GET)
You can use https://github.com/shirou/gopsutil package to gather metrics then use http package to push data to your backend using a POST request with a json body. Have a look to this thread for posting data with golang : How do I send a JSON string in a POST request in Go.

Resources