-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: adopt kubernetes DQL * chore: typo * chore: add tests and fix quotation of filter values * chore: add some comments * chore: address feedback * chore: don't use component namespace, only selector * chore: use correct namespace filter * chore: fix tests * chore: fix tests * chore: make kubernetes id annotation required, do not fallback to 'default' namespace * chore: fix kubernetes namespace, adjust readme, override kubernetes id if label is given * chore: address readme feedback * chore: address feedback * chore: address feedback & improve client-backend request * chore: type fixes and standalone server fix * chore: adjust empty and missing annotation screen * chore: adapt no-resources-found message for kubernetes
- Loading branch information
Showing
27 changed files
with
544 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Dynatrace LLC | ||
* 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. | ||
*/ | ||
import { dynatraceQueries, DynatraceQueryKeys } from './queries'; | ||
import { Entity } from '@backstage/catalog-model'; | ||
|
||
describe('queries', () => { | ||
const getEntity = (annotations?: Record<string, string>): Entity => ({ | ||
apiVersion: '1.0.0', | ||
kind: 'component', | ||
metadata: { name: 'componentName', annotations }, | ||
}); | ||
const defaultApiConfig = { | ||
environmentName: 'environment', | ||
environmentUrl: 'url', | ||
}; | ||
|
||
describe(DynatraceQueryKeys.KUBERNETES_DEPLOYMENTS, () => { | ||
it('should fail if neither the label selector nor the kubernetes id annotation is provided', () => { | ||
// act, assert | ||
expect(() => | ||
dynatraceQueries[DynatraceQueryKeys.KUBERNETES_DEPLOYMENTS]( | ||
getEntity(), | ||
defaultApiConfig, | ||
), | ||
).toThrow(); | ||
}); | ||
|
||
it('should return the query without the kubernetesId filter if a label selector is provided', () => { | ||
// act | ||
const query = dynatraceQueries[DynatraceQueryKeys.KUBERNETES_DEPLOYMENTS]( | ||
getEntity({ | ||
'backstage.io/kubernetes-id': 'kubernetesId', | ||
'backstage.io/kubernetes-label-selector': 'label=value', | ||
}), | ||
defaultApiConfig, | ||
); | ||
|
||
// assert | ||
expect(query).not.toContain( | ||
'| filter workload.labels[`backstage.io/kubernetes-id`] == "kubernetesId"', | ||
); | ||
expect(query).toContain('| filter workload.labels[`label`] == "value"'); | ||
}); | ||
|
||
it('should return the query with the kubernetesId filter ', () => { | ||
// act | ||
const query = dynatraceQueries[DynatraceQueryKeys.KUBERNETES_DEPLOYMENTS]( | ||
getEntity({ 'backstage.io/kubernetes-id': 'kubernetesId' }), | ||
defaultApiConfig, | ||
); | ||
|
||
// assert | ||
expect(query).toContain( | ||
'| filter workload.labels[`backstage.io/kubernetes-id`] == "kubernetesId"', | ||
); | ||
}); | ||
|
||
it('should return the query with the namespace filter', () => { | ||
// act | ||
const query = dynatraceQueries[DynatraceQueryKeys.KUBERNETES_DEPLOYMENTS]( | ||
getEntity({ | ||
'backstage.io/kubernetes-id': 'kubernetesId', | ||
'backstage.io/kubernetes-namespace': 'namespace', | ||
}), | ||
defaultApiConfig, | ||
); | ||
|
||
// assert | ||
expect(query).toContain('| filter Namespace == "namespace"'); | ||
}); | ||
|
||
it('should return the query with the label selector filter', () => { | ||
// act | ||
const query = dynatraceQueries[DynatraceQueryKeys.KUBERNETES_DEPLOYMENTS]( | ||
getEntity({ | ||
'backstage.io/kubernetes-label-selector': 'label=value', | ||
'backstage.io/kubernetes-namespace': 'namespace', | ||
}), | ||
defaultApiConfig, | ||
); | ||
|
||
// assert | ||
expect(query).toContain('| filter workload.labels[`label`] == "value"'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.