Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions grafana/rmf-app/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2"
version: '2'
run:
allow-parallel-runners: true
linters:
Expand All @@ -11,7 +11,6 @@ linters:
- durationcheck
- errchkjson
- errorlint
- exhaustive
- fatcontext
- gocheckcompilerdirectives
- gochecksumtype
Expand Down
8 changes: 4 additions & 4 deletions grafana/rmf-app/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Pre-requisites

- `NodeJS`: >=16
- `Yarn`: 1.x.x
- `Go`: >=1.21
- `NodeJS`: see `package.json`
- `Yarn`: see `package.json`
- `Go`: see `go.mod`
- `GNU Make`: >=3.81
- `jq`: >=v1.6
- `zip`: >=3.0
Expand All @@ -16,4 +16,4 @@
- Navigate to the directory `grafana/rmf-app`.
- Execute the command: `make all`.
This creates the `./build` directory and once successful you can find the
`ibm-rmf-grafana-<VERSION>.zip` and `ibm-rmf-grafana-<VERSION>.zip.md5` files there.
`ibm-rmf-grafana-<VERSION>.zip` and `ibm-rmf-grafana-<VERSION>.zip.md5` files there.
2 changes: 1 addition & 1 deletion grafana/rmf-app/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all: clean build zip ## Executes clean build and zip tasks
##@ Dependencies

node_modules: package.json yarn.lock
yarn install --frozen-lockfile
yarn install --immutable

deps-frontend: node_modules ## Install Node.js dependencies

Expand Down
2 changes: 1 addition & 1 deletion grafana/rmf-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"webpack-virtual-modules": "^0.6.2"
},
"engines": {
"node": ">=20"
"node": ">=22"
},
"dependencies": {
"@emotion/css": "^11.13.5",
Expand Down
63 changes: 63 additions & 0 deletions grafana/rmf-app/pkg/plugin/cache/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* (C) Copyright IBM Corp. 2023, 2025.
* (C) Copyright Rocket Software, Inc. 2023-2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cache

import (
"encoding/json"
"time"

"github.com/IBM/RMF/grafana/rmf-app/pkg/plugin/frame"
"github.com/VictoriaMetrics/fastcache"
"github.com/grafana/grafana-plugin-sdk-go/backend"
)

type ChannelCache struct {
cache *fastcache.Cache
}

type Channel struct {
Resource string
TimeRange backend.TimeRange
Absolute bool
Step time.Duration
Fields frame.SeriesFields
}

func NewChannelCache(size int) *ChannelCache {
return &ChannelCache{cache: fastcache.New(size * 1024 * 1024)}
}

func (cc *ChannelCache) Reset() {
cc.cache.Reset()
}

func (cc *ChannelCache) Get(path string) (*Channel, error) {
var c Channel
b := cc.cache.Get(nil, []byte(path))
err := json.Unmarshal(b, &c)
return &c, err
}

func (cc *ChannelCache) Set(path string, c *Channel) error {
b, err := json.Marshal(*c)
if err != nil {
return err
}
cc.cache.Set([]byte(path), b)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,30 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data"
)

type Cache struct {
type FrameCache struct {
cache *fastcache.Cache
}

func NewFrameCache(size int) *Cache {
return &Cache{cache: fastcache.New(size * 1024 * 1024)}
func NewFrameCache(size int) *FrameCache {
return &FrameCache{cache: fastcache.New(size * 1024 * 1024)}
}

func (fc *Cache) Reset() {
func (fc *FrameCache) Reset() {
fc.cache.Reset()
}

func Key(r *dds.Request, wide bool) []byte {
func FrameKey(r *dds.Request, wide bool) []byte {
format := "long"
if wide {
format = "wide"
}
return []byte(fmt.Sprintf("%s[%s]@%d-%d", r.Resource, format, r.TimeRange.From.UnixMilli(), r.TimeRange.To.UnixMilli()))
}

func (fc *Cache) GetFrame(r *dds.Request, wide bool) *data.Frame {
func (fc *FrameCache) Get(r *dds.Request, wide bool) *data.Frame {
logger := log.Logger.With("func", "GetFrame")
var frame data.Frame
key := Key(r, wide)
key := FrameKey(r, wide)
buf := fc.cache.GetBig(nil, key)
if buf != nil {
err := json.Unmarshal(buf, &frame)
Expand All @@ -65,9 +65,9 @@ func (fc *Cache) GetFrame(r *dds.Request, wide bool) *data.Frame {
return nil
}

func (fc *Cache) SaveFrame(f *data.Frame, r *dds.Request, wide bool) error {
key := Key(r, wide)
frame := fc.GetFrame(r, wide)
func (fc *FrameCache) Set(f *data.Frame, r *dds.Request, wide bool) error {
key := FrameKey(r, wide)
frame := fc.Get(r, wide)
if frame != nil {
return nil
}
Expand Down
82 changes: 0 additions & 82 deletions grafana/rmf-app/pkg/plugin/channel.go

This file was deleted.

2 changes: 1 addition & 1 deletion grafana/rmf-app/pkg/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (ds *RMFDatasource) getConfig(settings backend.DataSourceInstanceSettings)
}
}
if config.CacheSize, err = strconv.Atoi(config.JSON.CacheSizeRaw); err != nil {
logger.Warn("cache size is not valid, applying default", "cacheSize", config.JSON.CacheSizeRaw, "err", err)
logger.Warn("cache size is not valid, applying default", "cacheSizeRaw", config.JSON.CacheSizeRaw)
config.CacheSize = DefaultCacheSizeMB
}
if config.CacheSize < MinimalCacheSizeMB {
Expand Down
Loading
Loading