units

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

Unit Converter from Grafana to Guance

Quick view

In Grafana and Guance Dashboard, there are many units to represent to data semantic.

This package is a converter to convert the unit string from Grafana to Guance.

The implementation steps are:

  1. Get the full list of units from Grafana.
  2. Extract all the units from source code of Guance Cloud Console by tree-sitter query.
  3. Compare the units from Grafana and Guance, and find the mapping relationship.

Extract units from Guance

The Guance Cloud Console is written in React, and the source code is compiled to JavaScript.

The tree-sitter is a parser generator tool and incremental parsing library. It can extract any information from source code and its CST (Concrete Syntax Tree).

The query as follows:

; extract the unit formats
(program
    (expression_statement
        (assignment_expression left:
            (identifier) right:
            (object [
                (pair key: (string) @id)
                (pair key: (property_identifier) @id)
            ])
        )
    )
)

The steps to extract the units from Guance:

  1. Clone the frontend source code of Guance Cloud Console.
  2. cd lib/convert-units/lib/definitions folder.
  3. Run the script node main.js.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addon

type Addon struct {
	Measurement string
}

Addon is a builder to convert unit to the chart

func (*Addon) PatchChart

func (addon *Addon) PatchChart(panel *grafanaspec.Panel, chart map[string]any) (map[string]any, error)

type Category

type Category struct {
	Name    string `json:"name"`
	Formats []Unit `json:"formats"`
}

type Unit

type Unit struct {
	Name string `json:"name"`
	ID   string `json:"id"`
	Ref  string `json:"ref"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL