Skip to content

Commit

Permalink
[GEN-2222]: add instrumentation-rule for code attributes (#2239)
Browse files Browse the repository at this point in the history
Following-up with a UI update in response to PR #2230 

---

This pull request introduces the `CodeAttributes` feature to the
instrumentation rules in the frontend. The changes span across multiple
files, including model definitions, GraphQL schema, service functions,
and the web application interface. The most important changes are
summarized below:

### Model and Schema Updates:
* Added `CodeAttributes` and `CodeAttributesInput` types to the
`models_gen.go` file and integrated them into the `InstrumentationRule`
and `InstrumentationRuleInput` structs.
[[1]](diffhunk://#diff-642ccd7ed71fdfa394bd7f7fd99c9c33e20ff18c876a91cb989d379a44390469R82-R99)
[[2]](diffhunk://#diff-642ccd7ed71fdfa394bd7f7fd99c9c33e20ff18c876a91cb989d379a44390469R315)
[[3]](diffhunk://#diff-642ccd7ed71fdfa394bd7f7fd99c9c33e20ff18c876a91cb989d379a44390469R325)
* Updated the GraphQL schema to include `CodeAttributes` and
`CodeAttributesInput` in the `InstrumentationRule` and
`InstrumentationRuleInput` types.
[[1]](diffhunk://#diff-bc07b91dedd1782d9ddbbb6374ad97c7604f9a267de5174645723d863c732f80R125)
[[2]](diffhunk://#diff-bc07b91dedd1782d9ddbbb6374ad97c7604f9a267de5174645723d863c732f80R135)
[[3]](diffhunk://#diff-bc07b91dedd1782d9ddbbb6374ad97c7604f9a267de5174645723d863c732f80R196-R213)

### Service Layer Changes:
* Modified the `ListInstrumentationRules`, `UpdateInstrumentationRule`,
and `CreateInstrumentationRule` functions to handle the new
`CodeAttributes` field.
[[1]](diffhunk://#diff-d474e63d96bb8a180ea1f9d7687b2b6a0d78c2b04d32d8cdfd82874ad187eb56R44)
[[2]](diffhunk://#diff-d474e63d96bb8a180ea1f9d7687b2b6a0d78c2b04d32d8cdfd82874ad187eb56L114-L122)
[[3]](diffhunk://#diff-d474e63d96bb8a180ea1f9d7687b2b6a0d78c2b04d32d8cdfd82874ad187eb56R130-R157)
[[4]](diffhunk://#diff-d474e63d96bb8a180ea1f9d7687b2b6a0d78c2b04d32d8cdfd82874ad187eb56R172)
[[5]](diffhunk://#diff-d474e63d96bb8a180ea1f9d7687b2b6a0d78c2b04d32d8cdfd82874ad187eb56L199-R260)
[[6]](diffhunk://#diff-d474e63d96bb8a180ea1f9d7687b2b6a0d78c2b04d32d8cdfd82874ad187eb56R273)

### Web Application Updates:
* Added a new `CodeAttributesIcon` component and exported it for use in
the application.
[[1]](diffhunk://#diff-d0b5eb65b321f5856c062964a4f4f62f74624377a892b0d35507e93f7c9c6ab7R1-R17)
[[2]](diffhunk://#diff-e803ff39252ca5c7f9bb70dbc44e3041209deac4fa03d3f4f4147b1a79890749R1)
* Updated the `ActionModal` component to autofocus only when no action
type is selected.
* Enhanced the `build-drawer-item` function to include `codeAttributes`
in the drawer item construction.
[[1]](diffhunk://#diff-9c7e3ececb1f95abdfc76cb505f5cd2fd726dc111b2d9f407671b89197b6e0f0L2-R5)
[[2]](diffhunk://#diff-9c7e3ececb1f95abdfc76cb505f5cd2fd726dc111b2d9f407671b89197b6e0f0L16-R31)
* Introduced a new `CodeAttributes` component for the rule form body,
allowing users to select which code attributes to collect.
[[1]](diffhunk://#diff-651451ffd4d870846d3bca69fced174591c5f20ffaaa26a4f684185e029cc182R1-R139)
[[2]](diffhunk://#diff-79f8ef3b764df919457768e658fa2f90a2d5c2f794a78c90877532e0603d0ba1R2)
[[3]](diffhunk://#diff-79f8ef3b764df919457768e658fa2f90a2d5c2f794a78c90877532e0603d0ba1R23)
* Fixed an issue in the `PayloadCollection` component to handle cases
where `payloadCollection` might be undefined.
* Updated the `RuleModal` component to start with no pre-selected rule
option.
BenElferink authored Jan 20, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 42076d5 commit 3c05d6c
Showing 30 changed files with 1,126 additions and 176 deletions.
501 changes: 500 additions & 1 deletion frontend/graph/generated.go

Large diffs are not rendered by default.

20 changes: 20 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.

20 changes: 20 additions & 0 deletions frontend/graph/schema.graphqls
Original file line number Diff line number Diff line change
@@ -122,6 +122,7 @@ type InstrumentationRule {
workloads: [PodWorkload!]
instrumentationLibraries: [InstrumentationLibraryGlobalId!]
payloadCollection: PayloadCollection
codeAttributes: CodeAttributes
}

input InstrumentationRuleInput {
@@ -131,6 +132,7 @@ input InstrumentationRuleInput {
workloads: [PodWorkloadInput!]
instrumentationLibraries: [InstrumentationLibraryGlobalIdInput!]
payloadCollection: PayloadCollectionInput
codeAttributes: CodeAttributesInput
}

type InstrumentationLibraryGlobalId {
@@ -191,6 +193,24 @@ input MessagingPayloadCollectionInput {
dropPartialPayloads: Boolean
}

type CodeAttributes {
column: Boolean
filePath: Boolean
function: Boolean
lineNumber: Boolean
namespace: Boolean
stacktrace: Boolean
}

input CodeAttributesInput {
column: Boolean
filePath: Boolean
function: Boolean
lineNumber: Boolean
namespace: Boolean
stacktrace: Boolean
}

type ApiToken {
token: String!
name: String!
61 changes: 55 additions & 6 deletions frontend/services/instrumentationrule.go
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ func ListInstrumentationRules(ctx context.Context) ([]*model.InstrumentationRule
Workloads: convertWorkloads(rule.Spec.Workloads),
InstrumentationLibraries: convertInstrumentationLibraries(rule.Spec.InstrumentationLibraries),
PayloadCollection: convertPayloadCollection(rule.Spec.PayloadCollection),
CodeAttributes: (*model.CodeAttributes)(rule.Spec.CodeAttributes),
})
}
return gqlRules, nil
@@ -111,15 +112,12 @@ func UpdateInstrumentationRule(ctx context.Context, id string, input model.Instr
if input.PayloadCollection.HTTPRequest != nil {
payloadCollection.HttpRequest = &instrumentationrules.HttpPayloadCollection{}
}

if input.PayloadCollection.HTTPResponse != nil {
payloadCollection.HttpResponse = &instrumentationrules.HttpPayloadCollection{}
}

if input.PayloadCollection.DbQuery != nil {
payloadCollection.DbQuery = &instrumentationrules.DbQueryPayloadCollection{}
}

if input.PayloadCollection.Messaging != nil {
payloadCollection.Messaging = &instrumentationrules.MessagingPayloadCollection{}
}
@@ -129,6 +127,34 @@ func UpdateInstrumentationRule(ctx context.Context, id string, input model.Instr
existingRule.Spec.PayloadCollection = nil
}

var codeAttributes *instrumentationrules.CodeAttributes
if input.CodeAttributes != nil {
codeAttributes = &instrumentationrules.CodeAttributes{}

if input.CodeAttributes.Column != nil {
codeAttributes.Column = input.CodeAttributes.Column
}
if input.CodeAttributes.FilePath != nil {
codeAttributes.FilePath = input.CodeAttributes.FilePath
}
if input.CodeAttributes.Function != nil {
codeAttributes.Function = input.CodeAttributes.Function
}
if input.CodeAttributes.LineNumber != nil {
codeAttributes.LineNumber = input.CodeAttributes.LineNumber
}
if input.CodeAttributes.Namespace != nil {
codeAttributes.Namespace = input.CodeAttributes.Namespace
}
if input.CodeAttributes.Stacktrace != nil {
codeAttributes.Stacktrace = input.CodeAttributes.Stacktrace
}

existingRule.Spec.CodeAttributes = codeAttributes
} else {
existingRule.Spec.CodeAttributes = nil
}

// Update rule in Kubernetes
updatedRule, err := kube.DefaultClient.OdigosClient.InstrumentationRules(ns).Update(ctx, existingRule, metav1.UpdateOptions{})
if err != nil {
@@ -143,6 +169,7 @@ func UpdateInstrumentationRule(ctx context.Context, id string, input model.Instr
Workloads: convertWorkloads(updatedRule.Spec.Workloads),
InstrumentationLibraries: convertInstrumentationLibraries(updatedRule.Spec.InstrumentationLibraries),
PayloadCollection: convertPayloadCollection(updatedRule.Spec.PayloadCollection),
CodeAttributes: (*model.CodeAttributes)(updatedRule.Spec.CodeAttributes),
}, nil
}

@@ -196,20 +223,41 @@ func CreateInstrumentationRule(ctx context.Context, input model.InstrumentationR
if input.PayloadCollection.HTTPRequest != nil {
payloadCollection.HttpRequest = &instrumentationrules.HttpPayloadCollection{}
}

if input.PayloadCollection.HTTPResponse != nil {
payloadCollection.HttpResponse = &instrumentationrules.HttpPayloadCollection{}
}

if input.PayloadCollection.DbQuery != nil {
payloadCollection.DbQuery = &instrumentationrules.DbQueryPayloadCollection{}
}

if input.PayloadCollection.Messaging != nil {
payloadCollection.Messaging = &instrumentationrules.MessagingPayloadCollection{}
}
}

var codeAttributes *instrumentationrules.CodeAttributes
if input.CodeAttributes != nil {
codeAttributes = &instrumentationrules.CodeAttributes{}

if input.CodeAttributes.Column != nil {
codeAttributes.Column = input.CodeAttributes.Column
}
if input.CodeAttributes.FilePath != nil {
codeAttributes.FilePath = input.CodeAttributes.FilePath
}
if input.CodeAttributes.Function != nil {
codeAttributes.Function = input.CodeAttributes.Function
}
if input.CodeAttributes.LineNumber != nil {
codeAttributes.LineNumber = input.CodeAttributes.LineNumber
}
if input.CodeAttributes.Namespace != nil {
codeAttributes.Namespace = input.CodeAttributes.Namespace
}
if input.CodeAttributes.Stacktrace != nil {
codeAttributes.Stacktrace = input.CodeAttributes.Stacktrace
}
}

// Define the new rule spec based on the input
newRule := &v1alpha1.InstrumentationRule{
ObjectMeta: metav1.ObjectMeta{
@@ -222,6 +270,7 @@ func CreateInstrumentationRule(ctx context.Context, input model.InstrumentationR
Workloads: workloads,
InstrumentationLibraries: instrumentationLibraries,
PayloadCollection: payloadCollection,
CodeAttributes: codeAttributes,
},
}

17 changes: 17 additions & 0 deletions frontend/webapp/assets/icons/rules/code-attributes-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { SVG } from '@/assets';
import theme from '@/styles/theme';

export const CodeAttributesIcon: SVG = ({ size = 16, fill = theme.text.info, rotate = 0, onClick }) => {
return (
<svg width={size} height={size} viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg' fill='none' style={{ transform: `rotate(${rotate}deg)` }} onClick={onClick}>
<path
stroke={fill}
strokeWidth='1.5'
strokeLinecap='round'
strokeLinejoin='round'
d='M8 4C6.34315 4 5 5.19391 5 6.66667V9.33333C5 10.8061 3.65685 12 2 12C3.65685 12 5 13.1939 5 14.6667V17.3333C5 18.8061 6.34315 20 8 20M16 4C17.6569 4 19 5.19391 19 6.66667V9.33333C19 10.8061 20.3431 12 22 12C20.3431 12 19 13.1939 19 14.6667V17.3333C19 18.8061 17.6569 20 16 20M12.001 12H12M15.001 12H15M9.001 12H9'
/>
</svg>
);
};
1 change: 1 addition & 0 deletions frontend/webapp/assets/icons/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './code-attributes-icon';
export * from './payload-collection-icon';
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ export const ActionModal: React.FC<Props> = ({ isOpen, onClose }) => {
>
<ModalBody>
<SectionTitle title='Select Action' description='Select an action to modify telemetry data before it`s sent to destinations. Choose an action type and configure its details.' />
<AutocompleteInput options={ACTION_OPTIONS} selectedOption={selectedItem} onOptionSelect={handleSelect} style={{ marginTop: '24px' }} autoFocus />
<AutocompleteInput options={ACTION_OPTIONS} selectedOption={selectedItem} onOptionSelect={handleSelect} style={{ marginTop: '24px' }} autoFocus={!selectedItem?.type} />

{!!selectedItem?.type ? (
<div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deriveTypeFromRule } from '@/utils';
import { type InstrumentationRuleSpec, type InstrumentationRuleInput, PayloadCollectionType } from '@/types';
import { type InstrumentationRuleSpec, type InstrumentationRuleInput, PayloadCollectionType, CodeAttributesType } from '@/types';

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

return {
@@ -13,14 +13,22 @@ const buildDrawerItem = (id: string, formData: InstrumentationRuleInput, drawerI
disabled,
mutable,
profileName,
payloadCollection: {
[PayloadCollectionType.HTTP_REQUEST]: payloadCollection[PayloadCollectionType.HTTP_REQUEST] || undefined,
[PayloadCollectionType.HTTP_RESPONSE]: payloadCollection[PayloadCollectionType.HTTP_RESPONSE] || undefined,
[PayloadCollectionType.DB_QUERY]: payloadCollection[PayloadCollectionType.DB_QUERY] || undefined,
[PayloadCollectionType.MESSAGING]: payloadCollection[PayloadCollectionType.MESSAGING] || undefined,
},
workloads,
instrumentationLibraries,
payloadCollection: {
[PayloadCollectionType.HTTP_REQUEST]: payloadCollection?.[PayloadCollectionType.HTTP_REQUEST] || undefined,
[PayloadCollectionType.HTTP_RESPONSE]: payloadCollection?.[PayloadCollectionType.HTTP_RESPONSE] || undefined,
[PayloadCollectionType.DB_QUERY]: payloadCollection?.[PayloadCollectionType.DB_QUERY] || undefined,
[PayloadCollectionType.MESSAGING]: payloadCollection?.[PayloadCollectionType.MESSAGING] || undefined,
},
codeAttributes: {
[CodeAttributesType.COLUMN]: codeAttributes?.[CodeAttributesType.COLUMN] || undefined,
[CodeAttributesType.FILE_PATH]: codeAttributes?.[CodeAttributesType.FILE_PATH] || undefined,
[CodeAttributesType.FUNCTION]: codeAttributes?.[CodeAttributesType.FUNCTION] || undefined,
[CodeAttributesType.LINE_NUMBER]: codeAttributes?.[CodeAttributesType.LINE_NUMBER] || undefined,
[CodeAttributesType.NAMESPACE]: codeAttributes?.[CodeAttributesType.NAMESPACE] || undefined,
[CodeAttributesType.STACKTRACE]: codeAttributes?.[CodeAttributesType.STACKTRACE] || undefined,
},
};
};

Loading

0 comments on commit 3c05d6c

Please sign in to comment.