Skip to content

Commit

Permalink
feat: add internal networking option for ESP connectivity in data source
Browse files Browse the repository at this point in the history
configuration
  • Loading branch information
amlmtl committed Dec 7, 2023
1 parent 30f4b3b commit e33e3b7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
23 changes: 18 additions & 5 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ type SampleDatasource struct {
}

type datasourceJsonData struct {
IsViya bool `json:"isViya"`
OauthPassThru bool `json:"oauthPassThru"`
TlsSkipVerify bool `json:"tlsSkipVerify"`
UseInternalNetworking bool `json:"useInternalNetworking"`
OauthPassThru bool `json:"oauthPassThru"`
TlsSkipVerify bool `json:"tlsSkipVerify"`
}

// Dispose here tells plugin SDK that plugin wants to clean up resources when a new instance
Expand Down Expand Up @@ -130,7 +130,12 @@ func (d *SampleDatasource) QueryData(ctx context.Context, req *backend.QueryData
continue
}

serverUrl := qdto.ExternalServerUrl
var serverUrl string
if d.jsonData.UseInternalNetworking {
serverUrl = qdto.InternalServerUrl
} else {
serverUrl = qdto.ExternalServerUrl
}

var authHeaderToBePassed *string = nil
if authorizationHeaderPtr != nil && d.isServerUrlTrusted(serverUrl, true, authorizationHeaderPtr) {
Expand All @@ -144,7 +149,15 @@ func (d *SampleDatasource) QueryData(ctx context.Context, req *backend.QueryData
}

func (d *SampleDatasource) query(_ context.Context, datasourceUid string, qdto querydto.QueryDTO, authorizationHeader *string) backend.DataResponse {
s, err := server.FromUrlString(qdto.ExternalServerUrl)
var qServerUrl string
if d.jsonData.UseInternalNetworking {
qServerUrl = qdto.InternalServerUrl
log.DefaultLogger.Debug("Using internal ESP server URL from query", "query", qdto)
} else {
qServerUrl = qdto.ExternalServerUrl
}

s, err := server.FromUrlString(qServerUrl)
if err != nil {
return handleQueryError("invalid server URL", err)
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export function ConfigEditor({options, onOptionsChange}: DataSourcePluginOptions
changePropOptionsJsonData({tlsSkipVerify: checked});
}

const handleInternalNetworkingCheckboxChange = (checked: boolean) => {
changePropOptionsJsonData({useInternalNetworking: checked});
}

const handleViyaCheckboxChange = (checked: boolean) => {
const isViya = checked;
// Grafana will ignore attempts to reset datasource URLs and will revert to the previously saved value upon a future save, rather than persist a falsy URL.
Expand Down Expand Up @@ -95,6 +99,9 @@ export function ConfigEditor({options, onOptionsChange}: DataSourcePluginOptions
onChange={handleDiscoveryServiceProviderChange}
/>
</HorizontalGroup>
<Checkbox label="Use internal networking for ESP connectivity" value={jsonData.useInternalNetworking ?? false}
onChange={e => handleInternalNetworkingCheckboxChange(e.currentTarget.checked)}
/>
<Checkbox label="(Insecure) Skip TLS certificate verification" value={jsonData.tlsSkipVerify ?? false}
onChange={e => handleTlsSkipVerifyCheckboxChange(e.currentTarget.checked)}
/>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@ export interface EspDataSourceOptions extends DataSourceJsonData {
oauthPassThru: boolean;
tlsSkipVerify: boolean;
isViya: boolean;
useInternalNetworking: boolean;
}

0 comments on commit e33e3b7

Please sign in to comment.