Converting .proto to Json or yaml - protocol-buffers

New to protobuf. I have a bunch of .proto files which defines numerous endpoints. I would like to programmatically extract the endpoint definitions along with other method data defined in the endpoint specs. Is there an easy way to do this ?

Interesting question.
I'm unaware of any tools like jq for JSON and yq for YAML for processing|querying protos but it would be a useful tool to have.
I think there are probably tools out there that can help with the documentation aspect of protos but I've not used any. The folks at Buf are doing some interesting work. Their schema registry may be of interest? I've not used it.
Otherwise, you could one of the SDKs that supports reflection (e.g. Go's v2 SDK supports this) and build a solution.

Related

Using templating/overlay libraries in operators

While building operators using OperatorSDK: Go framework, we end up creating Kubernetes resources such Deployments, Services etc programmatically by leveraging structs from k8s modules/packages. Compared to creating these manifests in yaml/json formats, this is quite cumbersome and requires quite a bit of coding. And any changes to the manifest would require code changes and the new version of the operator needs to be rolled out.
I am wondering whether existing templating/overlay tools such as Helm or Kustomize can be used for building these k8s resources within the operator code. This would also enable you to externalise the manifest/template files from the operator code. I couldn't find any good examples of how these tools can be used as modules/libraries within a Go program. Please provide any pointers, suggestions or alternate approaches.
Related question: Kubernetes operator create Deployment using yaml template
This talks about how you can read a yaml file and unmarshal it into a Deployment object. Here, I would still need to code templating/overlay logic within the operator.
You can use the helm engine programmatically, by calling engine.Render.
func Render(chrt *chart.Chart, values chartutil.Values) (map[string]string, error)

How to use the incluxdb1-client library of golang to query the data?

My library is github.com/influxdata/influxdb1-client/v2,and I need to use it to operate the VictoriaMetrics, For example, I need to make the following query:
sort_desc(avg(idc_bandwidth_5m_data_cube_just_idc_bandwidth_kilobits{idc=~"$cluster", isp=~"$isp"}[5m]) by (idc))
What should I do? Or is there another better library to use? Help me!!!
Can you give me a sample code?
I'm afraid github.com/influxdata/influxdb1-client/v2 can't be used for reading data from VcitoriaMetrics. You need a library which can send PromQL/MetricsQL queries via HTTP and parse responses. I'm not sure if there are a good Golang lib for that. I've heard only about JS lib.
In general, sending queries and parsing responses to VictoriaMetrics or Prometheus is rarely needed. And when needed, it is usually implemented from scratch. Please use the following link as a reference.
You might be also interested in the following issue I'm afraid github.com/influxdata/influxdb1-client/v2 can't be used for reading data from VcitoriaMetrics. You need a library which can send PromQL/MetricsQL queries via HTTP and parse responses. I'm not sure if there are a good Golang lib for that. I've heard only about JS lib.
In general, sending queries and parsing responses to VictoriaMetrics or Prometheus is rarely needed. And when needed, it is usually implemented from scratch. Please use the following link as a reference.
You might be also interested in the following issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/108

can we check if the OpenAPI spec file is in sync with code written?

I have some repos for which I want to enable the OpenAPI(Previously known as Swagger) spec file check. There are tools(i.e. Stoplite's Spectral) available for the validation of file which provides lint support for the Yaml file.
However, what I want to achieve is that if I write an API in the code (i.e. GO or Java or Python) and if I do not specify that API in the OpenAPI Spec file, then it should throw an error in the CI tool.
If we can check the sync between Protocol buffer and OpenAPI spec file then also it would be useful so please do mention if any tool is available.
I believe that we may require different tools for different languages which are okay, but do we have that in any of the languages or not that I am not sure of.

A Priori Graphic Tool For Building Microservices

I've spend a lot of time for searching a tool for draw A-Priori Diagrams of Microservices Architecture which can be used for create the first layer of OpenAPI Specification of the infrastructure. Which can be later extenden directly throw Json or Yaml and the original graphic output should be updated consequently.
So far I was unable to find out any tool that can help me to do so.
I'm wondering if some who out there have in mind some tools for this othervise i will use like always draw.io
Thanks in advance.
You can try one of these:
https://www.visual-paradigm.com/solution/freeumldesigntool/
https://sparxsystems.com/products/ea/compare-editions.html
https://www.websequencediagrams.com
https://www.gliffy.com/
I am not really sure if you can export the diagram to json and yaml. In some of them you can export to html and xml.
Gliffy is good if you want to have nice diagrams for AWS services and similar.

Using proto files as the one source for documentation - handling expanded metadata/comments

We currently use gRPC exclusively and generate our documentation from the proto files. I want one place (the protofile) to define all related documentation for a service, preferably with some reference structure to follow.
We have been including extra information as comments in the proto files, while this has been working it would be nice if there was some sort of structured metadata template we could leverage for this. For example, I want the proto files and documentation to contain expanded information about errors and error handling. It would be nice if there was some structure to adopt for this, rather than trying to define our own pattern in comments.
Curious to know what people in the community have been doing for their gRPC documentation? Do you just maintain extra documentation outside of the protofile, or do you inline it with comments?

Resources