Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEN-2222]: add instrumentation-rule for code attributes #2239

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -122,6 +122,7 @@ type InstrumentationRule {
workloads: [PodWorkload!]
instrumentationLibraries: [InstrumentationLibraryGlobalId!]
payloadCollection: PayloadCollection
codeAttributes: CodeAttributes
}

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

type InstrumentationLibraryGlobalId {
Expand Down Expand Up @@ -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!
Expand Down
61 changes: 55 additions & 6 deletions frontend/services/instrumentationrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}
}
Expand All @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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{
Expand All @@ -222,6 +270,7 @@ func CreateInstrumentationRule(ctx context.Context, input model.InstrumentationR
Workloads: workloads,
InstrumentationLibraries: instrumentationLibraries,
PayloadCollection: payloadCollection,
CodeAttributes: codeAttributes,
},
}

Expand Down
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 }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this icon come from?

Copy link
Contributor Author

@BenElferink BenElferink Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Figma under "Design System" ---> icons
This one:

Screenshot 2025-01-16 at 15 21 07

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
Expand Up @@ -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>
Expand Down
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 {
Expand All @@ -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,
},
};
};

Expand Down
Loading
Loading