Skip to content

Conversation

samaradel
Copy link
Contributor

@samaradel samaradel commented Jul 29, 2025

Description

FQDN gateways will create name contracts using the workload name (which is alphanumeric) instead of the FQDN (which contains invalid characters)

Changes

image image

Related Issues

Tested Scenarios

  • Deploy FQDN and check the FQDN contract if it existed

Documentation PR

For UI changes, Please provide the Documentation PR on info_grid

To consider

Preliminary Checks:

  • Preliminary Checks
    • Does it completely address the issue linked?
    • What about edge cases?
    • Does it meet the specified acceptance criteria?
    • Are there any unintended side effects?
    • Does the PR adhere to the team's coding conventions, style guides, and best practices?
    • Does it integrate well with existing features?
    • Does it impact the overall performance of the application?
    • Are there any bottlenecks or slowdowns?
    • Has it been optimized for efficiency?
    • Has it been adequately tested with unit, integration, and end-to-end tests?
    • Are there any known defects or issues?
    • Is the code well-documented?
    • Are changes to documentation reflected in the code?

UI Checks:

  • UI Checks
    • If a UI design is provided/ does it follow it?
    • Does every button work?
    • Is the data displayed logical? Is it what you expected?
    • Does every validation work?
    • Does this interface feel intuitive?
    • What about slow network? Offline?
    • What if the gridproxy/graphql/chain is failing?
    • What would a first time user have a hard time navigating here?

Code Quality Checks:

  • Code Quality Checks
    • Code formatted/linted? Are there unused imports? .. etc
    • Is there redundant/repeated code?
    • Are there conditionals that are always true or always false?
    • Can we write this more concisely?
    • Can we reuse this code? If yes, where?
    • Will the changes be easy to maintain and update in the future?
    • Can this code become too complex to understand for other devs?
    • Can this code cause future integration problems?

Testing Checklist

  • Does it Meet the specified acceptance criteria.
  • Test if changes can affect any other functionality.
  • Tested with unit, integration, and end-to-end tests.
  • Tested the un-happy path and rollback scenarios.
  • Documentation updated to meet the latest changes.
  • Check automated tests working successfully with the changes.
  • Can be covered by automated tests.

General Checklist

  • Tests included
  • Build pass
  • Documentation
  • Code format and docstring
  • Screenshots/Video attached (needed for UI changes)

@@ -492,6 +497,11 @@ class TwinDeploymentHandler {
events.emit("logs", `Check the name contract for the workload with name: ${workload.name}`);
const extrinsic = await this.createNameContract(workload.data["name"]);
nameExtrinsics.push(extrinsic);
} else if (workload.type === WorkloadTypes.gatewayfqdnproxy) {
events.emit("logs", `Check the name contract for the FQDN workload with name: ${workload.name}`);
const contractName = workload.name.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

i suggest having this logic in a function and reusing it
to avoid code redundancy, andit will be easier to maintain

@samaradel samaradel marked this pull request as draft August 5, 2025 08:54
@samaradel samaradel marked this pull request as ready for review August 5, 2025 09:40
@samaradel samaradel requested a review from 0oM4R August 5, 2025 09:40
}
}
const gatewayResults = await this.handleGatewayWorkloads(twinDeployment.deployment.workloads, Operations.update);
nameExtrinsics = gatewayResults.nameExtrinsics;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should push the result, not reassign it.
also we can have

const gatewayResults = await this.handleGatewayWorkloads(twinDeployment.deployment.workloads, twinDeployment.operation)

then insdie the operation check block:

else if (twinDeployment.operation === Operations.update) {
...
nameExtrinsics.push(gatewayResults.nameExtrinsics)
}

same on delete

}
} else if (workload.type === WorkloadTypes.gatewayfqdnproxy) {
events.emit("logs", `Check the name contract for the FQDN workload with name: ${workload.name}`);
const contractName = workload.name.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

That's wrong. Why should the workload name be a unique identifier?! The workload name should be unique on the deployment object only. The unique identifier that should be on the name contract is the FQDN.

@samaradel samaradel marked this pull request as draft August 6, 2025 12:42
- Changing the reassignment operations to push operations
@samaradel samaradel marked this pull request as ready for review August 6, 2025 13:26
@ramezsaeed
Copy link
Contributor

ramezsaeed commented Aug 6, 2025

Test scenarios:

  1. Workload name with alphanumeric characters

    • Given a workload named testGateway42
    • When a gateway is created
    • Then the name contract should exactly match testGateway42
    • And contain no special characters from the FQDN
  2. FQDN with invalid characters

    • Given a FQDN api.dev-company.org
    • And a workload name apiDevCompany
    • When an FQDN gateway is created
    • Then the contract name should be apiDevCompany
    • And not contain ., -, or any other invalid characters
  3. Contract name uniqueness

    • Given two gateways with same workload name which have speciall characters my_domain$1
    • When both are deployed
    • Then the system should reject the second contract
    • Or append a unique suffix to prevent a name conflict

Copy link
Contributor

@0oM4R 0oM4R left a comment

Choose a reason for hiding this comment

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

created a fqdn with fqdn kassem-test.elgrid.xyz
this created
gateway contract
details

{
  "version": 0,
  "twin_id": 800,
  "contract_id": 225610,
  "metadata": "",
  "description": "",
  "expiration": 0,
  "signature_requirement": {
    "requests": [
      {
        "twin_id": 800,
        "required": false,
        "weight": 1
      }
    ],
    "weight_required": 1,
    "signatures": [
      {
        "twin_id": 800,
        "signature": "1aa73655d7bc6fdb6e6488fbac42365d6cc9155af79abf668adc1d9d4ccffb529419859e37cd52375511959af546a2c471ec3bca8578a9776d37094ccdf5d881",
        "signature_type": "sr25519"
      }
    ],
    "signature_style": ""
  },
  "workloads": [
    {
      "version": 0,
      "name": "kassem8",
      "type": "gateway-fqdn-proxy",
      "data": {
        "__type": "gateway-fqdn-proxy",
        "fqdn": "kassem-test.elgrid.xyz",
        "tls_passthrough": false,
        "backends": [
          "http://10.20.2.2:80"
        ],
        "network": "nwcnn2q"
      },
      "metadata": "",
      "description": "",
      "result": {
        "created": 1754566136,
        "state": "ok",
        "message": "",
        "data": {}
      }
    }
  ]
}

and name contract

{
  "contract_id": 225611,
  "twin_id": 800,
  "type": "name",
  "state": "Created",
  "created_at": 1754566128,
  "details": {
    "nodeId": "-",
    "farm_id": "-"
  },
  "solutionName": "kassemtestelgridxyz",
  "solutionType": "-",
  "expiration": "-",
  "consumption": 0,
  "discountPackage": "None"
}

then tried to create new fqdn pointing to kassem.test.elgrid.xyz
image

image

}> {
const nameExtrinsics: ExtrinsicResult<Contract>[] = [];
const deletedExtrinsics: ExtrinsicResult<number>[] = [];

Copy link
Contributor

Choose a reason for hiding this comment

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

We can add a function here to reduce code redundancy, so you can define the contract name, based on workload type, then pass it to this function, whatever the operation is

  const processContract = async (contractName: string) => {
    if (operation === Operations.delete) {
      const extrinsic = await this.deleteNameContract(contractName);
      if (extrinsic) deletedExtrinsics.push(extrinsic);
    } else {
      const extrinsic = await this.createNameContract(contractName);
      nameExtrinsics.push(extrinsic);
    }
  };

@samaradel samaradel marked this pull request as draft August 7, 2025 12:20
}
} else if (workload.type === WorkloadTypes.gatewayfqdnproxy) {
events.emit("logs", `Check the name contract for the FQDN workload with name: ${workload.name}`);
const contractName = workload.data["fqdn"].replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

we should store the full fqdn name and do not remove anything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we shouldn't as tf chain doesn't support the characters like dots for example

Copy link
Contributor

Choose a reason for hiding this comment

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

If we can't store the FQDN as is, there will be many variations of domains that will end up with the same string after removing ., -, and _. So, no unique records, which is the target of having the name contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so, any recommended ideas?

@samaradel samaradel marked this pull request as ready for review August 7, 2025 13:51
@samaradel samaradel requested a review from 0oM4R August 7, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants