Skip to content

Commit

Permalink
test(segments): Add more e2e tests for segments
Browse files Browse the repository at this point in the history
Additional e2e tests for referencing segments in deploying it, and also download/restore
  • Loading branch information
Laubi committed Feb 6, 2025
1 parent 639df22 commit 21b0f4e
Show file tree
Hide file tree
Showing 11 changed files with 486 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/monaco/integrationtest/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ package integrationtest

import (
"fmt"
"github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/utils/monaco"
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/timeutils"
"github.com/spf13/afero"
"github.com/stretchr/testify/require"
"path/filepath"
"testing"

"github.com/spf13/afero"
"github.com/stretchr/testify/require"

"github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/utils/monaco"
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/timeutils"
)

// CleanupIntegrationTest deletes all configs that are defined in a test manifest. It uses the CLI runner, to call the
Expand All @@ -50,7 +52,7 @@ func CleanupIntegrationTest(t *testing.T, fs afero.Fs, manifestPath string, envi
}
}

err = monaco.RunWithFSf(fs, "monaco delete --manifest %s --file %s %s", manifestPath, deleteFile, env)
err = monaco.RunWithFSf(fs, "monaco --verbose delete --manifest %s --file %s %s", manifestPath, deleteFile, env)
if err != nil {
t.Log(err)
t.Log("Failed to cleanup all test configurations, manual/nightly cleanup needed.")
Expand Down
20 changes: 20 additions & 0 deletions cmd/monaco/integrationtest/v2/segments_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ func TestSegments(t *testing.T) {
assertSegmentIsInResponse(t, false, result, coord)
})
})

t.Run("Segments can be referenced from other configs", func(t *testing.T) {

RunIntegrationWithCleanup(t, configFolder, manifestPath, environment, "Segments", func(fs afero.Fs, testContext TestContext) {
// when deploying once
err := monaco.RunWithFSf(fs, "monaco deploy %s --project=referenced-segment --verbose", manifestPath)
assert.NoError(t, err)

segmentsClient := createSegmentsClient(t, fs, manifestPath, environment)
result, err := segmentsClient.GetAll(context.Background())
assert.NoError(t, err)

coord := coordinate.Coordinate{
Project: "referenced-segment",
Type: "segment",
ConfigId: "segment_" + testContext.suffix,
}
assertSegmentIsInResponse(t, true, result, coord)
})
})
}

func createSegmentsClient(t *testing.T, fs afero.Fs, manifestPath string, environment string) client.SegmentClient {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
configs:
- id: segment
config:
template: segment.json
type: segment
- id: dashbaord
config:
name: Dashboard
parameters:
segment_id:
configId: segment
configType: segment
property: id
type: reference
template: dashboard.json
type:
document:
kind: dashboard
private: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"importedWithCode": false,
"layouts": {
"0": {
"h": 6,
"w": 8,
"x": 0,
"y": 0
}
},
"settings": {
"defaultSegments": {
"enabled": true,
"value": [
{
"id": "{{.segment_id}}",
"variables": [
{
"name": "field",
"values": [
"dt.system.table"
]
},
{
"name": "data_types",
"values": [
"[\"string\"]"
]
}
]
}
]
}
},
"tiles": {
"0": {
"davis": {},
"query": "fetch logs\n| limit 20",
"queryConfig": {
"globalCommands": {
"limit": 20
},
"subQueries": [
{
"datatype": "logs",
"id": "A",
"isEnabled": true
}
],
"version": "12.2.2"
},
"querySettings": {
"defaultSamplingRatio": 10,
"defaultScanLimitGbytes": 500,
"enableSampling": false,
"maxResultMegaBytes": 1,
"maxResultRecords": 1000
},
"subType": "dql-builder-logs",
"title": "",
"type": "data",
"visualization": "table",
"visualizationSettings": {
"autoSelectVisualization": true,
"chartSettings": {
"categoricalBarChartSettings": {
"categoryAxisTickLayout": "horizontal",
"colorPaletteMode": "multi-color",
"groupMode": "stacked",
"layout": "horizontal",
"scale": "absolute"
},
"categoryOverrides": {},
"circleChartSettings": {
"groupingThresholdType": "relative",
"groupingThresholdValue": 0,
"valueType": "relative"
},
"colorPalette": "categorical",
"curve": "linear",
"gapPolicy": "gap",
"pointsDisplay": "auto",
"truncationMode": "middle",
"valueRepresentation": "absolute"
},
"histogram": {
"colorPalette": "categorical",
"dataMappings": [],
"displayedFields": [],
"legend": "auto",
"truncationMode": "middle",
"variant": "single",
"yAxis": {
"label": "Frequency",
"scale": "linear"
}
},
"honeycomb": {
"colorMode": "color-palette",
"colorPalette": "categorical",
"dataMappings": {},
"displayedFields": [],
"legend": {
"hidden": false,
"position": "auto"
},
"shape": "hexagon",
"truncationMode": "middle"
},
"singleValue": {
"alignment": "center",
"autoscale": true,
"colorThresholdTarget": "value",
"prefixIcon": "",
"showLabel": true,
"trend": {
"isVisible": true,
"trendType": "auto"
}
},
"table": {
"columnTypeOverrides": [],
"columnWidths": {},
"enableSparklines": false,
"hiddenColumns": [],
"lineWrapIds": [],
"linewrapEnabled": false,
"monospacedFontColumns": [],
"monospacedFontEnabled": false,
"rowDensity": "condensed"
},
"thresholds": []
}
}
},
"variables": [],
"version": 17
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"allowedOperations": [
"READ",
"WRITE",
"DELETE",
"SHARE"
],
"description": "This is my segment",
"includes": [
{
"applyTo": [],
"dataObject": "_all_data_object",
"filter": "{\"type\":\"Group\",\"range\":{\"from\":0,\"to\":15},\"logicalOperator\":\"AND\",\"explicit\":false,\"children\":[{\"type\":\"Statement\",\"range\":{\"from\":0,\"to\":15},\"key\":{\"type\":\"Key\",\"textValue\":\"\\\"test\\\"\",\"value\":\"test\",\"range\":{\"from\":0,\"to\":6},\"isEscaped\":true},\"operator\":{\"type\":\"ComparisonOperator\",\"textValue\":\"=\",\"value\":\"=\",\"range\":{\"from\":7,\"to\":8{{`}}`}},\"value\":{\"type\":\"String\",\"textValue\":\"\\\"test\\\"\",\"value\":\"test\",\"range\":{\"from\":9,\"to\":15},\"isEscaped\":true{{`}}`}}]}"
},
{
"applyTo": [],
"dataObject": "bizevents",
"filter": "{\"type\":\"Group\",\"range\":{\"from\":0,\"to\":21},\"logicalOperator\":\"AND\",\"explicit\":false,\"children\":[{\"type\":\"Statement\",\"range\":{\"from\":0,\"to\":21},\"key\":{\"type\":\"Key\",\"textValue\":\"browser.name\",\"value\":\"browser.name\",\"range\":{\"from\":0,\"to\":12{{`}}`}},\"operator\":{\"type\":\"ComparisonOperator\",\"textValue\":\"=\",\"value\":\"=\",\"range\":{\"from\":13,\"to\":14{{`}}`}},\"value\":{\"type\":\"String\",\"textValue\":\"Chrome\",\"value\":\"Chrome\",\"range\":{\"from\":15,\"to\":21{{`}}`}}}]}"
},
{
"applyTo": [],
"dataObject": "dt.entity.container_group_instance",
"filter": "{\"type\":\"Group\",\"range\":{\"from\":0,\"to\":21},\"logicalOperator\":\"AND\",\"explicit\":false,\"children\":[{\"type\":\"Statement\",\"range\":{\"from\":0,\"to\":20},\"key\":{\"type\":\"Key\",\"textValue\":\"tags\",\"value\":\"tags\",\"range\":{\"from\":0,\"to\":4{{`}}`}},\"operator\":{\"type\":\"ComparisonOperator\",\"textValue\":\"=\",\"value\":\"=\",\"range\":{\"from\":5,\"to\":6{{`}}`}},\"value\":{\"type\":\"String\",\"textValue\":\"\\\"mytag:mytag\\\"\",\"value\":\"mytag:mytag\",\"range\":{\"from\":7,\"to\":20},\"isEscaped\":true{{`}}`}}]}",
"relationship": {
"name": "belongs_to",
"target": "dt.entity.kubernetes_cluster"
}
},
{
"applyTo": [
"bizevents",
"events",
"spans"
],
"dataObject": "dt.entity.host",
"filter": "{\"type\":\"Group\",\"range\":{\"from\":0,\"to\":22},\"logicalOperator\":\"AND\",\"explicit\":false,\"children\":[{\"type\":\"Statement\",\"range\":{\"from\":0,\"to\":22},\"key\":{\"type\":\"Key\",\"textValue\":\"osArchitecture\",\"value\":\"osArchitecture\",\"range\":{\"from\":0,\"to\":14{{`}}`}},\"operator\":{\"type\":\"ComparisonOperator\",\"textValue\":\"=\",\"value\":\"=\",\"range\":{\"from\":15,\"to\":16{{`}}`}},\"value\":{\"type\":\"String\",\"textValue\":\"\\\"osx\\\"\",\"value\":\"osx\",\"range\":{\"from\":17,\"to\":22},\"isEscaped\":true{{`}}`}}]}",
"relationship": {
"name": "clustered_by",
"target": "dt.entity.kubernetes_cluster"
}
},
{
"applyTo": [
"logs",
"metrics"
],
"dataObject": "dt.entity.kubernetes_cluster",
"filter": "{\"type\":\"Group\",\"range\":{\"from\":0,\"to\":34},\"logicalOperator\":\"AND\",\"explicit\":false,\"children\":[{\"type\":\"Statement\",\"range\":{\"from\":0,\"to\":34},\"key\":{\"type\":\"Key\",\"textValue\":\"entity.name\",\"value\":\"entity.name\",\"range\":{\"from\":0,\"to\":11{{`}}`}},\"operator\":{\"type\":\"ComparisonOperator\",\"textValue\":\"=\",\"value\":\"=\",\"range\":{\"from\":12,\"to\":13{{`}}`}},\"value\":{\"type\":\"String\",\"textValue\":\"\\\"This is an example\\\"\",\"value\":\"This is an example\",\"range\":{\"from\":14,\"to\":34},\"isEscaped\":true{{`}}`}}]}"
},
{
"applyTo": [],
"dataObject": "events",
"filter": "{\"type\":\"Group\",\"range\":{\"from\":0,\"to\":25},\"logicalOperator\":\"AND\",\"explicit\":false,\"children\":[{\"type\":\"Statement\",\"range\":{\"from\":0,\"to\":25},\"key\":{\"type\":\"Key\",\"textValue\":\"\\\"`Event source`\\\"\",\"value\":\"`Event source`\",\"range\":{\"from\":0,\"to\":16},\"isEscaped\":true},\"operator\":{\"type\":\"ComparisonOperator\",\"textValue\":\"=\",\"value\":\"=\",\"range\":{\"from\":17,\"to\":18{{`}}`}},\"value\":{\"type\":\"String\",\"textValue\":\"Monaco\",\"value\":\"Monaco\",\"range\":{\"from\":19,\"to\":25{{`}}`}}}]}"
},
{
"applyTo": [],
"dataObject": "metrics",
"filter": "{\"type\":\"Group\",\"range\":{\"from\":0,\"to\":34},\"logicalOperator\":\"AND\",\"explicit\":false,\"children\":[{\"type\":\"Statement\",\"range\":{\"from\":0,\"to\":34},\"key\":{\"type\":\"Key\",\"textValue\":\"k8s.namespace.name\",\"value\":\"k8s.namespace.name\",\"range\":{\"from\":0,\"to\":18{{`}}`}},\"operator\":{\"type\":\"ComparisonOperator\",\"textValue\":\"=\",\"value\":\"=\",\"range\":{\"from\":19,\"to\":20{{`}}`}},\"value\":{\"type\":\"String\",\"textValue\":\"\\\"hello-world\\\"\",\"value\":\"hello-world\",\"range\":{\"from\":21,\"to\":34},\"isEscaped\":true{{`}}`}}]}"
},
{
"applyTo": [],
"dataObject": "spans",
"filter": "{\"type\":\"Group\",\"range\":{\"from\":0,\"to\":29},\"logicalOperator\":\"AND\",\"explicit\":false,\"children\":[{\"type\":\"Statement\",\"range\":{\"from\":0,\"to\":29},\"key\":{\"type\":\"Key\",\"textValue\":\"code.function\",\"value\":\"code.function\",\"range\":{\"from\":0,\"to\":13{{`}}`}},\"operator\":{\"type\":\"ComparisonOperator\",\"textValue\":\"=\",\"value\":\"=\",\"range\":{\"from\":14,\"to\":15{{`}}`}},\"value\":{\"type\":\"String\",\"textValue\":\"\\\"My function\\\"\",\"value\":\"My function\",\"range\":{\"from\":16,\"to\":29},\"isEscaped\":true{{`}}`}}]}"
}
],
"isPublic": false,
"name": "My Segment",
"variables": {
"type": "query",
"value": "describe logs"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ manifestVersion: 1.0
projects:
- name: standalone-segment
- name: two-segments
- name: referenced-segment

environmentGroups:
- name: default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
configs:
- id: segment
config:
template: segment.json
type: segment
- id: dashbaord
config:
name: Dashboard
parameters:
segment_id:
configId: segment
configType: segment
property: id
type: reference
template: dashboard.json
type:
document:
kind: dashboard
private: true
Loading

0 comments on commit 21b0f4e

Please sign in to comment.