Skip to content

Commit fd93a1b

Browse files
authored
feat: Manage network zones configuration with monaco (#1333)
1 parent ab45fc7 commit fd93a1b

File tree

9 files changed

+65
-0
lines changed

9 files changed

+65
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
configs:
2+
- id: test-zone
3+
config:
4+
name: test-zone
5+
template: test-zone.json
6+
skip: false
7+
type:
8+
api: network-zone
9+
- id: test-zone-2
10+
config:
11+
name: test-zone-2
12+
template: test-zone-2.json
13+
skip: false
14+
type:
15+
api: network-zone
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"alternativeZones": [],
3+
"description": "This is a second test zone",
4+
"fallbackMode": "ANY_ACTIVE_GATE"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"alternativeZones": [],
3+
"description": "This is a test zone",
4+
"fallbackMode": "ANY_ACTIVE_GATE",
5+
"numOfConfiguredActiveGates": 0,
6+
"numOfConfiguredOneAgents": 0,
7+
"numOfOneAgentsFromOtherZones": 0,
8+
"numOfOneAgentsUsing": 0
9+
}

pkg/api/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type API struct {
3636
//
3737
// Those configs include all configs handling credentials, as well as the extension-API.
3838
SkipDownload bool
39+
// TweakResponseFunc can be optionally registered to add custom code that changes the
40+
// payload of the downloaded api content (e.g. to exclude unwanted/unnecessary fields)
41+
TweakResponseFunc func(map[string]any)
3942
}
4043

4144
// CreateURL creates final URL for given environmentUrl/domain

pkg/api/endpoints.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ var configEndpoints = []API{
2525
DeprecatedBy: "builtin:alerting.profile",
2626
NonUniqueName: true,
2727
},
28+
{
29+
ID: "network-zone",
30+
URLPath: "/api/v2/networkZones",
31+
PropertyNameOfGetAllResponse: "networkZones",
32+
TweakResponseFunc: func(m map[string]any) {
33+
delete(m, "numOfOneAgentsUsing")
34+
delete(m, "numOfConfiguredOneAgents")
35+
delete(m, "numOfOneAgentsFromOtherZones")
36+
delete(m, "numOfConfiguredActiveGates")
37+
},
38+
},
2839
{
2940
ID: "management-zone",
3041
URLPath: "/api/config/v1/managementZones",

pkg/client/dtclient/config_client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ func (d *DynatraceClient) upsertDynatraceObject(ctx context.Context, theApi api.
4747
}
4848
}
4949

50+
// The network-zone API doesn't have a POST endpoint, hence, we need to treat it as an update operation
51+
// per default
52+
if theApi.ID == "network-zone" {
53+
existingObjectID = objectName
54+
}
55+
5056
// The calculated-metrics-log API doesn't have a POST endpoint, to create a new log metric we need to use PUT which
5157
// requires a metric key for which we can just take the objectName
5258
if theApi.ID == "calculated-metrics-log" && existingObjectID == "" {

pkg/download/classic/downloader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func (d *Downloader) downloadConfigsOfAPI(api api.API, values []dtclient.Value,
164164
go func() {
165165
defer wg.Done()
166166
downloadedJson, err := d.downloadAndUnmarshalConfig(api, value)
167+
if api.TweakResponseFunc != nil {
168+
api.TweakResponseFunc(downloadedJson)
169+
}
170+
167171
if err != nil {
168172
log.WithFields(field.Type(api.ID), field.F("value", value), field.Error(err)).Error("Error fetching config '%v' in api '%v': %v", value.Id, api.ID, err)
169173
return

pkg/download/classic/filter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,9 @@ var apiContentFilters = map[string]ContentFilter{
7474
return strings.HasPrefix(value.Id, "dynatrace.") || strings.HasPrefix(value.Id, "ruxit.")
7575
},
7676
},
77+
"network-zone": {
78+
ShouldBeSkippedPreDownload: func(value dtclient.Value) bool {
79+
return value.Id == "default"
80+
},
81+
},
7782
}

pkg/download/classic/filter_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,10 @@ func TestShouldConfigBeSkipped(t *testing.T) {
145145
Id: "test.something",
146146
}))
147147
})
148+
149+
t.Run("default network zone - should be skipped", func(t *testing.T) {
150+
assert.True(t, apiContentFilters["network-zone"].ShouldBeSkippedPreDownload(dtclient.Value{
151+
Id: "default",
152+
}))
153+
})
148154
}

0 commit comments

Comments
 (0)