Skip to content

Commit

Permalink
[GEN-2224] add "mutable" and "profileName" fields to InstrumentationR…
Browse files Browse the repository at this point in the history
…ule model (#2236)

This pull request introduces several changes to the `frontend/graph` and
`frontend/webapp` directories to add new fields and functionality
related to `InstrumentationRule`. The most important changes include
adding the `mutable` and `profileName` fields to the
`InstrumentationRule` type, updating the GraphQL schema and queries, and
modifying the frontend components to handle these new fields.

### GraphQL Schema and Model Updates:
* Added `mutable` and `profileName` fields to the `InstrumentationRule`
struct in `frontend/graph/model/models_gen.go` and updated the GraphQL
schema in `frontend/graph/schema.graphqls`.
[[1]](diffhunk://#diff-642ccd7ed71fdfa394bd7f7fd99c9c33e20ff18c876a91cb989d379a44390469R292-R293)
[[2]](diffhunk://#diff-bc07b91dedd1782d9ddbbb6374ad97c7604f9a267de5174645723d863c732f80R120-R121)

### Backend Logic Updates:
* Updated the `ListInstrumentationRules` function in
`frontend/services/instrumentationrule.go` to populate the new fields
based on annotations.
* Modified the `Complexity` and `executionContext` functions in
`frontend/graph/generated.go` to handle the new fields.
[[1]](diffhunk://#diff-4bacf1f13939a5c243f3f83d21f4560b331d13667d81ea5945ed1f57ddb205f2R1391-R1397)
[[2]](diffhunk://#diff-4bacf1f13939a5c243f3f83d21f4560b331d13667d81ea5945ed1f57ddb205f2R1412-R1418)
[[3]](diffhunk://#diff-4bacf1f13939a5c243f3f83d21f4560b331d13667d81ea5945ed1f57ddb205f2R4536-R4539)
[[4]](diffhunk://#diff-4bacf1f13939a5c243f3f83d21f4560b331d13667d81ea5945ed1f57ddb205f2R8712-R8799)
[[5]](diffhunk://#diff-4bacf1f13939a5c243f3f83d21f4560b331d13667d81ea5945ed1f57ddb205f2R10538-R10541)
[[6]](diffhunk://#diff-4bacf1f13939a5c243f3f83d21f4560b331d13667d81ea5945ed1f57ddb205f2R10613-R10616)
[[7]](diffhunk://#diff-4bacf1f13939a5c243f3f83d21f4560b331d13667d81ea5945ed1f57ddb205f2R20133-R20142)

### Frontend Component Updates:
* Updated the `RuleDrawer` component in
`frontend/webapp/containers/main/instrumentation-rules/rule-drawer/index.tsx`
to handle the `mutable` field and restrict editing or deleting
system-managed rules.
[[1]](diffhunk://#diff-759940924dd4ee0c6895f60e21ca040542d9cf1d3f69162677c9983d62b12f8cL74-R74)
[[2]](diffhunk://#diff-759940924dd4ee0c6895f60e21ca040542d9cf1d3f69162677c9983d62b12f8cR94-R105)
* Added `mutable` and `profileName` fields to the
`GET_INSTRUMENTATION_RULES` GraphQL query in
`frontend/webapp/graphql/queries/compute-platform.ts`.
* Updated the `InstrumentationRuleSpec` interface in
`frontend/webapp/types/instrumentation-rules.ts` to include the new
fields.
* Enhanced the `FORM_ALERTS` constants in
`frontend/webapp/utils/constants/string.tsx` to include new alert
messages for system-managed rules.
  • Loading branch information
BenElferink authored Jan 15, 2025
1 parent c875968 commit 3cbb117
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 5 deletions.
126 changes: 126 additions & 0 deletions frontend/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ type InstrumentationRule {
ruleName: String
notes: String
disabled: Boolean
mutable: Boolean!
profileName: String!
workloads: [PodWorkload!]
instrumentationLibraries: [InstrumentationLibraryGlobalId!]
payloadCollection: PayloadCollection
Expand Down
6 changes: 6 additions & 0 deletions frontend/services/instrumentationrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/frontend/graph/model"
"github.com/odigos-io/odigos/frontend/kube"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"github.com/odigos-io/odigos/k8sutils/pkg/workload"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -26,12 +27,17 @@ func ListInstrumentationRules(ctx context.Context) ([]*model.InstrumentationRule

var gqlRules []*model.InstrumentationRule
for _, rule := range instrumentationRules.Items {
annotations := rule.GetAnnotations()
profileName := annotations[k8sconsts.OdigosProfileAnnotation]
mutable := profileName == ""

gqlRules = append(gqlRules, &model.InstrumentationRule{
RuleID: rule.Name,
RuleName: &rule.Spec.RuleName,
Notes: &rule.Spec.Notes,
Disabled: &rule.Spec.Disabled,
Mutable: mutable,
ProfileName: profileName,
Workloads: convertWorkloads(rule.Spec.Workloads),
InstrumentationLibraries: convertInstrumentationLibraries(rule.Spec.InstrumentationLibraries),
PayloadCollection: convertPayloadCollection(rule.Spec.PayloadCollection),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type { InstrumentationRuleSpec } from '@/types';
import { DataCardRow, DataCardFieldTypes } from '@/reuseable-components';

const buildCard = (rule: InstrumentationRuleSpec) => {
const { type, ruleName, notes, disabled, payloadCollection } = rule;
const { type, ruleName, notes, disabled, profileName, payloadCollection } = rule;

const arr: DataCardRow[] = [
{ title: DISPLAY_TITLES.TYPE, value: type },
{ type: DataCardFieldTypes.ACTIVE_STATUS, title: DISPLAY_TITLES.STATUS, value: String(!disabled) },
{ title: DISPLAY_TITLES.NAME, value: ruleName },
{ title: DISPLAY_TITLES.NOTES, value: notes },
{ title: DISPLAY_TITLES.MANAGED_BY_PROFILE, value: profileName },
{ type: DataCardFieldTypes.DIVIDER, width: '100%' },
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { type InstrumentationRuleSpec, type InstrumentationRuleInput, PayloadCol

const buildDrawerItem = (id: string, formData: InstrumentationRuleInput, drawerItem: InstrumentationRuleSpec): InstrumentationRuleSpec => {
const { ruleName, notes, disabled, payloadCollection } = formData;
const { workloads, instrumentationLibraries } = drawerItem;
const { mutable, profileName, workloads, instrumentationLibraries } = drawerItem;

return {
ruleId: id,
ruleName,
type: deriveTypeFromRule(formData),
notes,
disabled,
mutable,
profileName,
payloadCollection: {
[PayloadCollectionType.HTTP_REQUEST]: payloadCollection[PayloadCollectionType.HTTP_REQUEST] || undefined,
[PayloadCollectionType.HTTP_RESPONSE]: payloadCollection[PayloadCollectionType.HTTP_RESPONSE] || undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const RuleDrawer: React.FC<Props> = () => {
const { id, item } = selectedItem as { id: string; item: InstrumentationRuleSpecMapped };

const handleEdit = (bool?: boolean) => {
if (item.type === InstrumentationRuleType.UNKNOWN_TYPE && (bool || bool === undefined)) {
if (!item.mutable && (bool || bool === undefined)) {
addNotification({
type: NOTIFICATION_TYPE.WARNING,
title: FORM_ALERTS.FORBIDDEN,
Expand All @@ -91,7 +91,18 @@ export const RuleDrawer: React.FC<Props> = () => {
};

const handleDelete = async () => {
await deleteInstrumentationRule(id);
if (!item.mutable) {
addNotification({
type: NOTIFICATION_TYPE.WARNING,
title: FORM_ALERTS.FORBIDDEN,
message: FORM_ALERTS.CANNOT_DELETE_RULE,
crdType: OVERVIEW_ENTITY_TYPES.RULE,
target: id,
hideFromHistory: true,
});
} else {
await deleteInstrumentationRule(id);
}
};

const handleSave = async (newTitle: string) => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/webapp/graphql/queries/compute-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export const GET_INSTRUMENTATION_RULES = gql`
ruleName
notes
disabled
mutable
profileName
# workloads {}
# instrumentationLibraries {}
payloadCollection {
Expand Down
2 changes: 2 additions & 0 deletions frontend/webapp/types/instrumentation-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export interface InstrumentationRuleSpec {
type?: InstrumentationRuleType; // does not come from backend, it's derived during GET
notes: string;
disabled: boolean;
mutable: boolean;
profileName: string;
workloads?: PodWorkload[];
instrumentationLibraries?: InstrumentationLibraryGlobalId[];
payloadCollection?: PayloadCollection;
Expand Down
4 changes: 3 additions & 1 deletion frontend/webapp/utils/constants/string.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const FORM_ALERTS = {
REQUIRED_FIELDS: 'Required fields are missing',
FIELD_IS_REQUIRED: 'This field is required',
FORBIDDEN: 'Forbidden',
CANNOT_EDIT_RULE: 'Cannot edit instrumentation rule of this type',
CANNOT_EDIT_RULE: 'Cannot edit a system-managed instrumentation rule',
CANNOT_DELETE_RULE: 'Cannot delete a system-managed instrumentation rule',
LATENCY_HTTP_ROUTE: 'HTTP route must start with a forward slash "/"',
};

Expand Down Expand Up @@ -87,4 +88,5 @@ export const DISPLAY_TITLES = {
LANGUAGE: 'Language',
MONITORS: 'Monitors',
SIGNALS_FOR_PROCESSING: 'Signals for Processing',
MANAGED_BY_PROFILE: 'Managed by Profile',
};

0 comments on commit 3cbb117

Please sign in to comment.