Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: document how to write create new keptnmetricsprovider #2939

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
c9a57fb
keep
geoffrey1330 Aug 7, 2023
007130c
keep
geoffrey1330 Sep 22, 2023
a38b3c5
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
decf9ce
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
73ed522
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
1288846
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
59d59eb
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
e34c356
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
b941123
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
f694a51
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
f0c713a
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
89610f4
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
3da39bd
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
82ff85c
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
20dcfe6
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
2458e88
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
b6cbf99
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
d0670bb
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
fd23cbc
Added dummy provider in keptn metric provider
geoffrey1330 Feb 1, 2024
491b361
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 2, 2024
90660a8
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 2, 2024
0d643bb
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
c3fb722
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
65e3a52
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
7cfe368
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
5a4f822
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
f62c25f
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
95f9f4e
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
a77be7a
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
0f4947d
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
577ca9a
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
1592466
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
5f95c95
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
447eee1
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
8199672
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
ae81ae7
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
6774213
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
ae6006b
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
ac51465
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
0cf5be0
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
76bac32
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
f9dd6f4
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
d98ec97
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
462af45
Added dummy provider in keptn metric provider
geoffrey1330 Feb 2, 2024
0575eb3
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
da33022
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
0dfa7ad
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
d807824
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
90a0361
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
bff4667
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
1cc2401
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
887e90e
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
312a403
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
a19d3a9
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
9366b44
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
830fac1
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
325f4a7
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
9f59459
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
d951427
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
972581c
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
af27322
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
5579f8d
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
26d43eb
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
fb72358
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
206c166
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
4816a0f
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
9444a0e
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
3ac838b
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
14b4bb1
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
425e43f
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
8b31763
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
c872041
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
8a53e1a
Added dummy provider in keptn metric provider
geoffrey1330 Feb 5, 2024
dcd8f51
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
1b5f991
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
05856bf
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
63ed5ce
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
7ef117e
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
410865c
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
ba60139
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
e03e231
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
8499c72
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 6, 2024
b569b5b
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 6, 2024
eb0027a
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
ee23f5d
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
0710eff
Added dummy provider in keptn metric provider
geoffrey1330 Feb 6, 2024
9492512
reverted back the change in the helm test
geoffrey1330 Feb 6, 2024
6554d1e
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 9, 2024
eecdb10
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 9, 2024
c0fb934
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
660b54a
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
9d90c12
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
0ec1782
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
04f2237
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
0b6e851
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
a91fa0c
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
e0e4391
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
7869737
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
31da095
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
6f6d623
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
7a2b149
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
9d45b27
reverted back the change in the helm test
geoffrey1330 Feb 9, 2024
7ae0ce1
reverted back the change in the helm test
geoffrey1330 Feb 12, 2024
ccbdefb
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 12, 2024
ea06952
reverted back the change in the helm test
geoffrey1330 Feb 12, 2024
84ef1a7
reverted back the change in the helm test
geoffrey1330 Feb 12, 2024
a4b6ab4
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 12, 2024
3c27cd0
reverted back the change in the helm test
geoffrey1330 Feb 12, 2024
ed29941
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 12, 2024
0542852
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 12, 2024
1d56d51
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 12, 2024
28870b4
reverted back the change in the helm test
geoffrey1330 Feb 12, 2024
e314794
reverted back the change in the helm test
geoffrey1330 Feb 12, 2024
5243404
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 12, 2024
e48f3b6
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 12, 2024
ce320c0
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 12, 2024
45a0580
documenting the steps for creating a new metric provider
geoffrey1330 Feb 12, 2024
2a76a7c
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 12, 2024
abe4559
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 12, 2024
cf309c9
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 13, 2024
619aeff
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 13, 2024
1c918d9
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
664ff73
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
bfd540b
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
ca834af
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 13, 2024
e117d9d
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
da8cfd6
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
08212ed
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 13, 2024
721f67b
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 13, 2024
de9c130
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 13, 2024
4d4451c
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 13, 2024
161e8f7
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 13, 2024
d68840a
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 13, 2024
2779358
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
79c9ed3
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
c08cac4
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
75eea9a
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
c7f0aaf
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
8dd5b7e
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
2beec41
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
922734b
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
a6c468c
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
376a2d5
documenting the steps for creating a new metric provider
geoffrey1330 Feb 13, 2024
806ada8
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
3b43f5b
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
c686f1c
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
95e545c
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
425475b
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
6c6f20f
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
1098842
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
2a57c2e
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
598d123
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
6066e6a
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
758da0b
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
6aae2ea
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
1293a40
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
7c8469b
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
a346994
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
25bb139
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
96df7ae
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
9d78556
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
35fae0a
documenting the steps for creating a new metric provider
geoffrey1330 Feb 14, 2024
d6c6654
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 15, 2024
2532d36
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 15, 2024
50991f4
Update mkdocs.yml
geoffrey1330 Feb 15, 2024
2b7f6dc
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 15, 2024
c7dede0
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 15, 2024
17138d8
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 15, 2024
ad337e9
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 15, 2024
b1f19ad
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 15, 2024
17bf9ef
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 15, 2024
ca5a2a0
documenting the steps for creating a new metric provider
geoffrey1330 Feb 15, 2024
6514233
documenting the steps for creating a new metric provider
geoffrey1330 Feb 15, 2024
7e139e1
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 15, 2024
478dd67
documenting the steps for creating a new metric provider
geoffrey1330 Feb 15, 2024
414ff89
documenting the steps for creating a new metric provider
geoffrey1330 Feb 15, 2024
8b1abe8
documenting the steps for creating a new metric provider
geoffrey1330 Feb 15, 2024
552160d
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 15, 2024
f864eda
documenting the steps for creating a new metric provider
geoffrey1330 Feb 15, 2024
3343dc2
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
e82c53c
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
a79bc1d
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
f8bd3eb
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
22fe49a
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
23a4bd1
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
0149b1b
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
eabfb92
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
f93eec4
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
2ae6973
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
5502edb
documenting the steps for creating a new metric provider
geoffrey1330 Feb 16, 2024
28c77ed
documenting the steps for creating a new metric provider
geoffrey1330 Feb 20, 2024
f2226cf
documenting the steps for creating a new metric provider
geoffrey1330 Feb 20, 2024
eb28608
documenting the steps for creating a new metric provider
geoffrey1330 Feb 20, 2024
42731af
documenting the steps for creating a new metric provider
geoffrey1330 Feb 20, 2024
79ded21
documenting the steps for creating a new metric provider
geoffrey1330 Feb 20, 2024
37ebefd
documenting the steps for creating a new metric provider
geoffrey1330 Feb 20, 2024
9876c77
Merge branch 'main' into doc/1248/document_how_to_write_create_new_ke…
geoffrey1330 Feb 20, 2024
4ab7758
Update docs/docs/contribute/software/add-new-metric-provider.md
geoffrey1330 Feb 20, 2024
5843060
Update docs/docs/contribute/software/add-new-metric-provider.md
odubajDT Feb 20, 2024
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
124 changes: 124 additions & 0 deletions docs/docs/contribute/software/add-new-metric-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
comments: true
---

# Add a metrics provider

The
[KeptnMetric](../../guides/evaluatemetrics.md)
feature works with almost any data platform
but Keptn requires that a metrics provider be defined
for any data platform it uses as a data source.
This guide gives instructions for creating a new metrics provider.
For these instructions,
we define a sample provider called `placeholder`.
The steps to create your own metrics provider are:
<!-- markdownlint-disable MD007 -->

1. **Fork and clone** the
[Keptn repository](https://github.com/keptn/lifecycle-toolkit).
For more information, see
[Fork and clone the repository](https://keptn.sh/stable/docs/contribute/general/git/fork-clone/).

2. **Define the Provider Type:** In the `metrics-operator/controllers/common/providers/common.go` file,
define the constant `KeptnPlaceholderProviderType`.
In our example we use `"placeholder"`.

```go
const KeptnPlaceholderProviderType = "placeholder"
```

3. **Implement the Provider:** Create a new folder inside the
[metrics-operator/controllers/common/providers](<https://github.com/keptn/lifecycle-toolkit/tree/main/metrics-operator/controllers/common/providers>).
Use the provider name as the name of the folder.
This name defines the string used to identify this provider
in the `spec.type` field of the
[KeptnMetricsProvider](../../reference/crd-reference/metricsprovider.md)
resource.
In this example, the folder is named `placeholder`.
Create a new Go package for the placeholder provider in that folder.
This package should contain a `struct` that implements the `KeptnSLIProvider` interface.
To fully implement the `KeptnSLIProvider` interface, it's necessary to implement the following functions.

* `EvaluateQuery`(Fetches metric values from the provider)
* This function fetches metric values based on the provided
metric query from the provider.
It evaluates the query and returns the metric values
along with any additional data if required.
* It takes as input a [KeptnMetric](../../reference/crd-reference/metric.md)
and [KeptnMetricsProvider](../../reference/crd-reference/metricsprovider.md)
* `EvaluateQueryForStep`(Fetches metric values with step interval from the provider)
* This function fetches metric values with a specified step interval from the placeholder provider.
It takes into account the metric query and the step interval provided, executes the query,
and returns the metric values along with any additional data if required.
* It takes as input a [KeptnMetric](../../reference/crd-reference/metric.md)
and [KeptnMetricsProvider](../../reference/crd-reference/metricsprovider.md)
* `FetchAnalysisValue`(Fetches analysis values from the provider) functions.
* This function fetches analysis values based on the provided query and time range from the
provider.
It evaluates the query within the specified time range and returns the analysis
values along with any additional data if required.
* It takes as input an [Analysis](../../reference/crd-reference/analysis.md),
resource that contains a `query` and a
[KeptnMetricsProvider](../../reference/crd-reference/metricsprovider.md) resource.

You can follow other existing implementations,
such as [prometheus.go](https://github.com/keptn/lifecycle-toolkit/blob/main/metrics-operator/controllers/common/providers/prometheus/prometheus.go),
as an example.

Each of the three functions expects a string containing a float value in it.
But for example purposes we returned some of the data accessible in the function.

Below is an example of a placeholder provider implementation.

```go
{% include "./assets/example-code/placeholder-code-example.go" %}
```

> **Note** Refer to the documentation of the
> [KeptnMetric](../../reference/crd-reference/metric.md)
> and
> [Analysis](../../reference/crd-reference/analysis.md)
> resources
> to understand what data should be retrieved from the methods inputs to compute accurate results.

4. **Instantiate the Provider** in the `providers.NewProvider` function
in the `metrics-operator/controllers/common/providers/provider.go` file.
add a case for the `KeptnPlaceholderProviderType`.
Instantiate the placeholder provider struct and return it.

```go
geoffrey1330 marked this conversation as resolved.
Show resolved Hide resolved
{% include "./assets/example-code/new-provider-function.go" %}
```

5. **Update the validation webhook and crd config:** To update the validation webhook and crd config of the metrics operator.
Add the provider name next to last providers on this
[line](https://github.com/keptn/lifecycle-toolkit/blob/main/metrics-operator/api/v1beta1/keptnmetricsprovider_types.go#L29)
to look like this

`// +kubebuilder:validation:Pattern:=prometheus|dynatrace|datadog|dql|placeholder`.

In the metric-operator directory run `make generate manifests` to update the metrics-operator crd config
Then modify the helm chart and the helm chart crd validation to match the update in the metrics-operator crd config

6. **Add Test Cases:**
* Write a unit test to validate your implementation at the function level.
Unit tests ensure that individual
functions behave as expected and meet their functional requirements.

* Include a Chainsaw test to validate the behavior of Kubernetes resources managed by your code.
Chainsaw tests simulate real-world scenarios and interactions within a Kubernetes cluster, ensuring
the correctness of your Kubernetes configurations and deployments.

Below are the steps for adding an integration test.

* In the directory `test/chainsaw/testmetrics`, create a folder `metrics-provider-placeholder` in our case.
* Within the `keptn-metrics-placeholder` folder, create YAML file `00-install.yaml`.
* `00-install.yaml` contains a sample configuration that installs a valid `KeptnMetricsProvider`
in our case `placeholder` and it also defines a sample `KeptnMetric` configuration
representing a valid use case, while.
* Create a file named `chainsaw-test.yaml` and define the steps for the integration test in chainsaw-test.yaml.

> For more information checkout [an already existing integration test](https://github.com/keptn/lifecycle-toolkit/tree/main/test/chainsaw/testmetrics/metrics-provider)

<!-- markdownlint-enable MD007 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Inside the providers package

// NewProvider function
func NewProvider(providerType string, log logr.Logger, k8sClient client.Client) (KeptnSLIProvider, error) {
switch strings.ToLower(providerType) {
case KeptnPlaceholderProviderType:
return &placeholder.KeptnPlaceholderProvider{
Log: log,
HttpClient: http.Client{},
}, nil
// Other cases...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package placeholder

import (
"context"
"fmt"
"net/http"
"time"

"github.com/go-logr/logr"
metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1beta1"
)

type KeptnPlaceholderProvider struct {
Log logr.Logger
HttpClient http.Client
}

func (d *KeptnPlaceholderProvider) FetchAnalysisValue(ctx context.Context, query string, analysis metricsapi.Analysis, provider *metricsapi.KeptnMetricsProvider) (string, error) {
return fmt.Sprintf("placeholder provider FetchAnalysisValue was called with query %s from %d to %d", query, analysis.GetFrom().Unix(), analysis.GetTo().Unix()), nil
}

func (d *KeptnPlaceholderProvider) EvaluateQuery(ctx context.Context, metric metricsapi.KeptnMetric, provider metricsapi.KeptnMetricsProvider) (string, []byte, error) {
return fmt.Sprintf("placeholder provider EvaluateQuery was called with query %s", metric.Spec.Query), nil, nil
}

func (d *KeptnPlaceholderProvider) EvaluateQueryForStep(ctx context.Context, metric metricsapi.KeptnMetric, provider metricsapi.KeptnMetricsProvider) ([]string, []byte, error) {
fromTime, toTime, stepInterval, err := getTimeRangeForStep(metric)
if err != nil {
return nil, nil, err
}
result := fmt.Sprintf("placeholder provider EvaluateQueryForStep was called with query %s from %d to %d at an interval %d", metric.Spec.Query, fromTime, toTime, stepInterval)
return []string{result}, nil, nil
}

func getTimeRangeForStep(metric metricsapi.KeptnMetric) (int64, int64, int64, error) {
intervalDuration, err := time.ParseDuration(metric.Spec.Range.Interval)
if err != nil {
return 0, 0, 0, err
}
stepDuration, err := time.ParseDuration(metric.Spec.Range.Step)
if err != nil {
return 0, 0, 0, err
}
return time.Now().Add(-intervalDuration).Unix(), time.Now().Unix(), stepDuration.Milliseconds(), nil
}
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ nav:
- Software contributions:
- docs/contribute/software/index.md
- Software development environment: docs/contribute/software/dev-environ.md
- Add a metrics provider: docs/contribute/software/add-new-metric-provider.md
- Documentation contributions:
- docs/contribute/docs/index.md
- Contribution guidelines for documentation: docs/contribute/docs/contrib-guidelines-docs.md
Expand Down
Loading